/// <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; } }
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); }
private void InitBehaviorTree() { // Load from asset? if (BehaviorTree != null) { BehaviorTree = LoadTree(BehaviorTree); } }
public virtual bool AddChild(NPCNode n) { if (Children != null) { Children.Add(n); return(true); } return(false); }
public override bool AddChild(NPCNode node) { if (node != null) { Children = new List <NPCNode>(); Children.Add(node); return(true); } return(false); }
public void AddBehavior(NPCNode tree) { if (Status == BEHAVIOR_STATUS.INACTIVE) { BehaviorTree = tree; } else { // TODO - check status of behavior here } }
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); }
/// <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); }
public NPCDecoratorLoop(NPCNode child, NPCAssert assertion) : this(child) { g_Assertion = assertion; }
public NPCDecoratorLoop(NPCNode child = null) : base() { AddChild(child); }