public static bool IsJustStickDown(StickDirection direction, GamePad.Index index = GamePad.Index.One)
    {
        Vector2 stick, oldStick;

        if (direction >= (StickDirection)4)
        {
            stick    = currentState[(int)index].rightStickAxis;
            oldStick = oldState[(int)index].rightStickAxis;
        }
        else
        {
            stick    = currentState[(int)index].LeftStickAxis;
            oldStick = oldState[(int)index].LeftStickAxis;
        }

        switch (direction)
        {
        case StickDirection.LeftStickRight:
        case StickDirection.RightStickRight:
            return(stick.x > stickDead && oldStick.x <= stickDead);

        case StickDirection.LeftStickLeft:
        case StickDirection.RightStickLeft:
            return(stick.x < -stickDead && oldStick.x >= -stickDead);

        case StickDirection.LeftStickUp:
        case StickDirection.RightStickUp:
            return(stick.y > stickDead && oldStick.y <= stickDead);

        case StickDirection.LeftStickDown:
        case StickDirection.RightStickDown:
            return(stick.y < -stickDead && oldStick.y >= -stickDead);
        }
        return(false);
    }
    public static bool IsStickDown(StickDirection direction, GamePad.Index index = GamePad.Index.One)
    {
        Vector2 stick;

        if (direction >= (StickDirection)4)
        {
            stick = GetAxis(Axis.RightStick, index);
        }
        else
        {
            stick = GetAxis(Axis.LeftStick, index);
        }
        float dead = 0.3f;

        switch (direction)
        {
        case StickDirection.LeftStickRight:
        case StickDirection.RightStickRight:
            return(stick.x > dead);

        case StickDirection.LeftStickLeft:
        case StickDirection.RightStickLeft:
            return(stick.x < -dead);

        case StickDirection.LeftStickUp:
        case StickDirection.RightStickUp:
            return(stick.y > dead);

        case StickDirection.LeftStickDown:
        case StickDirection.RightStickDown:
            return(stick.y < -dead);
        }
        return(false);
    }
    public static Vector2 GetAxis(Axis axis, GamePad.Index index = GamePad.Index.One)
    {
        if (IsConnectJoyPad)
        {
            return(GamePad.GetAxis((GamePad.Axis)axis, index));
        }

        Vector2 axisXY = Vector2.zero;

        KeyConfigData.AxisKeyConfig axisKeyConfig = null;
        foreach (KeyConfigData.AxisKeyConfig config in keyConfig.axisConfigList)
        {
            if (config.axisName == axis)
            {
                axisKeyConfig = config;
            }
        }

        if (axisKeyConfig == null)
        {
            return(Vector2.zero);
        }

        if (axisKeyConfig.xAxisName != "null")
        {
            axisXY.x = Input.GetAxis(axisKeyConfig.xAxisName);
        }
        if (axisKeyConfig.yAxisName != "null")
        {
            axisXY.y = Input.GetAxis(axisKeyConfig.yAxisName);
        }

        return(axisXY);
    }
    public void SetUpCameraSize(GamePad.Index pNumber, bool fullScreen)
    {
        if (!fullScreen)
        {
            switch (pNumber)
            {
            case GamePad.Index.One:
                cam.rect = new Rect(_player1.x, _player1.y, _player1.h, _player1.w);
                break;

            case GamePad.Index.Two:
                cam.rect = new Rect(_player2.x, _player2.y, _player2.h, _player2.w);
                break;

            case GamePad.Index.Three:
                cam.rect = new Rect(_player3.x, _player3.y, _player3.h, _player3.w);
                break;

            case GamePad.Index.Four:
                cam.rect = new Rect(_player4.x, _player4.y, _player4.h, _player4.w);
                break;
            }
        }
        else
        {
            cam.rect = new Rect(_onePlayer.x, _onePlayer.y, _onePlayer.h, _onePlayer.w);
        }
    }
