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);
        }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
        /// <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));
            }
        }
Ejemplo n.º 6
0
        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);
Ejemplo n.º 8
0
 /// <summary>
 /// Called if the AIBehaviour's Start Method is called.
 /// </summary>
 /// <param name="aiBehaviour">The connected AIBehaviour.</param>
 protected virtual void OnStart(AIBehaviour aiBehaviour)
 {
 }
Ejemplo n.º 9
0
 /// <summary>
 /// Call the OnStart method.
 /// </summary>
 /// <param name="aiBehaviour">The connected AIBehaviour.</param>
 internal void StartNode(AIBehaviour aiBehaviour)
 {
     OnStart(aiBehaviour);
 }
Ejemplo n.º 10
0
 /// <summary>
 /// Is called if the state aiBehaviour updates this State.
 /// </summary>
 /// <param name="aiBehaviour">The connected AIBehaviour.</param>
 protected virtual void OnStateUpdate(AIBehaviour aiBehaviour)
 {
 }
Ejemplo n.º 11
0
 /// <summary>
 /// Is called if the state aiBehaviour enters this State.
 /// </summary>
 /// <param name="aiBehaviour">The connected AIBehaviour.</param>
 protected virtual void OnStateEnter(AIBehaviour aiBehaviour)
 {
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Is called if this SubState needs to be executed.
 /// </summary>
 /// <param name="aiBehaviour">The connected AIBehaviour.</param>
 protected abstract void OnPerform(AIBehaviour aiBehaviour);
Ejemplo n.º 13
0
 /// <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);
 }