Exemple #1
0
        public void AddState(RexState _state)
        {
            if (concurrentStates == null)
            {
                concurrentStates = new List <RexState>();
            }

            if (states == null)
            {
                states = new List <RexState>();
            }

            bool isStateAlreadyAdded = false;

            if (_state.isConcurrent)
            {
                for (int i = 0; i < concurrentStates.Count; i++)
                {
                    if (concurrentStates[i].id == _state.id)
                    {
                        isStateAlreadyAdded = true;
                        return;
                    }
                }

                if (!isStateAlreadyAdded)
                {
                    concurrentStates.Add(_state);
                }
            }
            else
            {
                for (int i = 0; i < states.Count; i++)
                {
                    if (states[i].id == _state.id)
                    {
                        isStateAlreadyAdded = true;
                        return;
                    }
                }

                if (!isStateAlreadyAdded)
                {
                    states.Add(_state);
                }
            }

            if (isStateAlreadyAdded)
            {
                return;
            }

            for (int i = 0; i < concurrentStates.Count; i++)
            {
                concurrentStates[i].OnNewStateAdded(_state);
            }

            for (int i = 0; i < states.Count; i++)
            {
                states[i].OnNewStateAdded(_state);
            }

            if (_state.id == BounceState.idString)
            {
                bounceState = _state.GetComponent <BounceState>();
            }
        }
Exemple #2
0
        //Attempts to set currentState to a new state
        public void SetState(RexState _state, bool canInterruptSelf = false)
        {
            bool isStateBlocked = false;

            if (_state.id == KnockbackState.idString && !currentState.isKnockbackEnabled)
            {
                isStateBlocked = true;
            }

            if (currentState && currentState.id == CrouchState.idString && !currentState.GetComponent <CrouchState>().CanExitCrouch())
            {
                isStateBlocked = true;
            }

            if (_state.id == KnockbackState.idString && isStateBlocked)
            {
                if (slots.audio && _state.audioClip)                //Play the damaged sound even if knockback itself doesn't happen
                {
                    slots.actor.PlaySoundIfOnCamera(_state.audioClip, 1.0f, slots.audio);
                }
            }

            if (isStateBlocked || slots.actor && slots.actor.isDead || !_state.isEnabled)
            {
                return;
            }

            if (_state != currentState || canInterruptSelf)
            {
                _state.hasEnded = false;

                if (_state != null)
                {
                    previousState = currentState;
                    currentState  = _state;
                }

                if (previousState)
                {
                    if (_state.id == KnockbackState.idString)
                    {
                        isKnockbackActive = true;
                        previousState.End();
                    }

                    previousState.OnStateChanged();
                }

                if (!_state.IsTurnAnimationOverriding())
                {
                    CancelTurn();
                }

                if (slots.actor)
                {
                    slots.actor.OnStateChanged(_state);
                    slots.actor.OnStateEntered(_state);
                    slots.actor.OnStateExited(previousState);
                }

                _state.OnBegin();

                if (slots.audio && _state.audioClip)
                {
                    slots.actor.PlaySoundIfOnCamera(_state.audioClip, 1.0f, slots.audio);
                }

                /*if(slots.actor.tag == "Player" && previousState)
                 *      Debug.Log(slots.actor.gameObject.name + " :: Begin State " + _state.id + "   from: " + previousState.id);*/

                if ((_state.willPlayAnimationOnBegin || slots.actor.currentAttack != null) && (!isKnockbackActive || _state.id == KnockbackState.idString))
                {
                    //Debug.Log("Playing animation for state: " + _state.id);
                    _state.PlayAnimation();
                }
            }
        }