State Decide(AIBehaviour aiBehaviour, ConnectionPort[] connectedPorts) { foreach (ConnectionPort port in connectedPorts) { Node node = port.node; if (node.IsTypeOf <State> ()) { return(node as State); } if (node.IsTypeOf <Condition> ()) { Condition condition = (Condition)node; State state = condition.Decide(aiBehaviour); if (state != null) { return(state); } } } return(null); }
/// <summary> /// Exit this state. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> internal void StateExit(AIBehaviour aiBehaviour) { activeTimer.SetActive(); aiBehaviour.Log(this, $"Exit"); OnStateExit(aiBehaviour); DoSubStates(aiBehaviour, onExitOutput.connectedPorts); }
/// <summary> /// Update this state. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> internal void StateUpdate(AIBehaviour aiBehaviour) { activeTimer.SetActive(); aiBehaviour.Log(this, $"Update"); OnStateUpdate(aiBehaviour); DoSubStates(aiBehaviour, onUpdateOutput.connectedPorts); }
/// <summary> /// Decide which SubState is the next one. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> internal void Decide(AIBehaviour aiBehaviour) { bool decision = OnDecide(aiBehaviour); aiBehaviour.Log(this, $"Decision was: {decision}"); if (decision) { Decide(aiBehaviour, outputTrue.connectedPorts); } else { Decide(aiBehaviour, outputFalse.connectedPorts); } }
/// <summary> /// Decides which states is the next one. /// </summary> /// <param name="aiBehaviour">the connected AIBehaviour.</param> /// <returns>Returns the next state.</returns> public State Decide(AIBehaviour aiBehaviour) { bool decision = OnDecide(aiBehaviour); aiBehaviour.Log(this, $"Decision was: {decision}"); if (decision) { return(Decide(aiBehaviour, outputTrue.connectedPorts)); } else { return(Decide(aiBehaviour, outputFalse.connectedPorts)); } }
void DoSubStates(AIBehaviour aiBehaviour, ConnectionPort[] connectedPorts) { foreach (ConnectionPort port in connectedPorts) { if (port.node.IsTypeOf <SubState> ()) { SubState originalSubState = (SubState)port.node; originalSubState.Perform(aiBehaviour); } if (port.node.IsTypeOf <SubCondition> ()) { SubCondition originalSubCondition = (SubCondition)port.node; originalSubCondition.Decide(aiBehaviour); } } }
/// <summary> /// Check if the condition is true. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> /// <returns>Returns true or false depending on the condition.</returns> protected abstract bool OnDecide(AIBehaviour aiBehaviour);
/// <summary> /// Called if the AIBehaviour's Start Method is called. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> protected virtual void OnStart(AIBehaviour aiBehaviour) { }
/// <summary> /// Call the OnStart method. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> internal void StartNode(AIBehaviour aiBehaviour) { OnStart(aiBehaviour); }
/// <summary> /// Is called if the state aiBehaviour updates this State. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> protected virtual void OnStateUpdate(AIBehaviour aiBehaviour) { }
/// <summary> /// Is called if the state aiBehaviour enters this State. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> protected virtual void OnStateEnter(AIBehaviour aiBehaviour) { }
/// <summary> /// Is called if this SubState needs to be executed. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> protected abstract void OnPerform(AIBehaviour aiBehaviour);
/// <summary> /// Execute this SubState. /// </summary> /// <param name="aiBehaviour">The connected AIBehaviour.</param> internal void Perform(AIBehaviour aiBehaviour) { aiBehaviour.Log(this, $"Perform"); activeTimer.SetActive(); OnPerform(aiBehaviour); }