From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 14 Aug 2019 22:50:43 +0800 Subject: +Unity Runtime code --- .../MonoBehaviourEventDummies/ColliderDummyBase.cs | 25 ++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs (limited to 'Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs') 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); + } + } +} + -- cgit v1.1-26-g67d0