Ejemplo n.º 1
0
 /// <summary>
 /// Only to be called in editor to replace the preloaded instance of the behavior tree.
 /// </summary>
 /// <param name="node"></param>
 public void LoadBehavior(NPCNode node)
 {
     if (!Application.isPlaying)
     {
         BehaviorTree = node;
     }
 }
Ejemplo n.º 2
0
        public new static NPCNode CreateInstance(Type nodeType)
        {
            NPCNode obj = (NPCNode)ScriptableObject.CreateInstance(nodeType);

            obj.Children = new List <NPCNode>();
            obj.Status   = BEHAVIOR_STATUS.PENDING;
            return(obj);
        }
Ejemplo n.º 3
0
 private void InitBehaviorTree()
 {
     // Load from asset?
     if (BehaviorTree != null)
     {
         BehaviorTree = LoadTree(BehaviorTree);
     }
 }
Ejemplo n.º 4
0
 public virtual bool AddChild(NPCNode n)
 {
     if (Children != null)
     {
         Children.Add(n);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 5
0
 public override bool AddChild(NPCNode node)
 {
     if (node != null)
     {
         Children = new List <NPCNode>();
         Children.Add(node);
         return(true);
     }
     return(false);
 }
Ejemplo n.º 6
0
 public void AddBehavior(NPCNode tree)
 {
     if (Status == BEHAVIOR_STATUS.INACTIVE)
     {
         BehaviorTree = tree;
     }
     else
     {
         // TODO - check status of behavior here
     }
 }
Ejemplo n.º 7
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);
 }
Ejemplo n.º 8
0
        /// <summary>
        /// Loads an asset tree from memory into a runtime copy
        /// </summary>
        /// <param name="node"></param>
        /// <returns></returns>
        private NPCNode LoadTree(NPCNode node, NPCBlackboard bb = null)
        {
            NPCNode parent = Instantiate(node);

            parent.Children.Clear();
            if (node.Blackboard != null && node.Blackboard.Root == node)
            {
                bb = node.Blackboard;
            }
            foreach (NPCNode n in node.Children)
            {
                NPCNode child = LoadTree(n, bb);
                child.Blackboard = bb;
                parent.AddChild(child);
            }
            bb = null;
            parent.SetMainAgent(gNPCController);
            return(parent);
        }
Ejemplo n.º 9
0
 public NPCDecoratorLoop(NPCNode child, NPCAssert assertion) : this(child) {
     g_Assertion = assertion;
 }
Ejemplo n.º 10
0
 public NPCDecoratorLoop(NPCNode child = null) : base()
 {
     AddChild(child);
 }