예제 #1
0
 public BehaviourTree(BT_Node _root)
 {
     root          = _root;
     interrupts    = new List <BT_Interrupt>();
     timings       = new List <Timing>();
     continueNodes = new Queue <BT_Node>();
 }
예제 #2
0
 public BT_While(BT_Node _c, BT_Node _p, IfEvent _e)
 {
     children = new List <BT_Node>();
     children.Add(_c);
     parent    = _p;
     condition = _e;
 }
예제 #3
0
 public BT_Execute(BT_Node _c, BT_Node _p, NodeEvent _e)
 {
     nodeEvent = _e;
     children  = new List <BT_Node>();
     children.Add(_c);
     parent = _p;
 }
예제 #4
0
 virtual public void AddChild(BT_Node c)
 {
     if (children == null)
     {
         children = new List <BT_Node>();
     }
     children.Add(c);
 }
예제 #5
0
 public BT_Node()
 {
     children = new List <BT_Node>();
     parent   = null;
 }
예제 #6
0
 public BT_Sequence(List <BT_Node> cList, BT_Node parent)
 {
     children     = cList;
     currentIndex = 0;
 }
예제 #7
0
 public BT_Selector(List <BT_Node> cList, BT_Node _p)
 {
     children = cList;
     parent   = _p;
 }
예제 #8
0
 public Timer(BT_Node node, double _waitTime) : base(node)
 {
     startTime = 0;
     waitTime  = _waitTime;
 }
예제 #9
0
        public void Tick()
        {
            // Check Timings
            int  timingLength      = timings.Count;
            bool isTimingActivated = false;
            int  activatedIndex    = -1;

            for (int i = 0; i < timingLength; i++)
            {
                if (timings[i].Check() && !isTimingActivated)
                {
                    isTimingActivated = true;
                    activatedIndex    = i;
                }
            }

            if (isTimingActivated && activatedIndex >= 0)
            {
                ResultContainer _result = timings[activatedIndex].Next();
                ProcessResult(_result);
                timings.RemoveAt(activatedIndex);

                return;
            }

            bool isInterruptActivated = false;

            if (!isTimingActivated)
            {
                // Check Interrupts
                foreach (BT_Interrupt interrupt in interrupts)
                {
                    if (interrupt.IsInterrupt())
                    {
                        ResultContainer _result = interrupt.Next();
                        ProcessResult(_result);
                        isInterruptActivated = true;
                        return;
                    }
                }
            }

            if (!isTimingActivated && !isInterruptActivated)
            {
                ResultContainer result = new ResultContainer();
                if (continueNodes.Count > 0)
                {
                    do
                    {
                        BT_Node nextNode = continueNodes.Dequeue();
                        result = nextNode.Next();
                    } while (result.Result == BT_Result.FAILURE && continueNodes.Count > 0);

                    if (result.Result == BT_Result.FAILURE)
                    {
                        result = root.Next();
                    }
                }
                else
                {
                    result = root.Next();
                }
                ProcessResult(result);
            }
        }