Exemple #5
0
 private void Start()
 {
     _index          = isLeft ? GamePad.Index.One : GamePad.Index.Two;
     _arm            = isLeft ? GamePad.Axis.LeftStick : GamePad.Axis.RightStick;
     _leg            = isLeft ? GamePad.Axis.RightStick : GamePad.Axis.LeftStick;
     _limbController = FindObjectOfType <LimbController>();
 }
Exemple #6
0
 void spawnOnGamepadInput(GamePad.Index index)
 {
     if (leftStickFirstMoved(index))
     {
         spawnPlayer(index);
     }
 }
Exemple #7
0
    void DrawState(GamePad.Index controller)
    {
        GUILayout.Space(45);

        GUILayout.BeginVertical();


        GamepadState state = GamePad.GetState(controller);

        // buttons
        GUILayout.Label("Gamepad " + controller);

        GUILayout.Label("");

        // triggers
        GUILayout.Label("" + System.Math.Round(state.LeftTrigger, 2));
        GUILayout.Label("" + System.Math.Round(state.RightTrigger, 2));

        GUILayout.Label("");

        // Axes
        GUILayout.Label("" + state.LeftStickAxis);
        GUILayout.Label("" + state.rightStickAxis);
        GUILayout.Label("" + state.dPadAxis);


        //GUILayout.EndArea();
        GUILayout.EndVertical();
    }
Exemple #8
0
    public override void check()
    {
        switch (indx)
        {
        case 1:
            ind = GamePad.Index.One;
            break;

        case 2:
            ind = GamePad.Index.Two;
            break;

        case 3:
            ind = GamePad.Index.Three;
            break;

        case 4:
            ind = GamePad.Index.Four;
            break;

        default:
            ind = GamePad.Index.Any;
            break;
        }

        Vector2 dir = GamePad.GetAxis(GamePad.Axis.Dpad, ind) + GamePad.GetAxis(GamePad.Axis.LeftStick, ind) + GamePad.GetAxis(GamePad.Axis.RightStick, ind);

        if (dir.y > 0)
        {
            up();
        }
        if (dir.y < 0)
        {
            down();
        }
        if (dir.x < 0)
        {
            left();
        }
        if (dir.x > 0)
        {
            right();
        }
        if (GamePad.GetButtonDown(GamePad.Button.A, ind))
        {
            b1();
        }
        if (GamePad.GetButtonDown(GamePad.Button.Y, ind))
        {
            b2();
        }
        if (GamePad.GetButtonDown(GamePad.Button.B, ind))
        {
            b3();
        }
        if (GamePad.GetButtonDown(GamePad.Button.X, ind))
        {
            b4();
        }
    }
 // Use this for initialization
 void Start()
 {
     charaTransform = character2P.transform.position;
     blin           = GetComponent <Blinker>();
     player         = GamePad.Index.Two;
     bulletHold2P   = bullet;
 }
