コード例 #1
0
ファイル: SequenceNode.cs プロジェクト: bli0219/Double-Helix
 public override void Tick()
 {
     if (activeChild == -1)   // no child ticked, ignore LastStatus, tick first child
     {
         try {
             activeChild = 0;
             BehaviorTree.path.Push(Children[activeChild]);
         } catch {
             Debug.LogError("Empty Children[]");
         }
     }
     else                                                   // some child already ticked, check result
     {
         if (BehaviorTree.lastStatus == NodeStatus.Failure) // fail if any failure
         {
             activeChild = -1;
             BehaviorTree.Finish(NodeStatus.Failure);
         }
         else                                       // no failure yet
         {
             if (activeChild < Children.Length - 1) // if last activeChild was not the last
             {
                 activeChild++;
                 BehaviorTree.path.Push(Children[activeChild]);
             }
             else     // reached the last, still no failure
             {
                 activeChild = -1;
                 BehaviorTree.Finish(NodeStatus.Success);
             }
         }
     }
 }
コード例 #2
0
 public override void Tick()
 {
     if (!started)
     {
         BehaviorTree.path.Push(Child);
     }
     else
     {
         NodeStatus inverted = BehaviorTree.lastStatus == NodeStatus.Success ? NodeStatus.Failure : NodeStatus.Success;
         BehaviorTree.Finish(inverted);
     }
 }
コード例 #3
0
 // If condition met, push child
 // Return Success when child succeeds, Failure otherwise
 // Ticked only twice: when pushed and when poped
 public override void Tick()
 {
     if (!started)
     {
         started = true;
         if (Fn())
         {
             BehaviorTree.path.Push(Child);
         }
         else
         {
             BehaviorTree.Finish(NodeStatus.Failure);
         }
     }
     else
     {
         BehaviorTree.Finish(BehaviorTree.lastStatus);
     }
 }
コード例 #4
0
        public override void Tick()
        {
            // this condition is most frequently used, so put it first

            if (!started)
            {
                started = true;
                BehaviorTree.path.Push(Child);
            }
            else
            {
                if (BehaviorTree.lastStatus == NodeStatus.Success)
                {
                    BehaviorTree.path.Push(Child);
                }
                else
                {
                    BehaviorTree.Finish(NodeStatus.Failure);
                }
            }
        }
コード例 #5
0
ファイル: SelectorNode.cs プロジェクト: bli0219/RhythmFighter
 // use global variable to pass status
 public override void Tick()
 {
     if (activeChild == -1)
     {
         // no child ticked, ignore LastStatus, tick first child
         // assuming Children.Length > 0
         try {
             activeChild = 0;
             BehaviorTree.path.Push(Children[activeChild]);
         } catch {
             Debug.LogError("Empty Children[]");
         }
     }
     else
     {
         // some child ticked
         if (BehaviorTree.lastStatus == NodeStatus.Success)
         {
             // succeed if any success
             activeChild = -1;
             BehaviorTree.Finish(NodeStatus.Success);
         }
         else
         {
             // no success yet
             if (activeChild < Children.Length - 1)
             {
                 // if last activeChild is not the last
                 activeChild++;
                 BehaviorTree.path.Push(Children[activeChild]);
             }
             else
             {
                 // reached the last, still no success
                 activeChild = -1;
                 BehaviorTree.Finish(NodeStatus.Failure);
             }
         }
     }
 }
コード例 #6
0
        public override void Tick()
        {
            if (scores == null)
            {
                scores = new List <int>(new int[Children.Length]);
            }
            else
            {
                Debug.LogWarning("Scores not initialized");
            }

            if (!ticked)
            {
                int largest = 0;
                for (int i = 1; i != scores.Count; i++)
                {
                    if (scores[i] > scores[largest])
                    {
                        largest = i;
                    }
                }
                lastTicked = largest;
                BehaviorTree.path.Push(Children[largest]);
            }
            else
            {
                if (BehaviorTree.lastStatus == NodeStatus.Success)
                {
                    scores[lastTicked] += 1;
                }
                if (BehaviorTree.lastStatus == NodeStatus.Failure)
                {
                    scores[lastTicked] -= 1;
                }
                BehaviorTree.Finish(BehaviorTree.lastStatus);
            }
        }