Player CreatePlayer(InputDevice inputDevice) { if (players.Count < maxPlayers) { // Pop a position off the list. We'll add it back if the player is removed. var playerPosition = playerPositions[0]; playerPositions.RemoveAt(0); var gameObject = (GameObject)Instantiate(playerPrefab, playerPosition, Quaternion.identity); var player = gameObject.GetComponent <Player>(); if (inputDevice == null) { // We could create a new instance, but might as well reuse the one we have // and it lets us easily find the keyboard player. player.Actions = keyboardListener; } else { // Create a new instance and specifically set it to listen to the // given input device (joystick). var actions = IncontrolPlayerActions.CreateWithJoystickBindings(); actions.Device = inputDevice; player.Actions = actions; } players.Add(player); return(player); } return(null); }
public static IncontrolPlayerActions CreateWithKeyboardBindings() { var actions = new IncontrolPlayerActions(); actions.Green.AddDefaultBinding(Key.A); actions.Red.AddDefaultBinding(Key.S); actions.Blue.AddDefaultBinding(Key.D); actions.Yellow.AddDefaultBinding(Key.F); actions.Up.AddDefaultBinding(Key.UpArrow); actions.Down.AddDefaultBinding(Key.DownArrow); actions.Left.AddDefaultBinding(Key.LeftArrow); actions.Right.AddDefaultBinding(Key.RightArrow); return(actions); }
public static IncontrolPlayerActions CreateWithJoystickBindings() { var actions = new IncontrolPlayerActions(); actions.Green.AddDefaultBinding(InputControlType.Action1); actions.Red.AddDefaultBinding(InputControlType.Action2); actions.Blue.AddDefaultBinding(InputControlType.Action3); actions.Yellow.AddDefaultBinding(InputControlType.Action4); actions.Up.AddDefaultBinding(InputControlType.LeftStickUp); actions.Down.AddDefaultBinding(InputControlType.LeftStickDown); actions.Left.AddDefaultBinding(InputControlType.LeftStickLeft); actions.Right.AddDefaultBinding(InputControlType.LeftStickRight); actions.Up.AddDefaultBinding(InputControlType.DPadUp); actions.Down.AddDefaultBinding(InputControlType.DPadDown); actions.Left.AddDefaultBinding(InputControlType.DPadLeft); actions.Right.AddDefaultBinding(InputControlType.DPadRight); return(actions); }
bool JoinButtonWasPressedOnListener(IncontrolPlayerActions actions) { return(actions.Green.WasPressed || actions.Red.WasPressed || actions.Blue.WasPressed || actions.Yellow.WasPressed); }
void OnEnable() { InputManager.OnDeviceDetached += OnDeviceDetached; keyboardListener = IncontrolPlayerActions.CreateWithKeyboardBindings(); joystickListener = IncontrolPlayerActions.CreateWithJoystickBindings(); }