Exemple #10
0
    // Update is called once per frame
    //just looks for the player inputs and handles them accordingly
    void Update()
    {
        for (int i = 0; i < agPlayer.Length; i++)
        {
            GamePad.Index index = ReturnWhichIndex(i);
            //print ( "i = " + i + "   index = " + index.ToString() );
            if (GamePad.GetAxis(GamePad.Axis.LeftStick, index).x < 0)
            {
                agPlayer[i].SendMessage("MoveRight", SendMessageOptions.DontRequireReceiver);
            }

            if (GamePad.GetAxis(GamePad.Axis.LeftStick, index).x > 0)
            {
                agPlayer[i].SendMessage("MoveLeft", SendMessageOptions.DontRequireReceiver);
            }
            if (GamePad.GetAxis(GamePad.Axis.LeftStick, index).y > 0)
            {
                agPlayer[i].SendMessage("LookUp", SendMessageOptions.DontRequireReceiver);
            }
            if (GamePad.GetAxis(GamePad.Axis.LeftStick, index).y < -.5f)
            {
                agPlayer[i].SendMessage("Crouch", SendMessageOptions.DontRequireReceiver);
            }

            if (GamePad.GetButtonDown(strctPlayerInputs[i].bAttack, index))
            {
                agPlayer[i].SendMessage("Attack", SendMessageOptions.DontRequireReceiver);
            }

            //print ( strctPlayerInputs[0].bAttack.ToString() + "  " + strctPlayerInputs[0].bJump.ToString() + "  " + strctPlayerInputs[0].bSwap2.ToString() );
            if (GamePad.GetButton(strctPlayerInputs[i].bJump, index))
            {
                agPlayer[i].SendMessage("Jump", SendMessageOptions.DontRequireReceiver);
            }

            if (GamePad.GetButtonUp(strctPlayerInputs[i].bJump, index))
            {
                agPlayer[i].SendMessage("StoppedJumping", SendMessageOptions.DontRequireReceiver);
            }
            if (GamePad.GetButtonDown(strctPlayerInputs[i].bSwap1, index))
            {
                agPlayer[i].SendMessage("Swap", 1, SendMessageOptions.DontRequireReceiver);
            }
            if (GamePad.GetButtonDown(strctPlayerInputs[i].bSwap2, index))
            {
                agPlayer[i].SendMessage("Swap", 2, SendMessageOptions.DontRequireReceiver);
            }
            if (GamePad.GetButtonDown(strctPlayerInputs[i].bSwap3, index))
            {
                agPlayer[i].SendMessage("Swap", 3, SendMessageOptions.DontRequireReceiver);
            }
            if (GamePad.GetButtonDown(strctPlayerInputs[i].bSwap4, index))
            {
                agPlayer[i].SendMessage("Swap", 4, SendMessageOptions.DontRequireReceiver);
            }

            agPlayer[i].SendMessage("SetYAxis", GamePad.GetAxis(GamePad.Axis.LeftStick, index).y, SendMessageOptions.DontRequireReceiver);
            agPlayer[i].SendMessage("SetXAxis", GamePad.GetAxis(GamePad.Axis.LeftStick, index).x, SendMessageOptions.DontRequireReceiver);
        }
    }
Exemple #11
0
        } // HorizontalKeyIn

        /// <summary>
        /// 左右にスティックが倒されたかチェックするメソッド
        /// </summary>
        /// <param name="gamePadNo">ジョイスティックのNo</param>
        /// <param name="param">倒された方向に影響される整数</param>
        /// <returns></returns>
        public int HorizontalKeyInDpad(GamePad.Index gamePadNo, int param = 0)
        {
            var vec        = GamePad.GetAxis(GamePad.Axis.Dpad, gamePadNo);
            var horizontal = vec.x;

            if (Mathf.Abs(horizontal) > 0.7f)
            {
                if (keyFlagsHorizontal_dpad[gamePadNo] == false)
                {
                    // 右に倒されたなら
                    if (horizontal > 0.0f)
                    {
                        param++;
                    }
                    // 左に倒されたなら
                    else if (horizontal < 0.0f)
                    {
                        param--;
                    }
                } // if(keyFlag)
            }     // if(Mathf.Abs...)
            else
            {
                keyFlagsHorizontal_dpad[gamePadNo] = false;
            } // else
            // 値を返す
            return(param);
        } // HorizontalKeyIn
 // Use this for initialization
 void Start()
 {
     rectra1P = duel1P_Chara.GetComponent <RectTransform>();
     rectra2P = duel2P_Chara.GetComponent <RectTransform>();
     player1P = GamePad.Index.One;
     player2P = GamePad.Index.Two;
 }
