summaryrefslogtreecommitdiff
path: root/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Collider/OnCollisionEvent.cs
blob: acc732e3720ef6bd1c9e76d429c86d6393a24e1c (plain)
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
using UnityEngine;

namespace UnityEngine.Graphs.LogicGraph
{
	public partial class ColliderNodes
	{
		// This is only used for node declaration. Implementation is in the OnCollisionEventDummy monobehaviour.
		[Logic(typeof(Collider))]
		public class OnCollisionEvent
		{
			[LogicTarget]
			public Collider self;

			public Action enter;
			public Action exit;
			public Action stay;

			private Vector3 m_RelativeVelocity;
			public Vector3 relativeVelocity
			{
				get { return m_RelativeVelocity; }
			}

			private Collider m_Other;
			public Collider other
			{
				get { return m_Other; }
			}

			//TODO: would be nice to have, but no nodes in graphs yet know about how to work with arrays
			//private ContactPoint[] m_Contacts;
			//public ContactPoint[] contacts
			//{
			//	get { return m_Contacts; }
			//}

			internal void EnterDummy(Collision collision)
			{
				if (enter == null)
					return;

				m_RelativeVelocity = collision.relativeVelocity;
				m_Other = collision.collider;
				//m_Contacts = collision.contacts;

				enter ();
			}

			internal void ExitDummy(Collision collision)
			{
				if (exit == null)
					return;

				m_RelativeVelocity = collision.relativeVelocity;
				m_Other = collision.collider;
				//m_Contacts = collision.contacts;

				exit();
			}

			internal void StayDummy(Collision collision)
			{
				if (stay == null)
					return;

				m_RelativeVelocity = collision.relativeVelocity;
				m_Other = collision.collider;
				//m_Contacts = collision.contacts;

				stay();
			}
		}
	}
}