forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathVerifyTriggerEventData.cs
More file actions
78 lines (67 loc) · 2.95 KB
/
Copy pathVerifyTriggerEventData.cs
File metadata and controls
78 lines (67 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
using System;
using Unity.Collections;
using Unity.Entities;
using Unity.Jobs;
using Unity.Physics.Systems;
using UnityEngine;
using UnityEngine.Assertions;
namespace Unity.Physics.Tests
{
public struct VerifyTriggerEventDataData : IComponentData
{
}
[Serializable]
public class VerifyTriggerEventData : MonoBehaviour, IConvertGameObjectToEntity
{
public void Convert(Entity entity, EntityManager dstManager, GameObjectConversionSystem conversionSystem)
{
dstManager.AddComponentData(entity, new VerifyTriggerEventDataData());
}
}
[UpdateBefore(typeof(StepPhysicsWorld))]
public class VerifyTriggerEventDataSystem : JobComponentSystem
{
EntityQuery m_VerificationGroup;
StepPhysicsWorld m_StepPhysicsWorld;
protected override void OnCreate()
{
m_StepPhysicsWorld = World.GetOrCreateSystem<StepPhysicsWorld>();
m_VerificationGroup = GetEntityQuery(new EntityQueryDesc
{
All = new ComponentType[] { typeof(VerifyTriggerEventDataData) }
});
}
struct VerifyTriggerEventDataJob : ITriggerEventsJob
{
[ReadOnly]
public NativeSlice<RigidBody> Bodies;
[ReadOnly]
public ComponentDataFromEntity<VerifyTriggerEventDataData> VerificationData;
public void Execute(TriggerEvent triggerEvent)
{
// Trigger event is between a static and dynamic box.
// Verify all data in the provided event struct.
Assert.AreNotEqual(triggerEvent.BodyIndices.BodyAIndex, triggerEvent.BodyIndices.BodyBIndex);
Assert.AreEqual(triggerEvent.ColliderKeys.ColliderKeyA.Value, ColliderKey.Empty.Value);
Assert.AreEqual(triggerEvent.ColliderKeys.ColliderKeyB.Value, ColliderKey.Empty.Value);
Assert.AreEqual(triggerEvent.Entities.EntityA, Bodies[triggerEvent.BodyIndices.BodyAIndex].Entity);
Assert.AreEqual(triggerEvent.Entities.EntityB, Bodies[triggerEvent.BodyIndices.BodyBIndex].Entity);
Assert.AreEqual(triggerEvent.Entities.EntityA.Version, 1);
Assert.AreEqual(triggerEvent.Entities.EntityB.Version, 1);
}
}
protected override JobHandle OnUpdate(JobHandle inputDeps)
{
SimulationCallbacks.Callback testTriggerEventCallback = (ref ISimulation simulation, ref PhysicsWorld world, JobHandle inDeps) =>
{
return new VerifyTriggerEventDataJob
{
Bodies = world.Bodies,
VerificationData = GetComponentDataFromEntity<VerifyTriggerEventDataData>(true)
}.Schedule(simulation, ref world, inDeps);
};
m_StepPhysicsWorld.EnqueueCallback(SimulationCallbacks.Phase.PostSolveJacobians, testTriggerEventCallback, inputDeps);
return inputDeps;
}
}
}