Exemple #13
0
    private void SetUpGamepad(GamePad.Index pad)
    {
        CreateCharacter(currPlayer);
        XBoxInputHandler xbi = player.AddComponent <XBoxInputHandler>();

        xbi.CC = player.AddComponent <CharController>();
        xbi.CC.SetUp();
        xbi.padNum = pad;
        player.AddComponent <PlayerInfo>().PlayerNumber = (currPlayer);
        pa.AddTarget(player.GetComponent <Transform>());
        float r = Random.Range(0f, 1f);

        if (r < .33f)
        {
            xbi.CC.SetRace(new R_Meat());
        }
        else if (r < .67f)
        {
            xbi.CC.SetRace(new R_Metal());
        }
        else
        {
            xbi.CC.SetRace(new R_Electronic());
        }
        AssignUI(xbi.CC, currPlayer);
        NextPlayer();
    }
 public virtual void UseItem(GamePad.Index playerNo, KeyBoard.Index playerKeyNo)
 {
     if (GamePad.GetButton(GamePad.Button.B, playerNo) || KeyBoard.GetButton(KeyBoard.Button.B, playerKeyNo))
     {
         // アイテムを所持しているか
         if (m_sItemData != null)
         {
             // 置く場所が適切かどうか
             if (IsUseItem() == true)
             {
                 //  アクション時間が経過しているか
                 if (m_fActionTime <= 0f)
                 {
                     UseItem();
                     // アクション経過時間を再設定
                     m_fActionTime = m_fLimitActionTime;
                     ItemHolderManager.Instance.UsingFromHolder(0, playerNo, playerKeyNo);
                 }
                 else
                 {
                     // アクション時間を経過させる
                     m_fActionTime -= Time.deltaTime;
                     float TimeParLimitTime = (m_fLimitActionTime - m_fActionTime) / m_fLimitActionTime;
                     ItemHolderManager.Instance.UsingFromHolder(TimeParLimitTime, playerNo, playerKeyNo);
                 }
             }
         }
     }
     else
     {
         // アクション経過時間を再設定
         m_fActionTime = m_fLimitActionTime;
         ItemHolderManager.Instance.UsingFromHolder(0, playerNo, playerKeyNo);
     }
 }
Exemple #15
0
    /// <summary>
    /// ゲームパッド入力のデバッグ
    /// </summary>
    private void GamePadDebugWindow(GamePad.Index controller)
    {
        //ゲームパッド(プレイヤー)を取得
        GamepadState state = GamePad.GetState(controller);

        //Button
        Debug.Log("Gamepad " + controller);
        Debug.Log("[" + controller + ":P]" + "A:" + state.A);
        Debug.Log("[" + controller + ":P]" + "B:" + state.B);
        Debug.Log("[" + controller + ":P]" + "X:" + state.X);
        Debug.Log("[" + controller + ":P]" + "Y:" + state.Y);
        Debug.Log("[" + controller + ":P]" + "START:" + state.Start);
        Debug.Log("[" + controller + ":P]" + "Back:" + state.Back);
        Debug.Log("[" + controller + ":P]" + "L1:" + state.LeftShoulder);
        Debug.Log("[" + controller + ":P]" + "R1:" + state.RightShoulder);
        Debug.Log("[" + controller + ":P]" + "POV_Left:" + state.Left);
        Debug.Log("[" + controller + ":P]" + "POV_Rigt:" + state.Right);
        Debug.Log("[" + controller + ":P]" + "POV_Up:" + state.Up);
        Debug.Log("[" + controller + ":P]" + "POV_Down:" + state.Down);
        Debug.Log("[" + controller + ":P]" + "L3:" + state.LeftStick);
        Debug.Log("[" + controller + ":P]" + "R3:" + state.RightStick);

        Debug.Log("-----------------------------");

        //Trigger
        Debug.Log("[" + controller + ":P]" + "L2:" + System.Math.Round(state.LeftTrigger, 2));
        Debug.Log("[" + controller + ":P]" + "R2:" + System.Math.Round(state.RightTrigger, 2));

        Debug.Log("-----------------------------");

        //Axis
        Debug.Log("[" + controller + ":P]" + "LStick:" + state.LeftStickAxis);
        Debug.Log("[" + controller + ":P]" + "RStick:" + state.rightStickAxis);
        Debug.Log("[" + controller + ":P]" + "DPad:" + state.dPadAxis);
    }
Exemple #16
0
    // Use this for initialization

    public void Start()
    {
        transform.GetComponent <Rigidbody>().centerOfMass = Vector3.zero;
        SetSpecialImage();
        idx  = (GamePad.Index)PlayerIndex;
        xIdx = (XInputDotNetPure.PlayerIndex)PlayerIndex;
    }
