using System.Collections; using System.Collections.Generic; using UnityEngine; using XNode; using RPGCreationKit.BehaviourTree; namespace RPGCreationKit.BehaviourTree { [CreateNodeMenu("RPGCK_BehaviourTree/Wait", order = 1)] [System.Serializable] public class WaitNode : BTNode { public string did = null; public float startTime = 0.0f; public float waitTime = 0.0f; public bool randomizeWaitTime = false; public float minWait = 0.0f; public float maxWait = 1.0f; // Use this for initialization protected override void Init() { base.Init(); } // Return the correct value of an output port when requested public override object GetValue(NodePort port) { return null; // Replace this } public override NodeState Execute() { if (m_NodeState == NodeState.Success || m_NodeState == NodeState.Failure) if (hasEvaluated == true) return m_NodeState; if (!STARTED) OnStart(); if(did == "debug") { //Debug.Log(this.GetInstanceID() + " -----" + (startTime + waitTime).ToString() + " | " + Time.time); } if (startTime + waitTime < Time.time) { m_NodeState = NodeState.Success; STARTED = false; hasEvaluated = true; return m_NodeState; } m_NodeState = NodeState.Running; return m_NodeState; } public override void ReEvaluate() { if (m_NodeState != NodeState.Running) base.ReEvaluate(); } public override void OnRemoveConnection(NodePort port) { base.OnRemoveConnection(port); indexInSequence = -1; } public override void OnStart() { // Remember the start time. startTime = Time.time; if (randomizeWaitTime) waitTime = Random.Range(minWait, maxWait); STARTED = true; } } }