public ChanceRunning(float probability, Func <float> randomFunction, BehaviorComponent behavior) { this.probability = probability; this.randomFunction = randomFunction; AssignBehaviors(new[] { behavior }); Name = "ChanceRunning"; }
public void Init(BehaviorComponent root) { Root = root; History = new List <BehaviorComponent>(); AlterableComponents = new Dictionary <string, Alterable>(); SetupHistoryCallBackAndAlterable(Root); }
public BehaviorTree(BehaviorComponent root) { _Root = root; _Root.behaviorTree = this; m_blackboardData = new UBlackboardData(); m_inputParam = new InsParam(); }
protected List <BehaviorComponent> m_childBehaviorsList; // 孩子节点 // 添加子节点 public override void addChild(BehaviorComponent child) { if (m_childBehaviorsList == null) { m_childBehaviorsList = new List <BehaviorComponent>(); } m_childBehaviorsList.Add(child); }
protected List<BehaviorComponent> m_childBehaviorsList; // 孩子节点 // 添加子节点 public override void addChild(BehaviorComponent child) { if(m_childBehaviorsList == null) { m_childBehaviorsList = new List<BehaviorComponent>(); } m_childBehaviorsList.Add(child); }
public void OnCalled(BehaviorComponent called, BehaviorReturnCode result) { this.AddToCalled(called); // Check if we just called the root node, so are done with the tree. if (!this.isInvokingFinalizer && this.calling.Count > 0 && this.calling[0] == called) { this.ProcessFinalizers(this.calling[0]); } }
public void buildComp(string type, BehaviorComponent comp, SecurityElement xmlElem) { if (string.IsNullOrEmpty(type)) { buildDefault(comp, xmlElem); } else { m_id2BuildDic[type](comp, xmlElem); } }
public Alterable(BehaviorComponent behavior, string id) { Name = "Atlerable"; ID = id; if (behavior is Alterable) { Debug.LogError("Cannot have Alterable BehaviorComponent child of Alterable"); return; } AssignBehaviors(new[] { behavior }); }
public BehaviorComponent UpdateBehaviors(BehaviorComponent behavior) { if (behavior is Alterable) { Debug.LogError("Cannot have Alterable Decorator as Child of Alterable"); return(this); } #if UNITY_EDITOR behaviors = new[] { (BehaviorComponent)behavior.Clone() }; #else behaviors = new[] { behavior }; #endif //BehaviorTree.RefreshBehaviorTree(); return(this); }
private void ProcessFinalizers(BehaviorComponent rootNode) { if (this.OldContext == null) { return; } foreach (var onNotCalledBehavior in this.OldContext.onNotCalledBehaviors) { if (!this.HasBeenCalled(onNotCalledBehavior)) { this.isInvokingFinalizer = true; onNotCalledBehavior.InvokeFinalizer(this); this.isInvokingFinalizer = false; } } }
public void SetupHistoryCallBackAndAlterable(BehaviorComponent behaviorComponent) { behaviorComponent.AddToHistory = AddToHistory; if (behaviorComponent is Alterable) { Alterable alterable = (Alterable)behaviorComponent; alterable.BehaviorTree = this; AlterableComponents.Add(alterable.ID, alterable); } if (behaviorComponent.Behaviors != null) { for (int i = 0; i < behaviorComponent.Behaviors.Length; i++) { BehaviorComponent behavior = behaviorComponent.Behaviors[i]; behavior.AddToHistory = AddToHistory; if (behavior.Behaviors != null) { SetupHistoryCallBackAndAlterable(behavior); } } } }
protected void depthTraverse(Stack<BehaviorComponent> stack, BehaviorComponent parentNode, SecurityElement btNode) { ArrayList btCmtNodeList = btNode.Children; BehaviorComponent btCmt; string type = ""; if (btCmtNodeList != null) { stack.Push(parentNode); foreach (SecurityElement node in btCmtNodeList) { if (m_id2CreateDic.ContainsKey(node.Tag)) { UtilXml.getXmlAttrStr(node, "type", ref type); btCmt = m_id2CreateDic[node.Tag].createComp(type); btCmt.behaviorTree = parentNode.behaviorTree; parentNode.addChild(btCmt); m_id2CreateDic[node.Tag].buildComp(type, btCmt, node); depthTraverse(stack, btCmt, node); } } stack.Pop(); } }
protected void depthTraverse(Stack <BehaviorComponent> stack, BehaviorComponent parentNode, SecurityElement btNode) { ArrayList btCmtNodeList = btNode.Children; BehaviorComponent btCmt; string type = ""; if (btCmtNodeList != null) { stack.Push(parentNode); foreach (SecurityElement node in btCmtNodeList) { if (m_id2CreateDic.ContainsKey(node.Tag)) { UtilXml.getXmlAttrStr(node, "type", ref type); btCmt = m_id2CreateDic[node.Tag].createComp(type); btCmt.behaviorTree = parentNode.behaviorTree; parentNode.addChild(btCmt); m_id2CreateDic[node.Tag].buildComp(type, btCmt, node); depthTraverse(stack, btCmt, node); } } stack.Pop(); } }
public override void addChild(BehaviorComponent child) { base.addChild(child); _selLength = (short)m_childBehaviorsList.Count; }
/// <summary> /// executes the behavior after a given amount of time in miliseconds has passed /// </summary> /// <param name="elapsedTimeFunction">function that returns elapsed time</param> /// <param name="timeToWait">maximum time to wait before executing behavior</param> /// <param name="behavior">behavior to run</param> public Timer(Func<int> elapsedTimeFunction, int timeToWait, BehaviorComponent behavior) { _ElapsedTimeFunction = elapsedTimeFunction; m_childBehavior = behavior; _WaitTime = timeToWait; }
public void buildActionFollow(BehaviorComponent btCmt, SecurityElement btNode) { }
public void buildActionWander(BehaviorComponent btCmt, SecurityElement btNode) { }
virtual protected void buildDefault(BehaviorComponent comp, SecurityElement xmlElem) { }
public void buildConditionIdle(BehaviorComponent btCmt, SecurityElement btNode) { }
/// <summary> /// executes the behavior every time again /// </summary> /// <param name="timeToWait">maximum time to wait before executing behavior</param> /// <param name="behavior">behavior to run</param> public RepeatUntilFail(BehaviorComponent behavior) { m_childBehavior = behavior; }
public UtilityPair(UtilityVector vector, BehaviorComponent behavior) { this.vector = vector; this.behavior = behavior; }
/// <summary> /// /// </summary> /// <param name="root"></param> public BehaviorTree(IndexSelector root) { _Root = root; m_inputParam = new InsParam(); m_blackboardData = new UBlackboardData(); }
public BehaviorNode(BehaviorComponent behaviorComponent, Vector2 position) { BehaviorComponent = behaviorComponent; Position = position; BehaviorComponent.Node = this; }
public void buildActionAttackAll(BehaviorComponent btCmt, SecurityElement btNode) { }
// 添加子节点 public virtual void addChild(BehaviorComponent child) { }
override protected void buildDefault(BehaviorComponent btCmt, SecurityElement btNode) { }
/// <summary> /// /// </summary> /// <param name="root"></param> public Behavior(IndexSelector root) { _Root = root; }
/// <summary> /// returns a success even when the decorated component failed /// </summary> /// <param name="behavior">behavior to run</param> public Succeeder(BehaviorComponent behavior) { m_childBehavior = behavior; }
/// <summary> /// randomly executes the behavior /// </summary> /// <param name="probability">probability of execution</param> /// <param name="randomFunction">function that determines probability to execute</param> /// <param name="behavior">behavior to execute</param> public RandomDecorator(float probability, Func <float> randomFunction, BehaviorComponent behavior) { _Probability = probability; _RandomFunction = randomFunction; m_childBehavior = behavior; }
public BehaviorTree(BehaviorComponent root) { Init(root); }
/// <summary> /// executes the behavior based on a counter /// -each time Counter is called the counter increments by 1 /// -Counter executes the behavior when it reaches the supplied maxCount /// </summary> /// <param name="maxCount">max number to count to</param> /// <param name="behavior">behavior to run</param> public Counter(int maxCount, BehaviorComponent behavior) { _MaxCount = maxCount; m_childBehavior = behavior; }
// TODO: consider moving these into a Behavior.Editor history object private void AddToHistory(BehaviorComponent behaviorComponent) { History.Add(behaviorComponent); }
private void AddToCalled(BehaviorComponent behavior) { this.called.Add(behavior); }
public Timer(float timeToWait, BehaviorComponent behavior) { AssignBehaviors(new[] { behavior }); waitTime = timeToWait; Name = "Timer"; }
public bool HasBeenCalled(BehaviorComponent behavior) { return(this.called.Contains(behavior)); }
public bool IsCalling(BehaviorComponent behavior) { return(this.calling.Contains(behavior)); }
public void OnAboutToCall(BehaviorComponent caller) { this.AddToCalling(caller); this.callCount++; }
public Behavior(BehaviorComponent root) { _Root = root; }
/// <summary> /// executes the behavior every time again /// </summary> /// <param name="timeToWait">maximum time to wait before executing behavior</param> /// <param name="behavior">behavior to run</param> public Repeater(BehaviorComponent behavior) { m_childBehavior = behavior; }