예제 #1
0
 public void ChangeState(IPlayerState newPlayerState)
 {
     if (playerState != null)
     {
         Debug.Log("Change state from: " + playerState.GetType() + " to: " + newPlayerState.GetType());
         playerState.OnExit();
     }
     playerState = newPlayerState;
     playerState.OnEnter();
 }
예제 #2
0
    public void FixedUpdate()
    {
        // Cache not used yet
        cacheUsedThisUpdate = false;

        // Fixedupdate might run several times per frame to "catch up" with the rest of input
        hasFinalizedCacheBeenUsedOnce = true;

        // Make a copy of the finalized cache
        // After using, only the "key hold" commands (to be executed multiple times between updates)
        //      + any remaining commands from the clone should be in the finalized cache
        Dictionary <ECommandType, Queue <ICommand> > cloneCache = new Dictionary <ECommandType, Queue <ICommand> >(finalizedCache);

        // Use a new gravity scale for this update
        currentGravityScale = playerCharacter.defaultGravityScale;
        playerCharacter.rigidBody.gravityScale = currentGravityScale;

        // Create a new list of gravity manipulators for one frame, so that a double'd input doesn't change the gravity twice
        grvManipulatorsThisFrame = new Dictionary <EInputControls, float>();

        HashSet <Type> usedStateClasses = new HashSet <Type>();

        while (true)
        {
            //MonoBehaviour.print(currentState.ToString());

            // Check if the current state wants to switch or if the update wants to switch in the middle of the update
            if (currentState.check() && (cacheUsedThisUpdate || currentState.FixedUpdate(cloneCache)))
            {
                // If the check was good and the fixedupdate finished, we are done with this full FixedUpdate call
                break;
            }

            // Prevent infinite loop
            if (usedStateClasses.Contains <Type>(currentState.getNextState().GetType()))
            {
                break;
            }

            // Otherwise we switch states and keep executing
            currentState.exit();
            currentState = currentState.getNextState();
            currentState.enter();

            // Add to list of used states
            usedStateClasses.Add(currentState.GetType());
        }

        cacheUsedThisUpdate = true;
    }
예제 #3
0
    /// <summary>
    /// ステートに応じたアニメーション描画
    /// </summary>
    /// <param name="arg_playerState">Argument player state.</param>
    private void ViewStateAnimation(IPlayerState arg_playerState)
    {
        switch (m_player.m_playerForm)
        {
        //通常形態アニメーション
        case IPlayer.PlayerForm.Normal:
            if (arg_playerState.GetType() == typeof(PlayerFall))
            {
                m_animator.Play("PlayerFall");
            }
            else if (arg_playerState.GetType() == typeof(PlayerIdle))
            {
                m_animator.Play("Player");
            }
            else if (arg_playerState.GetType() == typeof(PlayerRun))
            {
                m_animator.Play("PlayerMove");
            }
            break;

        //幽霊状態アニメーション
        case IPlayer.PlayerForm.Ghost:
            if (arg_playerState.GetType() == typeof(PlayerIdle))
            {
                m_animator.Play("PlayerGhost");
            }
            else if (arg_playerState.GetType() == typeof(PlayerRun))
            {
                m_animator.Play("PlayerGhostMove");
            }
            break;

        default:
            break;
        }
    }
예제 #4
0
 /// <summary>
 /// 現在のステート(状態)を取得する
 /// </summary>
 /// <returns>Player.○○の形式</returns>
 public System.Type GetCurrentState()
 {
     return(m_currentState.GetType());
 }