protected override BTResult OnTick(BTContext context) { if (_activeChildIndex == -1) { _activeChildIndex = 0; } for (; _activeChildIndex < m_Children.Count; _activeChildIndex++) { BTNode activeChild = m_Children[_activeChildIndex]; BTResult result = activeChild.Tick_(context); switch (result.Code) { case BTResultCode.Running: Running = true; return(BTResult.Running); case BTResultCode.Success: activeChild.Reset(); continue; case BTResultCode.Failed: activeChild.Reset(); _activeChildIndex = -1; Running = false; return(BTResult.Failed); } } _activeChildIndex = -1; Running = false; return(BTResult.Success); }
protected override BTResult OnTick(BTContext context) { for (int i = 0; i < m_Children.Count; i++) { BTNode child = m_Children[i]; BTResult result = child.Tick_(context); switch (result.Code) { case BTResultCode.Running: if (_activeChildIndex != i && _activeChildIndex != -1) { m_Children[_activeChildIndex].Reset(); } _activeChildIndex = i; _previousSuccessChildIndex = -1; Running = true; return(BTResult.Running); case BTResultCode.Success: if (_activeChildIndex != i && _activeChildIndex != -1) { m_Children[_activeChildIndex].Reset(); } child.Reset(); _activeChildIndex = -1; _previousSuccessChildIndex = i; Running = false; return(BTResult.Success); case BTResultCode.Failed: child.Reset(); continue; } } _activeChildIndex = -1; _previousSuccessChildIndex = -1; Running = false; return(BTResult.Failed); }