Exemplo n.º 1
0
    // Start is called before the first frame update
    void Awake()
    {
        // Initilize the state array
        currentStateIndex = 0;
        allStates         = new PlayerStateBase[3];
        allStates[0]      = playerStateGuitar;
        allStates[1]      = playerStateRecord;
        allStates[2]      = playerStateTrumpet;

        // Set references and components
        myCC        = GetComponent <CharacterController>();
        myTransform = transform;
        mainCamera  = Camera.main;
        myAnimator  = GetComponent <Animator>();
        audioSource = GetComponent <AudioSource>();

        // Set the initial state of the player
        currentState = playerStateGuitar;

        // Begin cycling between states
        //InvokeRepeating("CycleStates", switchStateSeconds, switchStateSeconds);
        StartCoroutine(CycleStates());

        // Set a layer mask so that we only hit things marked as default
        layerMask = LayerMask.GetMask("Default");
    }
Exemplo n.º 2
0
    //添加新状态到集合
    void AddState <T>() where T : PlayerStateBase
    {
        //添加状态类脚本到物体
        PlayerStateBase state = gameObject.AddComponent <T>();

        state.OnInit();                     //初始化状态
        states.Add(state.GetType(), state); //添加到状态集合
    }
Exemplo n.º 3
0
        public override void OnEnter(Player owner, PlayerStateBase prevState)
        {
            // 動作停止
            owner.enabled = false;
            owner.GetComponent <Collider>().enabled = false;

            // 吹っ飛ばす
            owner.rigidBody.constraints = RigidbodyConstraints.FreezePositionZ | RigidbodyConstraints.FreezeRotationX;
            owner.rigidBody.AddForce(owner.deathAddForce, ForceMode.Impulse);
            owner.rigidBody.AddTorque(owner.deathAddTorque, ForceMode.Impulse);
        }
Exemplo n.º 4
0
 //State Related Methods////////////////////
 public void SetState(Type state)
 {
     if (_currentState.GetType() == state)
     {
         return;
     }
     Debug.Log("Player Changing from: " + _currentState.GetType() + " to: " + state);
     _currentState.EndState();
     _currentState = _states[state];
     _currentState.BeginState();
 }
Exemplo n.º 5
0
    //切换状态
    public void ChangeState <T>() where T : PlayerStateBase
    {
        //旧状态离开回调
        if (currentState != null)
        {
            currentState.OnExit();
        }

        currentState = states[typeof(T)]; //切换状态

        currentState.OnEnter();           //新状态进入回调

        //Debug.Log("进入" + CurrentState.PlayerState);
    }
Exemplo n.º 6
0
    public void SetState(PlayerStateBase newState)
    {
        // Set the last state to equal current state so that we have reference to it
        lastState = currentState;

        // Set the new state
        currentState = newState;

        // Call the exit method of the last state and the enter method of the current state
        lastState.ExitState(this);
        currentState.EnterState(this);

        // Fire the changed state event
        PlayerStateChanged();
    }
Exemplo n.º 7
0
    void OnGetGestureInfoCallback(int PlayerIndex, PlayerStateBase playerState)
    {
        PlayerState_SegTimeState SegTimeState = playerState as PlayerState_SegTimeState;

        if (SegTimeState == null)
        {
            return;
        }

        //bool HasRecognized = false;
        for (int i = 0; i < SegTimeState.GestureInfoData.ItemNum; ++i)
        {
            GestureInfo_Seg_Time_State state = SegTimeState.GestureInfoData[i];
            if (state.IsRecognized != 0)
            {
                //HasRecognized = true;
                if (GestureText != null)
                {
                    string info = string.Format("Gesture {0}, Index:{1} Recognized", GestureManager.Instance.GetGestureName(PlayerIndex, state.GestureIndex), state.GestureIndex);
                    GestureText.text = info;
                    Log.Print(Log.Level.Log, info);
                }
            }
            else if (state.IsSegmentSucceed != 0)
            {
                if (GestureText != null)
                {
                    string info = string.Format("Gesture {0}, Segment: {1} OK", GestureManager.Instance.GetGestureName(PlayerIndex, state.GestureIndex), state.SegmentIndex);
                    //GestureText.text = info;
                    Log.Print(Log.Level.Log, info);
                }
            }
            else
            {
                if (GestureText != null)
                {
                    //string info = string.Format("Gesture {0}, Index:{1} Segment: {2} Failed", GestureManager.Instance.GetGestureName(state.GestureIndex), state.GestureIndex, state.SegmentIndex);
                    //GestureText.text = info;
                    //Log.Print(Log.Level.Log, info);
                }
            }
        }

//      if (!HasRecognized)
//      {
//          GestureText.text = "No Gesture has been recognized.";
//      }
    }
Exemplo n.º 8
0
        public override void Start()
        {
            //Basics///////////////////////////////
            base.Start();
            Position           = CurrentNode.Position;
            _properHighlighter = GetComponent <ProperHighlighter>();
            _animator          = GetComponentInChildren <Animator>();

            //Setting up the Cache/////////////////
            _states = new Dictionary <Type, PlayerStateBase>();
            _states.Add(typeof(PlayerStateIdle), new PlayerStateIdle(this));
            _states.Add(typeof(PlayerStateWalking), new PlayerStateWalking(this));
            _states.Add(typeof(PlayerStateInteractionEnemy), new PlayerStateInteractionEnemy(this));
            _states.Add(typeof(PlayerStateInteractionBuilding), new PlayerStateInteractionBuilding(this));
            _states.Add(typeof(PlayerStateInteractionNPC), new PlayerStateInteractionNPC(this));
            _states.Add(typeof(PlayerStateInteractionProp), new PlayerStateInteractionProp(this));

            //Starting First State Manually////////
            _currentState = _states[typeof(PlayerStateIdle)];
            _currentState.BeginState();
        }
Exemplo n.º 9
0
 /// <summary>
 /// ステートを開始した時に呼ばれる
 /// </summary>
 public virtual void OnEnter(Player owner, PlayerStateBase prevState)
 {
 }
Exemplo n.º 10
0
 /// <summary>
 /// ステートを終了した時に呼ばれる
 /// </summary>
 public virtual void OnExit(Player owner, PlayerStateBase nextState)
 {
 }
Exemplo n.º 11
0
 // ステート変更
 private void ChangeState(PlayerStateBase nextState)
 {
     currentState.OnExit(this, nextState);
     nextState.OnEnter(this, currentState);
     currentState = nextState;
 }
Exemplo n.º 12
0
 public void ChangeStates(PlayerStateBase stateBase)
 {
     stateManager.ChangeStates(stateBase);
 }
Exemplo n.º 13
0
 public override void OnEnter(Player owner, PlayerStateBase prevState)
 {
     owner.transform.localScale = Vector3.one;
     owner.AdjustGround();
 }
Exemplo n.º 14
0
 public override void OnExit(Player owner, PlayerStateBase nextState)
 {
     owner.transform.localScale = owner.defaultScale;
     owner.AdjustGround();
 }
Exemplo n.º 15
0
 public void Awake()
 {
     player    = FindObjectOfType <PlayerStats>();
     stateBase = GetComponent <PlayerStateBase>();
 }
Exemplo n.º 16
0
 public override void OnEnter(Player owner, PlayerStateBase prevState)
 {
     owner.rigidBody.AddForce(Vector3.up * 7f, ForceMode.Impulse);
 }