Exemple #17
0
    void Start()
    {
        player_controller = GetComponent <PlayerController>();
        player_num        = player_controller.player_num;
        horizontal        = player_controller.GetHorizontal();
        vertical          = player_controller.GetVertical();
        shoot_bullet      = player_controller.GetShootButton();

        foreach (Transform tr in transform)
        {
            if (tr.gameObject.CompareTag("FuriHability"))
            {
                furi_object = tr.gameObject;
            }
        }

        if (furi_object == null)
        {
            Destroy(this);
        }
        else
        {
            furi_object.SetActive(false);
        }
    }
 public void IconMove(string conName, GamePad.Index num, GameObject player, string name)
 {
     if (name == "Arcade")
     {
         // 移動キーを押していなければ何もしない
         if (GamePad.GetAxis(GamePad.Axis.LeftStick, num).x == 0.0f && GamePad.GetAxis(GamePad.Axis.LeftStick, num).y == 0.0f)
         {
             return;
         }
         // 移動先を計算
         pos += new Vector2(GamePad.GetAxis(GamePad.Axis.LeftStick, num).x *iconSpeed, GamePad.GetAxis(GamePad.Axis.LeftStick, num).y *iconSpeed * -1) * Time.deltaTime;
         // アイコン位置を設定
         player.transform.localPosition = pos;
     }
     else if (name == "Xbox")
     {
         // 移動キーを押していなければ何もしない
         if (GamePad.GetAxis(GamePad.Axis.LeftStick, num).x == 0.0f && GamePad.GetAxis(GamePad.Axis.LeftStick, num).y == 0.0f)
         {
             return;
         }
         // 移動先を計算
         pos += new Vector2(GamePad.GetAxis(GamePad.Axis.LeftStick, num).x *iconSpeed, GamePad.GetAxis(GamePad.Axis.LeftStick, num).y *iconSpeed) * Time.deltaTime;
         // アイコン位置を設定
         player.transform.localPosition = pos;
     }
 }
Exemple #19
0
 void Awake()
 {
     if (debug)
     {
         Debug.Log(this.ToString() + " awake.");
     }
     this.padIndex = GamePad.Index.Any;
     if (Network.isClient || Network.isServer)
     {
         if (this.GetComponent <NetworkView>().isMine)
         {
             this.isThisMachinesPlayer = true;
         }
     }
     else
     {
         this.isThisMachinesPlayer = true;
     }
     if (this.isThisMachinesPlayer)
     {
         if (debug)
         {
             Debug.Log("This machine owns player " + this.ToString());
         }
         GrabCamera(Camera.main);
     }
 }
        static void GrabCorrectStruct(GamePad.Index index)
        {
            //Debug.Log (index.ToString ());
            switch (index)
            {
            case Index.One:
                iActiveIndexListCB = 3;
                break;

            case Index.Two:
                iActiveIndexListCB = 2;
                break;

            case Index.Three:
                iActiveIndexListCB = 1;
                break;

            case Index.Four:
                iActiveIndexListCB = 0;
                break;

            default:
                Debug.Log("default called - GamePad.cs - GrabCorrectStruct");
                iActiveIndexListCB = 0;
                break;
            }
        }
Exemple #21
0
    /// <summary>
    /// 入力待ち処理
    /// </summary>
    void WaitForInput()
    {
        //入力待ちプレイヤーを取得
        var players = data.Where(it => it.state == State.Wait).ToArray();

        foreach (var it in players)
        {
            if (it.id == PlayerManager.NOT_ENTRY)
            {
                continue;
            }

            int           index        = DataBase.GetControllerID(it.id) - 1;
            GamePad.Index gamePadIndex = (GamePad.Index)(index + 1);
            var           input        = MyInputManager.GetController(gamePadIndex);

            //入力終了の瞬間
            if (input.START)
            {
                data[index].state = State.End;
                ResultTextManager.Instance.StartCloseAndOpenVertical(index);
                ResultTextManager.Instance.SetFinishedText(index);

                //効果音
                SoundManager.Instance.PlayOnSE("Inputed");
            }
        }
    }
