diff options
Diffstat (limited to 'Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs')
-rw-r--r-- | Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs | 25 |
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); + } + } +} + |