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
80 lines (70 loc) · 2.93 KB
/
Copy pathVerifyTriggerEventData.cs
File metadata and controls
80 lines (70 loc) · 2.93 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
79
80
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());
#if HAVOK_PHYSICS_EXISTS
Havok.Physics.HavokConfiguration config = Havok.Physics.HavokConfiguration.Default;
config.EnableSleeping = 0;
dstManager.AddComponentData(entity, config);
#endif
}
}
[UpdateInGroup(typeof(FixedStepSimulationSystemGroup))]
[UpdateBefore(typeof(StepPhysicsWorld))]
public class VerifyTriggerEventDataSystem : SystemBase
{
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 NativeArray<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.BodyIndexA, triggerEvent.BodyIndexB);
Assert.AreEqual(triggerEvent.ColliderKeyA.Value, ColliderKey.Empty.Value);
Assert.AreEqual(triggerEvent.ColliderKeyB.Value, ColliderKey.Empty.Value);
Assert.AreEqual(triggerEvent.EntityA, Bodies[triggerEvent.BodyIndexA].Entity);
Assert.AreEqual(triggerEvent.EntityB, Bodies[triggerEvent.BodyIndexB].Entity);
}
}
protected override void OnUpdate()
{
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, Dependency);
}
}
}