Exemple #22
0
        /// <summary>
        /// 上下にキーが倒されたかチェック
        /// </summary>
        /// <param name="gamePadNo"></param>
        /// <param name="param"></param>
        /// <returns></returns>
        public int VerticalKeyInLeftStick(GamePad.Index gamePadNo, int param = 0)
        {
            var vec      = GamePad.GetAxis(GamePad.Axis.LeftStick, gamePadNo);
            var vertical = vec.y;

            if (Mathf.Abs(vertical) > 0.7f)
            {
                if (keyFlagsVertical_leftStick[gamePadNo] == false)
                {
                    // 右に倒されたなら
                    if (vertical < 0.0f)
                    {
                        param++;
                    }
                    // 左に倒されたなら
                    else if (vertical > 0.0f)
                    {
                        param--;
                    }
                } // if(keyFlag)
            }     // if(Mathf.Abs...)
            else
            {
                keyFlagsVertical_leftStick[gamePadNo] = false;
            } // else
            // 値を返す
            return(param);
        }
Exemple #23
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (!canInput)
        {
            return;
        }


        // 入力受付
        for (int i = 0; i < GameDataManager.Instance.PlayerIDList.Count; i++)
        {
            GamePad.Index index = (GamePad.Index)(i + 1);

            // IDから情報取得
            GamepadState state   = GamePad.GetState(index);
            Vector2      moveVec = state.LeftStickAxis;
            playerMoveMap [i + 1].Move(moveVec);
            if (moveVec.sqrMagnitude > 0)
            {
                playerViewMap [i + 1].StartRun();
            }
            else
            {
                playerViewMap [i + 1].StopRun();
            }
        }
    }
        public static ControllerIndex ToControllerIndex(this GamePad.Index index)
        {
            if (index == GamePad.Index.Any)
            {
                throw new ArgumentException(nameof(index));
            }

            return((ControllerIndex)index);
        }
        public void OnButton(GamePad.Button button, GamePad.Index index, Action handler)
        {
            if (!_handlers.ContainsKey(button))
            {
                _handlers.Add(button, new List <Action>());
            }

            _handlers[button].Add(handler);
        }
Exemple #26
0
 bool leftStickFirstMoved(GamePad.Index index)
 {
     if ((GamePad.GetAxis(GamePad.Axis.LeftStick, index) != Vector2.zero || Input.GetAxisRaw("Vertical_" + (int)index) != 0) && !GamepadIndexesActive.Contains(index))
     {
         GamepadIndexesActive.Add(index);
         return(true);
     }
     return(false);
 }
 void Start()
 {
     player_controller = GetComponent <PlayerController>();
     shoot_point       = player_controller.horizontal_shoot_point.transform.localPosition;
     horizontal        = player_controller.GetHorizontal();
     vertical          = player_controller.GetVertical();
     shoot_bullet      = player_controller.GetShootButton();
     player_num        = player_controller.player_num;
 }
 void Start()
 {
     player_controller          = GetComponent <PlayerController>();
     shoot_point                = player_controller.horizontal_shoot_point.transform.localPosition;
     horizontal                 = player_controller.GetHorizontal();
     vertical                   = player_controller.GetVertical();
     shoot_bullet               = player_controller.GetShootButton();
     real_timer_between_bullets = Random.Range(0, time_between_bullets);
     player_num                 = player_controller.player_num;
 }
 void Start()
 {
     playerNo = (GamePad.Index)EntrySystem.playerNumber[characterNum - 1];
     if ((int)playerNo == -1)
     {
         gameObject.SetActive(false);
     }
     SpawnPos   = transform.position;
     player_Pos = transform.position;// 座標の更新
 }
 public void SetDictionary()
 {
     controllerIndex = new Dictionary <int, GamePad.Index>();
     controllerIndex.Add(0, GamePad.Index.Any);
     controllerIndex.Add(1, GamePad.Index.One);
     controllerIndex.Add(2, GamePad.Index.Two);
     controllerIndex.Add(3, GamePad.Index.Three);
     controllerIndex.Add(4, GamePad.Index.Four);
     gamePadIndex = controllerIndex[controllerNumber];
 }
