public Parallel(int childrenTickInterval, params BTNode[] children) { this.childrenTickInterval = childrenTickInterval; this.children = children; lastStatus = BTStatus.Failed; /* allow tasks to initialize */ }
public override BTStatus Execute() { BTStatus rv = BTStatus.FAILURE; for (int i = CurrentChildIndex; i < children.Count; i++) //Current childindex is the table { rv = children[i].Execute(); //Selector CurrentChildIndex = i; //Updating the current child index. if (rv == BTStatus.FAILURE) // if it fails it returns to the top { return(rv); } if (rv == BTStatus.RUNNING) //if it runs it returns to the top { return(rv); } if (rv == BTStatus.SUCCESS) //if we are good it resets { Reset(); return(rv); } if (rv == BTStatus.FAILURE && (CurrentChildIndex + 1) == children.Count) //it fals on the last child node, it resets and returns failure { Reset(); return(rv); } } return(rv); }
public override BTStatus Execute() { for (int i = 0; i < children.Length; i++) { if (!children[i].CanExecute()) { continue; } if (lastRunningChildIndex != null && i != lastRunningChildIndex) { children[lastRunningChildIndex.Value].ResetState(); } BTStatus status = children[i].Execute(); if (status == BTStatus.Success) { lastRunningChildIndex = null; return(status); } else if (status == BTStatus.Running) { lastRunningChildIndex = i; return(status); } } lastRunningChildIndex = null; return(BTStatus.Failed); }
public override BTStatus Execute() { BTStatus rv = BTStatus.FAILURE; for (int i = CurrentChildIndex; i < children.Count; i++) //Current childindex is the table { rv = children[i].Execute(); //Selector CurrentChildIndex = i; //Updating the current child index. if (rv == BTStatus.FAILURE) { Reset(); return(rv); } if (rv == BTStatus.RUNNING) //if it runs it returns to the top { return(rv); } if (rv == BTStatus.SUCCESS && (CurrentChildIndex + 1) == children.Count) //if all nodes succed, return success. { Reset(); } return(rv); } return(rv); }
public override BTStatus Execute() { BTStatus rv = BTStatus.SUCCESS; Debug.Log("Zombie Biting"); return(rv); }
public sealed override BTStatus Step() { m_Result = BTStatus.Success; if (m_Status == BTStatus.Initial) { bool checkCondition = Enter(); m_Status = checkCondition ? BTStatus.Running : BTStatus.Failure; } if (m_Status == BTStatus.Running) { bool success = Prepare(); if (success) { m_Result = Execute(); if (m_Result != BTStatus.Running) { Exit(); m_Status = BTStatus.Initial; m_IsRunning = false; } else { m_IsRunning = true; } } else { m_IsRunning = true; return(BTStatus.Running); } } return(m_Result); }
protected override BTResult OnTick(ref BTInput _input) { BTResult result = BTResult.Success; if (mStatus == BTStatus.Ready) { OnEnter(_input); mNeedExit = true; mStatus = BTStatus.Running; } if (mStatus == BTStatus.Running) { result = OnExecute(ref _input); if (result == BTResult.Success || result == BTResult.Failed) { mStatus = BTStatus.Finish; } } if (mStatus == BTStatus.Finish) { if (mNeedExit) { OnExit(_input, result); } mStatus = BTStatus.Ready; mNeedExit = false; } return(result); }
public BTStatus Tick(float time, T context) { BTStatus result = BTStatus.Running; int count = 0; foreach (INode <T> node in _nodes) { BTStatus status = node.Tick(time, context); switch (status) { case BTStatus.Success: count++; break; case BTStatus.Failed: result = BTStatus.Failed; break; default: break; } } return(result); }
public override BTStatus Tick() { BTStatus status = ChildrenNodes[NowChild].Tick(); switch (status) { case BTStatus.Fail: NowChild = 0; return(BTStatus.Fail); case BTStatus.Running: return(BTStatus.Running); case BTStatus.Success: NowChild++; if (NowChild == ChildrenNodes.Count) { NowChild = 0; return(BTStatus.Success); } return(BTStatus.Running); case BTStatus.Exit: NowChild = 0; return(BTStatus.Exit); } throw new System.Exception("no node, but try get it"); }
public BTNode OpenBranch(BTNode _node, BTStatus _decorator, BTStatus falseStatus) { ChildNode = _node; DecoratorStatus = _decorator; FalseStatus = falseStatus; return(this); }
public override BTStatus Execute() { BTStatus RV = BTStatus.FAILURE; bool failure = false; for (int i = 0; i < children.Count; i++) //Iterate through children and continue until a success is found. { RV = children[i].Execute(); if (RV == BTStatus.SUCCESS) { return(RV); } else if (RV == BTStatus.RUNNING) { CurrentChildIndex = i; return(BTStatus.RUNNING); } else if (RV == BTStatus.FAILURE) { failure = true; } } //If a success is not found, return a failure //CurrentChildIndex = 0; if (failure == true) { return(BTStatus.FAILURE); } else { return(BTStatus.SUCCESS); } }
public override BTStatus Tick() { RandomNodes(); BTStatus status = ChildrenNodes[NowChild].Tick(); switch (status) { case BTStatus.Fail: NowChild++; if (NowChild >= ChildrenNodes.Count) { NowChild = 0; } return(BTStatus.Fail); case BTStatus.Running: return(BTStatus.Running); case BTStatus.Success: NowChild = 0; return(BTStatus.Success); case BTStatus.Exit: NowChild = 0; return(BTStatus.Exit); } throw new System.NotImplementedException(); }
public override BTStatus Step() { BTStatus pStatus = base.Step(); switch (pStatus) { case BTStatus.Success: { Count++; base.Clear(); break; } case BTStatus.Running: { break; } case BTStatus.Failure: { return(BTStatus.Failure); } } return(Count >= Times ? BTStatus.Success : BTStatus.Running); }
public void Step() { for (int i = 0; i < m_BTTrees.Count; i++) { BTTree tree = m_BTTrees[i]; BTStatus pStatus = tree.Step(); switch (pStatus) { case BTStatus.Initial: break; case BTStatus.Running: break; case BTStatus.Success: case BTStatus.Failure: { m_DeleteList.Add(tree); } break; } } for (int i = 0; i < m_DeleteList.Count; i++) { BTTree tree = m_DeleteList[i]; m_BTTrees.Remove(tree); tree.Clear(); } m_DeleteList.Clear(); }
public override void Clear() { base.Clear(); if (m_Status != BTStatus.Initial) { Exit(); m_Status = BTStatus.Initial; } }
protected override void OnTransition(BTInput _input) { if (mNeedExit) { OnExit(_input, BTResult.Failed); } mStatus = BTStatus.Ready; mNeedExit = false; }
// Update is called once per frame void Update() { BTStatus status = rootNode.Tick(Time.deltaTime, bb); Debug.Log(status + "passedTime: " + bb.passedTime); if (status == BTStatus.Success) { bb.passedTime = 0.0f; } }
public override BTStatus Execute() { BTStatus rv = BTStatus.RUNNING; if ((zombieRef.transform.position - zBB.MoveToLocation).magnitude <= 1.0f) { Debug.Log("Reached target"); rv = BTStatus.SUCCESS; } return(rv); }
public override BTStatus Execute() { BTStatus rv = BTStatus.FAILURE; if (CheckStatus()) { rv = WrappedNode.Execute(); } return(rv); }
public BTStatus Tick(float time, T context) { foreach (INode <T> node in _nodes) { BTStatus status = node.Tick(time, context); if (status != BTStatus.Success) { return(status); } } return(BTStatus.Success); }
public override BTStatus Tick() { BTStatus status = ChildNode.Tick(); // 子节点匹配装饰节点 if (status == DecoratorStatus) { return(DecoratorStatus); } // 不匹配装饰节点 else { return(FalseStatus); } }
public override BTStatus Execute() { BTStatus rv = WrappedNode.Execute(); if (rv == BTStatus.FAILURE) { rv = BTStatus.SUCCESS; } else if (rv == BTStatus.SUCCESS) { rv = BTStatus.FAILURE; } return(rv); }
public override BTStatus Execute() { BTStatus rv = BTStatus.RUNNING; if (Vector3.Distance(mBB.FleeTarget.transform.position, MinerRef.transform.position) > mBB.FleeProximity - 1) { rv = BTStatus.SUCCESS; MinerRef.SB.EvadeOff(); MinerRef.SB.FleeOff(); MinerRef.SB.Stop(); mBB.fleeing = false; } return(rv); }
public BTStatus Tick(float time, T context) { BTStatus status = _node.Tick(time, context); switch (status) { case BTStatus.Success: return(BTStatus.Failed); case BTStatus.Failed: return(BTStatus.Success); default: return(status); } }
public override BTStatus Step() { for (int i = 0; i < m_Children.Count; i++) { BTNode pNode = m_Children[i]; BTStatus pStatus = pNode.Step(); switch (pStatus) { case BTStatus.Running: { if (m_ActiveIndex != i && m_ActiveIndex != -1) { m_Children[m_ActiveIndex].Clear(); } m_ActiveIndex = i; m_PreviaIndex = -1; m_IsRunning = true; return(BTStatus.Running); } case BTStatus.Success: { if (m_ActiveIndex != i && m_ActiveIndex != -1) { m_Children[m_ActiveIndex].Clear(); } pNode.Clear(); m_ActiveIndex = -1; m_PreviaIndex = i; m_IsRunning = false; return(BTStatus.Success); } case BTStatus.Failure: { pNode.Clear(); return(BTStatus.Failure); } } } m_IsRunning = false; return(BTStatus.Failure); }
public override BTStatus Step() { if (m_ActiveIndex == -1) { m_ActiveIndex = UnityEngine.Random.Range(0, m_Children.Count); } if (m_Children.Count > 0) { BTNode pNode = m_Children[m_ActiveIndex]; BTStatus pStatus = pNode.Step(); switch (pStatus) { case BTStatus.Running: { m_IsRunning = true; return(BTStatus.Running); } case BTStatus.Success: { pNode.Clear(); m_ActiveIndex = -1; m_PreviaIndex = m_ActiveIndex; m_IsRunning = false; return(BTStatus.Success); } case BTStatus.Failure: { pNode.Clear(); m_ActiveIndex = -1; m_PreviaIndex = -1; m_IsRunning = false; return(BTStatus.Failure); } } } m_ActiveIndex = -1; m_PreviaIndex = -1; m_IsRunning = false; return(BTStatus.Failure); }
public override BTStatus Execute() { BTStatus rv = BTStatus.RUNNING; if (!Started && !DelayFinished) { Started = true; regulator.Start(); } else if (DelayFinished) { DelayFinished = false; Started = false; rv = BTStatus.SUCCESS; } return(rv); }
public override BTStatus Execute() { for (int i = currentChildIndex; i < children.Length; i++) { if (!alwaysLoop) { currentChildIndex = i; } BTStatus status = children[i].Execute(); if (status != BTStatus.Success) { return(status); } } currentChildIndex = 0; return(BTStatus.Success); }
public override BTStatus Execute() { if (FirstRun) { FirstRun = false; Debug.Log("Moving to player"); // perhaps the BTNode should have some "start" function that // can be overridden in child classes so we don't have to do this? } BTStatus rv = BTStatus.RUNNING; zombieRef.ZombieMoveTo(zBB.PlayerLocation); if ((zombieRef.transform.position - zBB.PlayerLocation).magnitude <= 1.0f) { Debug.Log("Reached the player"); rv = BTStatus.SUCCESS; FirstRun = true; } return(rv); }
public override BTStatus Execute() { BTStatus RV = BTStatus.FAILURE; for (int i = 0; i < children.Count; i++) //Iterate through all children UNTIL a failure occurs. { RV = children[i].Execute(); if (RV == BTStatus.FAILURE) { return(RV); } else if (RV == BTStatus.RUNNING) { CurrentChildIndex = i; return(BTStatus.RUNNING); } } //CurrentChildIndex = 0; return(BTStatus.SUCCESS); //If no failure occurs, return a success }