protected override IEnumerator process(BehaviourTreeAgent agent)
        {
            BehaviourTreeNodeState myState = stateForAgent(agent);

            foreach (ConnectionPort knob in outputPorts)
            {
                if (knob.connected())
                {
                    BehaviourTreeNode      node       = knob.connection(0).body as BehaviourTreeNode;
                    BehaviourTreeNodeState childState = node.stateForAgent(agent);
                    yield return(agent.StartCoroutine(node.routine(childState)));

                    if (childState.actualCondition == processCondition.Sucess)
                    {
                        myState.actualCondition = processCondition.Sucess;
                    }
                    if (myState.actualCondition == processCondition.Sucess)
                    {
                        yield break;
                    }
                }
            }
            if (myState.actualCondition == processCondition.Running)
            {
                myState.actualCondition = processCondition.Failure;
            }
        }
Esempio n. 2
0
        private IEnumerator refreshNode(BehaviourTreeNodeState state)
        {
            yield return(new WaitForSeconds(2.0f));

            state.actualCondition = processCondition.Stopped;
            stopNode = null;
        }
Esempio n. 3
0
 void Start()
 {
     nodes  = new List <BehaviourTreeNodeState>();
     states = new Dictionary <Vector2, BehaviourTreeNodeState>();
     if (tree == null)
     {
         throw new MissingReferenceException(name + " has no Behaviour Tree");
     }
     tree.Validate();
     foreach (Node node in tree.nodes)
     {
         BehaviourTreeNodeState state = new BehaviourTreeNodeState
         {
             agent           = this,
             node            = node as BehaviourTreeNode,
             actualCondition = processCondition.Stopped
         };
         nodes.Add(state);
         states.Add(node.position, state);
         if (node.isInput())
         {
             root = node as BehaviourTreeNode;
         }
     }
     StartThinking();
 }
        protected override IEnumerator process(BehaviourTreeAgent agent)
        {
            BehaviourTreeNodeState state = stateForAgent(agent);

            state.actualCondition = processCondition.Running;
            yield return(new WaitForSeconds(waitTime));

            state.actualCondition = processCondition.Sucess;
        }
Esempio n. 5
0
        protected override IEnumerator process(BehaviourTreeAgent agent)
        {
            BehaviourTreeNodeState state      = stateForAgent(agent);
            BehaviourTreeNode      child      = outputKnob.connection(0).body as BehaviourTreeNode;
            BehaviourTreeNodeState childState = child.stateForAgent(agent);

            yield return(agent.StartCoroutine(child.routine(childState)));

            state.actualCondition = processCondition.Sucess;
        }
Esempio n. 6
0
        public IEnumerator routine(BehaviourTreeNodeState parentState)
        {
            BehaviourTreeNodeState state = stateForAgent(parentState.agent);

            if (stopNode != null)
            {
                parentState.agent.StopCoroutine(stopNode);
            }
            state.actualCondition = processCondition.Running;
            yield return(parentState.agent.StartCoroutine(process(parentState.agent)));

            parentState.agent.StartCoroutine(refreshNode(state));
        }
Esempio n. 7
0
        protected override IEnumerator process(BehaviourTreeAgent agent)
        {
            actualRepetition = 0;
            BehaviourTreeNodeState state      = stateForAgent(agent);
            BehaviourTreeNode      child      = outputKnob.connection(0).body as BehaviourTreeNode;
            BehaviourTreeNodeState childState = child.stateForAgent(agent);

            while (repeatForever || actualRepetition < repetitionQuantity)
            {
                yield return(agent.StartCoroutine(child.routine(childState)));

                actualRepetition++;
            }
            state.actualCondition = childState.actualCondition;
        }
Esempio n. 8
0
        protected override IEnumerator process(BehaviourTreeAgent agent)
        {
            actualRepetition = 0;
            BehaviourTreeNodeState state      = stateForAgent(agent);
            BehaviourTreeNode      child      = outputKnob.connection(0).body as BehaviourTreeNode;
            BehaviourTreeNodeState childState = child.stateForAgent(agent);

            do
            {
                yield return(agent.StartCoroutine(child.routine(childState)));

                actualRepetition++;
            } while ((repeatForever || actualRepetition < repetitionQuantity) && childState.actualCondition != processCondition.Failure);
            if (childState.actualCondition == processCondition.Failure)
            {
                state.actualCondition = processCondition.Sucess;
            }
            if (childState.actualCondition == processCondition.Sucess)
            {
                state.actualCondition = processCondition.Failure;
            }
        }
Esempio n. 9
0
        public BehaviourTreeNodeState stateForAgent(BehaviourTreeAgent agent)
        {
            BehaviourTreeNodeState state = agent.nodes.Where(x => x.node.position == this.position).First();

            return(state);
        }
Esempio n. 10
0
        void StartThinking()
        {
            BehaviourTreeNodeState rootState = nodes.Where(x => x.node == root).First();

            coroutine = StartCoroutine(root.routine(rootState));
        }