From 15740faf9fe9fe4be08965098bbf2947e096aeeb Mon Sep 17 00:00:00 2001
From: chai <chaifix@163.com>
Date: Wed, 14 Aug 2019 22:50:43 +0800
Subject: +Unity Runtime code

---
 .../LogicNodeLibrary/Input/InputNodes.cs           | 82 ++++++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/InputNodes.cs

(limited to 'Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/InputNodes.cs')

diff --git a/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/InputNodes.cs b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/InputNodes.cs
new file mode 100644
index 0000000..d1687db
--- /dev/null
+++ b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/Input/InputNodes.cs
@@ -0,0 +1,82 @@
+using UnityEngine;
+
+namespace UnityEngine.Graphs.LogicGraph
+{
+	public partial class InputNodes
+	{
+		public delegate void AxisDelegate (float value);
+		public delegate void MouseDelegate (Vector3 mousePosition);
+
+		[Logic]
+		[Title("Input/Get Button")]
+		public static void GetButton(string buttonName, Action onDown, Action onUp, Action down, Action up)
+		{
+			if (onDown != null && Input.GetButtonDown (buttonName))
+				onDown ();
+
+			if (onUp != null && Input.GetButtonUp (buttonName))
+				onUp ();
+
+			if (down != null || up != null)
+			{
+				var stateDelegate = Input.GetButton (buttonName) ? down : up;
+				if (stateDelegate != null)
+					stateDelegate ();
+			}
+		}
+
+		[Logic]
+		[Title("Input/Get Mouse Button")]
+		public static void GetMouseButton (int mouseButton, MouseDelegate onDown, MouseDelegate onUp, MouseDelegate down, MouseDelegate up)
+		{
+			if (onDown != null && Input.GetMouseButtonDown(mouseButton))
+				onDown(Input.mousePosition);
+
+			if (onUp != null && Input.GetMouseButtonUp(mouseButton))
+				onUp(Input.mousePosition);
+
+			if (down != null || up != null)
+			{
+				MouseDelegate stateDelegate = Input.GetMouseButton(mouseButton) ? down : up;
+				if (stateDelegate != null)
+					stateDelegate(Input.mousePosition);
+			}
+		}
+
+		[Logic]
+		[Title("Input/Get Key")]
+		public static void GetKey(KeyCode key, Action onDown, Action onUp, Action down, Action up)
+		{
+			if (onDown != null && Input.GetKeyDown (key))
+				onDown ();
+
+			if (onUp != null && Input.GetKeyUp (key))
+				onUp ();
+
+			if (down != null || up != null)
+			{
+				var stateDelegate = Input.GetKey (key) ? down : up;
+				if (stateDelegate != null)
+					stateDelegate ();
+			}
+		}
+
+		[Logic]
+		[Title("Input/Get Axis")]
+		public static void GetAxis(string axisName, AxisDelegate down, AxisDelegate up)
+		{
+			AxisDelegate stateDelegate = Input.GetButton (axisName) ? down : up;
+			if (stateDelegate != null)
+				stateDelegate (Input.GetAxis (axisName));
+		}
+
+		[LogicEval]
+		[Title("Input/Mouse Position")]
+		[return: Title("Mouse Position")]
+		public static Vector3 MousePosition ()
+		{
+			return Input.mousePosition;
+		}
+	}
+}
+
-- 
cgit v1.1-26-g67d0