diff options
author | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2019-08-14 22:50:43 +0800 |
commit | 15740faf9fe9fe4be08965098bbf2947e096aeeb (patch) | |
tree | a730ec236656cc8cab5b13f088adfaed6bb218fb /Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/YieldedNodeBase.cs |
Diffstat (limited to 'Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/YieldedNodeBase.cs')
-rw-r--r-- | Runtime/Graphs/UnityEngine.Graphs/LogicNodeLibrary/YieldedNodeBase.cs | 54 |
1 files changed, 54 insertions, 0 deletions
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 (); + } +} |