public void StartBehavior()
 {
     if (Status != BEHAVIOR_STATUS.INACTIVE)
     {
         BehaviorTree.Start();
     }
 }
示例#2
0
 protected override IEnumerable <BEHAVIOR_STATUS> Execute()
 {
     g_Status = BEHAVIOR_STATUS.RUNNING;
     // Only a single node will be considered
     g_Child = Children[0];
     g_Child.Start();
     while (!Finished)
     {
         if (g_Assertion != null)
         {
             // Only considers the assertion's outcome
             g_Assertion.Start();
             g_Assertion.UpdateNode();
             if (g_Assertion.Status == BEHAVIOR_STATUS.FAILURE)
             {
                 g_Status = g_Assertion.Status;
             }
             else
             {
                 if (g_Child.Finished)
                 {
                     g_Child.Start();
                 }
                 g_Child.UpdateNode();
                 yield return(g_Status);
             }
         }
         else
         {
             // Keep executing and restaring until failure
             g_Child.UpdateNode();
             if (g_Child.Finished)
             {
                 if (g_Child.Status == BEHAVIOR_STATUS.FAILURE)
                 {
                     g_Status = g_Child.Status;
                     break;
                 }
                 else
                 {
                     g_Child.Start();
                 }
             }
             yield return(g_Status);
         }
     }
     yield return(g_Status);
 }