Пример #1
0
        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);
        }
Пример #2
0
		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;
		}
Пример #3
0
        public override BTResult Tick()
        {
            // first time
            if (_activeChild == null)
            {
                _activeChild = children[0];
                _activeIndex = 0;
            }

            BTResult result = _activeChild.Tick();

            if (result == BTResult.Ended)               // Current active node over
            {
                _activeIndex++;
                if (_activeIndex >= children.Count)                     // sequence is over
                {
                    _activeChild.Clear();
                    _activeChild = null;
                    _activeIndex = -1;
                }
                else                    // next node
                {
                    _activeChild.Clear();
                    _activeChild = children[_activeIndex];
                    result       = BTResult.Running;
                }
            }
            return(result);
        }
Пример #4
0
        public EBTResult Update()
        {
            if (null != mRoot)
            {
                return(mRoot.Tick());
            }

            return(EBTResult.Failed);
        }
        protected override Result Excute()
        {
            Result result = root.Tick();

            if (result == Result.Success)
            {
                set_postcon();
            }
            return(result);
        }
Пример #6
0
        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);
                }
            }
        }
Пример #7
0
        public override BTResult Tick()
        {
            if (_activeChild == null)
            {
                return(BTResult.Ended);
            }

            BTResult result = _activeChild.Tick();

            if (result != BTResult.Running)
            {
                _activeChild.Clear();
                _activeChild = null;
            }
            return(result);
        }
Пример #8
0
        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);
        }
Пример #9
0
        public override EBTResult Tick()
        {
            if (0 == ChildNodes.Count)
            {
                return(EBTResult.Success);
            }

            EBTResult tmpResult = EBTResult.Running;

            IsRunning = true;

            for (int i = 0, max = ChildNodes.Count; i < max; i++)
            {
                if (mCompleteChildIdxList.Contains(i))
                {
                    continue;
                }

                BTNode tmpChildNode = ChildNodes[i];

                switch (tmpChildNode.Tick())
                {
                case EBTResult.Success:
                    mCompleteChildIdxList.Add(i);

                    if (mCompleteChildIdxList.Count == ChildNodes.Count)
                    {
                        tmpResult = EBTResult.Success;
                    }
                    break;

                case EBTResult.Failed:
                    tmpResult = EBTResult.Failed;
                    break;
                }

                if (EBTResult.Running != tmpResult)
                {
                    IsRunning = false;
                    Clear();
                    break;
                }
            }

            return(tmpResult);
        }
Пример #10
0
        public override EBTResult Tick()
        {
            if (-1 == mActiveChildIndex)
            {
                mActiveChildIndex = 0;
            }

            if (mActiveChildIndex >= ChildNodes.Count)
            {
                return(EBTResult.Success);
            }

            BTNode    tmpChildNode = ChildNodes[mActiveChildIndex];
            EBTResult tmpResult    = EBTResult.Running;

            IsRunning = true;

            switch (tmpChildNode.Tick())
            {
            case EBTResult.Success:
                mActiveChildIndex++;

                if (mActiveChildIndex >= ChildNodes.Count)
                {
                    tmpResult = EBTResult.Success;
                }
                break;

            case EBTResult.Failed:
                IsRunning = false;
                tmpResult = EBTResult.Failed;
                break;
            }

            if (EBTResult.Running != tmpResult)
            {
                Clear();
            }

            return(tmpResult);
        }
Пример #11
0
        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);
        }
Пример #12
0
        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);
            }
        }
Пример #13
0
        public override EBTResult Tick()
        {
            if (-1 == mActiveChildIndex)
            {
                int tmpTotalWeight = 0;

                for (int i = 0, max = ChildNodes.Count; i < max; ++i)
                {
                    if (mFailedChildIdxList.Contains(i))
                    {
                        continue;
                    }

                    tmpTotalWeight += (i >= mChildNodeWeightList.Count ? 1 : mChildNodeWeightList[i]);
                }

                int tmpRandonValue = Random.Range(0, tmpTotalWeight);

                for (int i = 0, max = ChildNodes.Count; i < max; ++i)
                {
                    if (mFailedChildIdxList.Contains(i))
                    {
                        continue;
                    }

                    tmpRandonValue -= (i >= mChildNodeWeightList.Count ? 1 : mChildNodeWeightList[i]);

                    if (tmpRandonValue < 0)
                    {
                        mActiveChildIndex = i;
                        break;
                    }
                }
            }

            BTNode    tmpChildNode = ChildNodes[mActiveChildIndex];
            EBTResult tmpResult    = EBTResult.Running;

            IsRunning = true;

            switch (tmpChildNode.Tick())
            {
            case EBTResult.Success:
                tmpResult = EBTResult.Success;
                break;

            case EBTResult.Failed:
                mActiveChildIndex = -1;

                if (mFailedChildIdxList.Count >= ChildNodes.Count)
                {
                    tmpResult = EBTResult.Failed;
                }
                break;
            }

            if (EBTResult.Running != tmpResult)
            {
                IsRunning = false;
                Clear();
            }

            return(tmpResult);
        }
Пример #14
0
 void Update()
 {
     _root.Tick();
 }
Пример #15
0
 public void Update()
 {
     _database.characterManager.localEventManager.Move(0f, 0f);
     _root.Tick();
 }