Exemple #31
0
    public GamepadMapping(int player)
    {
        GamePadIndex = (GamePad.Index)Enum.Parse(typeof(GamePad.Index), PlayerPrefs.GetString("p" + player + "GamePadIndex"));

        GamePadHorizontalAxis = (GamePad.Axis)Enum.Parse(typeof(GamePad.Axis), PlayerPrefs.GetString("p" + player + "GamePadHorizontalAxis"));
        GamePadHorizontalAxisDirection = (InputConfigurator.AxisDirection)Enum.Parse(typeof(InputConfigurator.AxisDirection), PlayerPrefs.GetString("p" + player + "GamePadHorizontalAxisDirection"));

        GamePadVerticalAxis = (GamePad.Axis)Enum.Parse(typeof(GamePad.Axis), PlayerPrefs.GetString("p" + player + "GamePadVerticalAxis"));
        GamePadVerticalAxisDirection = (InputConfigurator.AxisDirection)Enum.Parse(typeof(InputConfigurator.AxisDirection), PlayerPrefs.GetString("p" + player + "GamePadVerticalAxisDirection"));

        GamePadRocketUp = (GamePad.Button)Enum.Parse(typeof(GamePad.Button), PlayerPrefs.GetString("p" + player + "GamePadRocketUp"));
        GamePadRocketDown = (GamePad.Button)Enum.Parse(typeof(GamePad.Button), PlayerPrefs.GetString("p" + player + "GamePadRocketDown"));
        GamePadRocketLeft = (GamePad.Button)Enum.Parse(typeof(GamePad.Button), PlayerPrefs.GetString("p" + player + "GamePadRocketLeft"));
        GamePadRocketRight = (GamePad.Button)Enum.Parse(typeof(GamePad.Button), PlayerPrefs.GetString("p" + player + "GamePadRocketRight"));
    }
    public void Init( Texture aTexture , int aiMaxIndex, int iDotSize, float afTimeBetweenMoves, GamePad.Index aGamepadIndex)
    {
        texture = aTexture;
        iMaxIndex = aiMaxIndex;

        dotLeft = new Dot();
        dotLeft.vSize = new Vector2(iDotSize,iDotSize);
        dotLeft.vPosition = Vector2.zero;

        dotRight = new Dot();
        dotRight.vSize = new Vector2(iDotSize,iDotSize);
        dotRight.vPosition = Vector2.zero;

        fTimeBetweenMoves = afTimeBetweenMoves;

        controllerIndex = aGamepadIndex;
    }
    private void SetVibration(float leftSide, float rightSide)
    {
        _gamepadIndex = _inputManager.m_PlayerData.GamepadIndex;
        var gamepad = _gamepadIndex.ToPlayerIndex();
        if (gamepad == null) return;

        XInputDotNetPure.GamePad.SetVibration((XInputDotNetPure.PlayerIndex)gamepad, leftSide, rightSide);
    }
        public GamePad.Index whichController; // = GamePad.Index.One;

        #endregion Fields

        #region Constructors

        public PlayerBrain(GamePad.Index controllerIdx)
        {
            whichController = controllerIdx;
        }
