public override BTResult Tick () { for (int i=0; i<children.Count; i++) { if(_completeChildNumList.Contains(i)) continue; BTNode child = children[i]; switch (child.Tick()) { case BTResult.Running: isRunning = true; continue; case BTResult.Success: child.Clear(); _completeChildNumList.Add(i); return BTResult.Success; case BTResult.Failed: child.Clear(); _completeChildNumList.Add(i); continue; } } if (_completeChildNumList.Count == children.Count) { isRunning = false; _completeChildNumList.Clear (); return BTResult.Failed; } return BTResult.Running; }
private BTResult TickFromActiveChild() { if (_activeChildIndex == -1) { _activeChildIndex = 0; } for (; _activeChildIndex < children.Count; _activeChildIndex++) { BTNode activeChild = children[_activeChildIndex]; switch (activeChild.Tick()) { case BTResult.Running: isRunning = true; return(BTResult.Running); case BTResult.Success: activeChild.Clear(); continue; case BTResult.Failed: activeChild.Clear(); _activeChildIndex = -1; isRunning = false; return(BTResult.Failed); } } _activeChildIndex = -1; isRunning = false; return(BTResult.Success); }
public override void Clear() { base.Clear(); switch (clearOpt) { case BTClearOpt.Default: if (_activeChildIndex != -1) { children[_activeChildIndex].Clear(); } break; case BTClearOpt.Selected: foreach (BTNode child in selectedChildrenForClear) { int index = children.IndexOf(child); if (index > _previousSuccessChildIndex) { child.Clear(); } } break; case BTClearOpt.DefaultAndSelected: if (_activeChildIndex != -1) { BTNode activeChild = children[_activeChildIndex]; if (!selectedChildrenForClear.Contains(activeChild)) { activeChild.Clear(); } } int split = Mathf.Max(_activeChildIndex, _previousSuccessChildIndex); foreach (BTNode child in selectedChildrenForClear) { int index = children.IndexOf(child); if (index > split) { child.Clear(); } } break; case BTClearOpt.All: split = Mathf.Max(_activeChildIndex - 1, _previousSuccessChildIndex); foreach (BTNode child in children) { int index = children.IndexOf(child); if (index > split) { child.Clear(); } } break; } _activeChildIndex = -1; _previousSuccessChildIndex = -1; }
public void Clear() { if (null != mRoot) { mRoot.Clear(); } }
public override BTResult Tick() { int startPos = Random.Range(0, children.Count); for (int a = 0; a < children.Count; a++) { int i = a + startPos; if (i > children.Count) { i -= children.Count; } BTNode child = children[i]; switch (child.Tick()) { case BTResult.Running: if (_activeChildIndex != i && _activeChildIndex != -1) { children[_activeChildIndex].Clear(); } _activeChildIndex = i; _previousSuccessChildIndex = -1; isRunning = true; return(BTResult.Running); case BTResult.Success: if (_activeChildIndex != i && _activeChildIndex != -1) { children[_activeChildIndex].Clear(); } child.Clear(); _activeChildIndex = -1; _previousSuccessChildIndex = i; isRunning = false; return(BTResult.Success); case BTResult.Failed: child.Clear(); continue; } } _activeChildIndex = -1; _previousSuccessChildIndex = -1; isRunning = false; return(BTResult.Failed); }
// selects the active child protected override bool DoEvaluate() { foreach (BTNode child in children) { if (child.Evaluate()) { if (_activeChild != null && _activeChild != child) { _activeChild.Clear(); } _activeChild = child; return(true); } } _activeChild = null; return(false); }
protected override bool DoEvaluate() { if (_activeChild != null) { bool result = _activeChild.Evaluate(); if (!result) { _activeChild.Clear(); _activeChild = null; _activeIndex = -1; } return(result); } else { return(children[0].Evaluate()); } }
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 BTResult Tick() { for (int i = 0; i < children.Count; i++) { BTNode child = children[i]; switch (child.Tick()) { case BTResult.Running: if (_activeChildIndex != i && _activeChildIndex != -1) { children[_activeChildIndex].Clear(); } _activeChildIndex = i; _previousSuccessChildIndex = -1; isRunning = true; return(BTResult.Running); case BTResult.Success: if (_activeChildIndex != i && _activeChildIndex != -1) { children[_activeChildIndex].Clear(); } child.Clear(); _activeChildIndex = -1; _previousSuccessChildIndex = i; isRunning = false; return(BTResult.Success); case BTResult.Failed: child.Clear(); continue; } } _activeChildIndex = -1; _previousSuccessChildIndex = -1; isRunning = false; return(BTResult.Failed); }
private void RunBackground() { for (int i = _runningChildren.Count - 1; i >= 0; i--) { BTNode child = _runningChildren[i]; BTResult result = child.Tick(); if (result != BTResult.Running) { child.Clear(); _runningChildren.RemoveAt(i); } } }
public override void Clear() { base.Clear(); for (int i = 0, max = ChildNodes.Count; i < max; ++i) { BTNode tmpNode = ChildNodes[i]; if (null != tmpNode) { tmpNode.Clear(); } } }
public override BTResult Tick() { if (_primaryChild == null) { Debug.LogError("Primary Child not set!"); } BTResult primaryChildResult = _primaryChild.Tick(); if (primaryChildResult == BTResult.Running) { RunBackground(); isRunning = true; return(BTResult.Running); } else { _shouldClearPrimaryChild = false; _primaryChild.Clear(); isRunning = false; return(primaryChildResult); } }
public override EBTStatus Step() { if (mActiveIndex == -1) { mActiveIndex = 0; } for (; mActiveIndex < mChildren.Count; mActiveIndex++) { BTNode pNode = mChildren[mActiveIndex]; EBTStatus pStatus = pNode.Step(); switch (pStatus) { case EBTStatus.BT_RUNNING: { mIsRunning = true; return(EBTStatus.BT_RUNNING); } case EBTStatus.BT_SUCCESS: { pNode.Clear(); continue; } case EBTStatus.BT_FAILURE: { mActiveIndex = -1; mIsRunning = false; pNode.Clear(); return(EBTStatus.BT_FAILURE); } } } mActiveIndex = -1; mIsRunning = false; return(EBTStatus.BT_SUCCESS); }
public override BTStatus Step() { if (m_ActiveIndex == -1) { m_ActiveIndex = 0; } for (; m_ActiveIndex < m_Children.Count; m_ActiveIndex++) { 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(); continue; } case BTStatus.Failure: { m_ActiveIndex = -1; m_IsRunning = false; pNode.Clear(); return(BTStatus.Failure); } } } m_ActiveIndex = -1; m_IsRunning = false; return(BTStatus.Success); }
public override EBTStatus Step() { for (int i = 0; i < mChildren.Count; i++) { if (mFinishChildrenIndexList.Contains(i)) { continue; } BTNode pNode = mChildren[i]; EBTStatus pStatus = pNode.Step(); if (pStatus != EBTStatus.BT_RUNNING) { pNode.Clear(); mFinishChildrenIndexList.Add(i); } } mIsRunning = (mFinishChildrenIndexList.Count < mChildren.Count); return((mIsRunning) ? EBTStatus.BT_RUNNING : EBTStatus.BT_SUCCESS); }
public override BTStatus Step() { for (int i = 0; i < m_Children.Count; i++) { if (m_FinishChildrenIndexList.Contains(i)) { continue; } BTNode pNode = m_Children[i]; BTStatus pStatus = pNode.Step(); if (pStatus != BTStatus.Running) { pNode.Clear(); m_FinishChildrenIndexList.Add(i); } } m_IsRunning = (m_FinishChildrenIndexList.Count < m_Children.Count); return((m_IsRunning) ? BTStatus.Running : BTStatus.Success); }
public override void Clear() { base.Clear(); switch (clearOpt) { case BTClearOpt.Default: if (_activeChildIndex != -1) { children[_activeChildIndex].Clear(); } break; case BTClearOpt.Selected: foreach (BTNode child in selectedChildrenForClear) { int index = children.IndexOf(child); // greater than active child index means they are not cleared yet // also if _activeChildIndex is -1, then all selected children will be cleared if (index >= _activeChildIndex) { child.Clear(); } } break; case BTClearOpt.DefaultAndSelected: if (_activeChildIndex != -1) { BTNode activeChild = children[_activeChildIndex]; if (!selectedChildrenForClear.Contains(activeChild)) { activeChild.Clear(); } } foreach (BTNode child in selectedChildrenForClear) { int index = children.IndexOf(child); if (index >= _activeChildIndex) { child.Clear(); } } break; case BTClearOpt.All: if (_activeChildIndex > -1) { for (int i = _activeChildIndex; i < children.Count; i++) { if (i < 0) { continue; } children[i].Clear(); } } break; } _activeChildIndex = -1; }