summaryrefslogtreecommitdiff
path: root/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/NodeLibrary.cs
blob: 4723b37cbe9560471ed3592289afe02030f9c5aa (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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
using System.Collections;
using UnityEngine;

namespace UnityEngine.Graphs.LogicGraph
{
	public class NodeLibrary
	{
		public enum ToggleEnum { On, Off, Toggle }

		public static string version
		{
			get { return "0.3a"; }
		}

		// this is actually used, leave here when cleaning up this class
		public static float Iff(bool a, float t, float f)
		{
			return a ? t : f;
		}

		public static int Iffint(bool a, int t, int f)
		{
			return a ? t : f;
		}

		public static bool IsTrigger(Collider target)
		{
			return target.isTrigger;
		}

		public static bool IsNotTrigger(Collider target)
		{
			return !target.isTrigger;
		}

		[Logic]
		[Title("Logic/Log")]
		public static void Log (string str)
		{
			Debug.Log(str);
		}

		[Logic]
		[Title("Logic/Wait")]
		public static IEnumerator Wait (float waitSeconds)
		{
			yield return new WaitForSeconds(waitSeconds);
		}

		[Logic]
		[Title("Logic/Timer")]
		public static IEnumerator Timer (float waitSeconds, int repeatCount, Action tick, Action done)
		{
			for (int i = 0; i < repeatCount; i++)
			{
				yield return new WaitForSeconds(waitSeconds);
				if (tick != null)
					tick();
			}

			if (done != null)
				done();
		}

		[Logic]
		[Title("Logic/Nop")]
		public static T Nop<T>(T arg)
		{
			return arg;
		}

		[Logic]
		[Title("Object/Instantiate")]
		[return: Title("Instantiated Object")]
		public static Object Instantiate ([Title("Object")] Object obj, Vector3 position, Quaternion rotation)
		{
			return Object.Instantiate(obj, position, rotation);
		}

		[Logic]
		[Title("Object/Destroy")]
		public static void Destroy ([Title("Object")] Object obj)
		{
			Object.Destroy(obj);
		}

		[Logic]
		[Title("Object/Dont Destroy On Load")]
		public static void DontDestroyOnLoad([Title("Object")] Object obj)
		{
			Object.DontDestroyOnLoad (obj);
		}
	}
}