summaryrefslogtreecommitdiff
path: root/Runtime/Graphs/UnityEngine.Graphs/MonoBehaviourEventDummies/ColliderDummyBase.cs
blob: 2d7efca941f87fffd576756270a642965113e836 (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
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);
		}
	}
}