Exemple #35
0
    void Update()
    {
        AnimatorStateInfo state = Animator.GetCurrentAnimatorStateInfo(0);

        if (!state.IsName("P1Config") &&
            !state.IsName("P2Config") &&
            !state.IsName("P3Config") &&
            !state.IsName("P4Config"))
        {
            return;
        }

        if (Input.GetKeyDown(KeyCode.F12) && Input.GetKey(KeyCode.LeftShift))
        {
            Debug.Log("flusing save data");
            PlayerPrefs.DeleteAll();
            return;
        }

        if (Input.GetKeyDown(KeyCode.Escape))
        {
            if (CurrentPhase == ConfigurationPhase.SlideUp)
            {
                if (CurrentPlayer == 1)
                {
                    QuitWithoutSaving();
                }
                else
                {
                    CurrentPlayer--;
                    PlayerConfigurators[CurrentPlayer - 1].Unready();
                    GetComponent<GameJoinControl>().PlayersReady[CurrentPlayer - 1] = false;
                }
            }
            else
            {
                CurrentPhase = ConfigurationPhase.SlideUp;
            }

            PlaySound(CancelClip, Players[CurrentPlayer-1]);

            return;
        }

        if (WaitingForAxisReset)
        {
            if (GamePad.GetAxis(GamePad.Axis.Dpad, GamePadIndex).magnitude > 0.1f ||
                GamePad.GetAxis(GamePad.Axis.LeftStick, GamePadIndex).magnitude > 0.1f ||
                GamePad.GetAxis(GamePad.Axis.RightStick, GamePadIndex).magnitude > 0.1f)
            {
                return;
            }

            WaitingForAxisReset = false;
        }

        if (CurrentPhase == ConfigurationPhase.WaitingToReadInput)
        {
            if (CurrentControllerType != ControllerType.Gamepad ||
                AnyPad() == GamePad.Index.Any)
            {
                CurrentPhase++;
            }
        }
        else if (CurrentPhase == ConfigurationPhase.SlideUp)
        {
            if (PressedKeyOrButton() != KeyCode.None)
            {
                CurrentControllerType = ControllerType.Keyboard;
                FetchAxisMapping(ref KeyboardSlideUp, ref GamePadVerticalAxis, ref GamePadVerticalAxisDirection);
            }
            else
            {
                GamePad.Index index = AnyPad();
                if (index != GamePad.Index.Any)
                {
                    CurrentControllerType = ControllerType.Gamepad;
                    GamePadIndex = index;
                    FetchAxisMapping(ref KeyboardSlideUp, ref GamePadVerticalAxis, ref GamePadVerticalAxisDirection);
                }
            }
        }
        else if (CurrentPhase == ConfigurationPhase.SlideDown)
        {
            FetchAxisMapping(ref KeyboardSlideDown, ref GamePadHorizontalAxis, ref GamePadHorizontalAxisDirection, true);
        }
        else if (CurrentPhase == ConfigurationPhase.SlideLeft)
        {
            FetchAxisMapping(ref KeyboardSlideLeft, ref GamePadHorizontalAxis, ref GamePadHorizontalAxisDirection);
        }
        else if (CurrentPhase == ConfigurationPhase.SlideRight)
        {
            FetchAxisMapping(ref KeyboardSlideRight, ref GamePadHorizontalAxis, ref GamePadHorizontalAxisDirection, true);
        }
        else if (CurrentPhase == ConfigurationPhase.RocketUp)
        {
            FetchButtonMapping(ref KeyboardRocketUp, ref GamePadRocketUp);
        }
        else if (CurrentPhase == ConfigurationPhase.RocketDown)
        {
            FetchButtonMapping(ref KeyboardRocketDown, ref GamePadRocketDown);
        }
        else if (CurrentPhase == ConfigurationPhase.RocketLeft)
        {
            FetchButtonMapping(ref KeyboardRocketLeft, ref GamePadRocketLeft);
        }
        else if (CurrentPhase == ConfigurationPhase.RocketRight)
        {
            FetchButtonMapping(ref KeyboardRocketRight, ref GamePadRocketRight);
        }
        else if (CurrentPhase == ConfigurationPhase.Finished)
        {
            StoreForSaving();
            PlayerConfigurators[CurrentPlayer - 1].Ready();
            GetComponent<GameJoinControl>().PlayersReady[CurrentPlayer - 1] = true;

            if (CurrentPlayer < PlayersToConfigure)
            {
                CurrentPlayer++;
                CurrentPhase = ConfigurationPhase.WaitingToReadInput;
            }
            else
            {
                SaveAndQuit();
            }
        }

        UpdateGUI();
    }
 public void SetDictionary()
 {
     controllerIndex = new Dictionary<int, GamePad.Index>();
     controllerIndex.Add(0, GamePad.Index.Any);
     controllerIndex.Add(1, GamePad.Index.One);
     controllerIndex.Add(2, GamePad.Index.Two);
     controllerIndex.Add(3, GamePad.Index.Three);
     controllerIndex.Add(4, GamePad.Index.Four);
     gamePadIndex = controllerIndex[controllerNumber];
 }