Exemple #1
0
        public void ChangeState(string destinationState)
        {
            if (string.IsNullOrEmpty(destinationState))
            {
                throw new ArgumentException("Invalid state");
            }

            if (_CurrentState != null && _CurrentState.Name == destinationState)
            {
                return;
            }
            if (_NextState != null)
            {
                return;
            }
            _NextState = null;
            if (!_States.TryGetValue(destinationState, out _NextState))
            {
                throw new ArgumentException("Invalid state");
            }
            Status.Interrupt();
        }
Exemple #2
0
        /// <summary>
        /// Force update tree even not reach UpdateTimeInterval
        /// </summary>
        public void ForceUpdate()
        {
            this._Reset          = false;
            this._LastUpdateTime = UnityEngine.Time.time;

            if (_NextState != null && _NextState != _CurrentState)
            {
                foreach (var runningAction in Status.RunningActions)
                {
                    runningAction.Action.Interrupt();
                }
                Status.RunningActions.Clear();

                string preState = string.Empty;
                if (_CurrentState != null)
                {
                    Status.Begin();
                    _CurrentState.ResetBehavior(this.Status);
                    preState = _CurrentState.Name;
                }
                _CurrentState = _NextState;
                OnStateChanged(preState, _CurrentState.Name);
            }
            _NextState = null;

            Status.Begin();
            CurrentState.Execute(Status);

            if (Status.Exception != null)
            {
                UnityEngine.Debug.LogException(Status.Exception);
            }

            CurrentState.ResetBehavior(this.Status);
            OnUpdated();
        }