Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public unsafe class TestSystem : JobComponentSystem
- {
- private EntityQuery _query;
- private IReactionBuilder _reactions;
- private IReactionBuilder _burstReactions;
- private NativeObject<OnSelected> _onSelected;
- protected override void OnCreate()
- {
- SetupMethods();
- SetupBurstMethods();
- _query = GetEntityQuery(_reactions.QueryDesc, _burstReactions.QueryDesc);
- RequireForUpdate(_query);
- }
- private void SetupMethods()
- {
- _reactions = new ReactionBuilder<
- Delegate<OnMatchedEvent, MatchedEvent>,
- Delegate<OnPointerPressedEvent, PointerPressedEvent>,
- Delegate<DoSomethingElse, PointerPressedEvent>>();
- _reactions.Add<MatchedEvent, OnMatchedEvent>();
- // Test multiple methods triggered off the same component.
- _reactions.Add<PointerPressedEvent, OnPointerPressedEvent>();
- _reactions.Add<PointerPressedEvent, DoSomethingElse>();
- }
- private void SetupBurstMethods()
- {
- // Test burst and components passed to method being different from trigger component.
- _burstReactions = new ReactionBuilder<
- Delegate<OnSelected, Translation, BoardPosition, Rotation>>();
- _onSelected = _burstReactions.Add<SelectedElement, OnSelected>(new OnSelected
- {
- Count = 1000 // verify starting values passed in on creation make it through to the job.
- });
- }
- protected override JobHandle OnUpdate(JobHandle inputDeps)
- {
- // Verify burst jobs are working
- Debug.Log($"{_onSelected.Value.Count}");
- if (_onSelected.Value.Count > 1050)
- {
- // Test directly editing data jobs are using.
- _onSelected.Value.Count = 1000;
- }
- return JobHandle.CombineDependencies(
- _reactions.Job.Schedule(_query, inputDeps),
- _burstReactions.Job.Schedule(_query, inputDeps));
- }
- [BurstCompile]
- public struct OnSelected : IEntityHandler<Translation, BoardPosition, Rotation>
- {
- public void Invoke(Entity entity, ref Translation translation, ref BoardPosition boardPosition, ref Rotation rotation)
- {
- Count++;
- }
- public int Count;
- }
- public struct OnMatchedEvent : IEntityHandler<MatchedEvent>
- {
- public void Invoke(Entity entity, ref MatchedEvent component)
- {
- Debug.Log($"OnMatchedEvent Invoked {entity} Count={component.Count}");
- Count++;
- }
- public int Count;
- }
- public struct OnPointerPressedEvent : IEntityHandler<PointerPressedEvent>
- {
- public void Invoke(Entity entity, ref PointerPressedEvent component)
- {
- Debug.Log($"OnPointerPressedEvent Invoked {entity} Position={component.Position}");
- Count++;
- }
- public int Count;
- }
- public struct DoSomethingElse : IEntityHandler<PointerPressedEvent>
- {
- public void Invoke(Entity entity, ref PointerPressedEvent component)
- {
- Debug.Log($"DoSomethingElse Invoked {entity} Position={component.Position}");
- Count++;
- }
- public int Count;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement