void ManageGamePadConnection(GamePadData gamePad) { if (!gamePad.playerIndexSet || !gamePad.prevState.IsConnected) { PlayerIndex testPlayerIndex = (PlayerIndex)gamePad.ID; GamePadState testState = GamePad.GetState(testPlayerIndex); if (testState.IsConnected) { gamePad.state = testState; gamePad.playerIndex = testPlayerIndex; gamePad.playerIndexSet = true; //GamePadConnection(gamePad); return; } } }
// Use this for initialization void Start() { m_gameMgr = GameManager.Instance; //init all GamePads int gamePadNb = m_gamePads.Length; for (int i = 0; i < gamePadNb; i++) { m_gamePads[i] = new GamePadData(); m_gamePads[i].padEvent = new GamePadEvent(); m_gamePads[i].ID = i; } Debug.Log("InputMgr Init Done"); init = true; OnInitComplete.Invoke(); }
void EventCall(GamePadData gamePad) { if (gamePad.prevState.Buttons.A == ButtonState.Released && gamePad.state.Buttons.A == ButtonState.Pressed) { gamePad.padEvent.OnButtonA.Invoke(); } if (gamePad.prevState.Buttons.B == ButtonState.Released && gamePad.state.Buttons.B == ButtonState.Pressed) { gamePad.padEvent.OnButtonB.Invoke(); } if (gamePad.prevState.Buttons.X == ButtonState.Released && gamePad.state.Buttons.X == ButtonState.Pressed) { gamePad.padEvent.OnButtonX.Invoke(); } if (gamePad.prevState.Buttons.Y == ButtonState.Released && gamePad.state.Buttons.Y == ButtonState.Pressed) { gamePad.padEvent.OnButtonY.Invoke(); } if (gamePad.prevState.Buttons.A == ButtonState.Pressed && gamePad.state.Buttons.A == ButtonState.Released) { gamePad.padEvent.OnButtonARelease.Invoke(); } if (gamePad.prevState.Buttons.Start == ButtonState.Released && gamePad.state.Buttons.Start == ButtonState.Pressed) { gamePad.padEvent.OnButtonStart.Invoke(); } if (gamePad.prevState.Buttons.RightShoulder == ButtonState.Released && gamePad.state.Buttons.RightShoulder == ButtonState.Pressed) { gamePad.padEvent.OnButtonRightBumper.Invoke(); } if (gamePad.prevState.Buttons.LeftShoulder == ButtonState.Released && gamePad.state.Buttons.LeftShoulder == ButtonState.Pressed) { gamePad.padEvent.OnButtonLeftBumper.Invoke(); } if (gamePad.prevState.DPad.Down == ButtonState.Released && gamePad.state.DPad.Down == ButtonState.Pressed) { gamePad.padEvent.OnDPadDown.Invoke(); } if (gamePad.prevState.DPad.Left == ButtonState.Released && gamePad.state.DPad.Left == ButtonState.Pressed) { gamePad.padEvent.OnDPadLeft.Invoke(); } if (gamePad.prevState.DPad.Up == ButtonState.Released && gamePad.state.DPad.Up == ButtonState.Pressed) { gamePad.padEvent.OnDPadUp.Invoke(); } if (gamePad.prevState.DPad.Right == ButtonState.Released && gamePad.state.DPad.Right == ButtonState.Pressed) { gamePad.padEvent.OnDPadRight.Invoke(); } }