summaryrefslogtreecommitdiff
path: root/Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs
diff options
context:
space:
mode:
authorchai <chaifix@163.com>2019-08-14 22:50:43 +0800
committerchai <chaifix@163.com>2019-08-14 22:50:43 +0800
commit15740faf9fe9fe4be08965098bbf2947e096aeeb (patch)
treea730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs
+Unity Runtime codeHEADmaster
Diffstat (limited to 'Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs')
-rw-r--r--Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs25
1 files changed, 25 insertions, 0 deletions
diff --git a/Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs b/Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs
new file mode 100644
index 0000000..2d7efca
--- /dev/null
+++ b/Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs
@@ -0,0 +1,25 @@
+using System;
+using UnityEngine;
+
+namespace UnityEngine.Graphs.LogicGraph
+{
+ // For now we do triggers by attaching this MonoBehaviour to needed gameobjects. Class then sends events to logic graph nodes.
+ public abstract class ColliderDummyBase : MonoBehaviour
+ {
+ protected static Component AttachToCollider(Collider self, Type dummyType)
+ {
+ var attached = GetAndAddComponentIfNeeded(self.gameObject, dummyType);
+
+ if (attached == null)
+ throw new ArgumentException("Failed to attach Logic Graph Collider Event handler to a game object of component '" + self + "'.");
+
+ return attached;
+ }
+
+ private static Component GetAndAddComponentIfNeeded(GameObject go, Type type)
+ {
+ return go.GetComponent(type) ?? go.AddComponent(type);
+ }
+ }
+}
+