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/YieldedNodeBase.cs            | 54 ++++++++++++++++++++++
 1 file changed, 54 insertions(+)
 create mode 100644 Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/YieldedNodeBase.cs

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

diff --git a/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/YieldedNodeBase.cs b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/YieldedNodeBase.cs
new file mode 100644
index 0000000..2086d95
--- /dev/null
+++ b/Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/YieldedNodeBase.cs
@@ -0,0 +1,54 @@
+using System.Collections;
+using UnityEngine;
+
+namespace UnityEngine.Graphs.LogicGraph
+{
+	public abstract class YieldedNodeBase
+	{
+		protected float m_Time;
+		protected float m_Percentage;
+
+		public Action done;
+		public Action update;
+
+		public virtual float totalTime { set { m_Time = value; } }
+		public virtual float percentage { get { return m_Percentage; } }
+
+		protected YieldedNodeBase () {}
+
+		protected YieldedNodeBase (float time)
+		{
+			m_Time = time;
+		}
+
+		public IEnumerator Start ()
+		{
+			OnStart ();
+
+			if (m_Time > 0.0f)
+			{
+				float doneTime = Time.time + m_Time;
+				float t = 0;
+				do
+				{
+					t += Time.deltaTime;
+					m_Percentage = t / m_Time;
+
+					OnUpdate();
+					if (update != null)
+						update();
+
+					yield return 0;
+				} while (Time.time < doneTime);
+			}
+
+			OnDone();
+			if (done != null)
+				done();
+		}
+
+		protected abstract void OnStart ();
+		protected abstract void OnUpdate ();
+		protected abstract void OnDone ();
+	}
+}
-- 
cgit v1.1-26-g67d0