private void ActivateDevice() { InputUser.PerformPairingWithDevice(this.device, user); //gameplayInput.Enable(); user.AssociateActionsWithUser(gameplayInput); user.AssociateActionsWithUser(uiInput); user.ActivateControlScheme(this.schemeName); }
////TODO: this is also where we should look for whether we have custom bindings for the user that we should activate public bool OnJoin(InputUser user) { Debug.Assert(user.valid); Debug.Assert(user.pairedDevices.Count == 1, "Players should join on exactly one input device"); // Associate our InputUser with the actions we're using. user.AssociateActionsWithUser(controls); // Find out what control scheme to use and whether we have all the devices needed for it. var controlScheme = SelectControlSchemeBasedOnDevice(user.pairedDevices[0]); Debug.Assert(controlScheme.HasValue, "Must not join player on devices that we have no control scheme for"); // Try to activate control scheme. The scheme may require additional devices which we // also need to pair to the user. This process may fail and we may end up a player missing // devices to start playing. user.ActivateControlScheme(controlScheme.Value).AndPairRemainingDevices(); if (user.hasMissingRequiredDevices) { return(false); } // Put the player in joined state. m_User = user; ChangeState(State.Joined); return(true); }
#pragma warning restore CS0649 /***************************** * Init * *****************************/ public User(InputDevice device) { Controls = new MainControls(); Devices = new List <InputDevice>(); _user = InputUser.PerformPairingWithDevice(device: device); _user.AssociateActionsWithUser(Controls); Devices.Add(device); }
public void Init(InputUser user, int id) { this.id = id; this.user = user; user.AssociateActionsWithUser(controls); GetComponentInChildren <RandomColor>().SetColor(PlayerSkinManager.Instance.Colors[id]); m_RandomSkin.ToggleSkin(PlayerSkinManager.Instance.GetSelection(id)); }
private void Awake() { //Default player to player 1 (which is 0 in the gamepad order) if (playerNumber == -1) { playerNumber = 0; } playerScript = GetComponent <PlayerScript>(); playerRB = GetComponent <Rigidbody>(); inputAction = new PlayerInputActions(); spellInputTable = new float[4]; //Here we handle multiple users _user = new InputUser(); if (playerNumber >= Gamepad.all.Count) { //This means that somehow, there are more players in the game then gamepads //Remember to throw an exception playerNumber = 0; } _user = InputUser.PerformPairingWithDevice(Gamepad.all[playerNumber]); _user.AssociateActionsWithUser(inputAction); currentState = new PlayerStateIdle(this); //Setup input for horizontal movement value press inputAction.PlayerControls.Walk.performed += ctx => movementInput = ctx.ReadValue <Vector2>(); //Setup input for horizontal movement release inputAction.PlayerControls.Walk.canceled += ctx => movementInput = ctx.ReadValue <Vector2>(); //Setup input for run value press inputAction.PlayerControls.Run.performed += ctx => runInput = ctx.ReadValue <Vector2>(); //Setup input for run value release inputAction.PlayerControls.Run.canceled += ctx => runInput = ctx.ReadValue <Vector2>(); //Setup input for jump values press inputAction.PlayerControls.Jump.performed += ctx => jumpInput = ctx.ReadValue <float>(); //Setup input for jump value release inputAction.PlayerControls.Jump.canceled += ctx => jumpInput = ctx.ReadValue <float>(); //Setup input for jump values press inputAction.PlayerControls.Cancel.performed += ctx => cancelSpell = ctx.ReadValue <float>(); //Setup input for jump value release inputAction.PlayerControls.Cancel.canceled += ctx => cancelSpell = ctx.ReadValue <float>(); //Setup input for jump movement values inputAction.PlayerControls.Spell0.performed += ctx => spellInputTable[0] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell0.canceled += ctx => spellInputTable[0] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell1.performed += ctx => spellInputTable[1] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell1.canceled += ctx => spellInputTable[1] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell2.performed += ctx => spellInputTable[2] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell2.canceled += ctx => spellInputTable[2] = ctx.ReadValue <float>(); }
public void SetPlayerNumber(int p) { playerNumber = p; _user = new InputUser(); if (playerNumber >= Gamepad.all.Count) { //This means that somehow, there are more players in the game then gamepads //Remember to throw an exception playerNumber = 0; } _user = InputUser.PerformPairingWithDevice(Gamepad.all[playerNumber]); _user.AssociateActionsWithUser(inputAction); }
public void LoadSelection() { controls.Player.Run.started += _ => running = true; controls.Player.Run.canceled += _ => running = false; controls.Player.Move.started += context => OnMove(context.ReadValue <Vector2>()); controls.Player.Move.performed += context => OnMove(context.ReadValue <Vector2>()); controls.Player.Move.canceled += context => OnMove(context.ReadValue <Vector2>()); controls.Player.Interact.started += delegate { OnInteractButtonPressed(); }; controls.Player.Jump.started += delegate { OnJumpPressed(); }; controls.Player.Start.started += delegate { OnStartPressed(); }; user.AssociateActionsWithUser(controls); GetComponentInChildren <RandomColor>().SetColor(PlayerSkinManager.Instance.Colors[id]); m_RandomSkin.ToggleSkin(PlayerSkinManager.Instance.GetSelection(id)); }
void SetupInGameDevices() { if (inputDevice is Gamepad) { gamepad = inputDevice as Gamepad; inputType = InputType.GP; } else { keyboard = inputDevice as Keyboard; mouse = InputSystem.GetDevice <Mouse>(); inputType = InputType.KB; inputUser = InputUser.PerformPairingWithDevice(mouse, inputUser); } inputUser = InputUser.PerformPairingWithDevice(inputDevice, inputUser); inputUser.AssociateActionsWithUser(controls); }
void SetupTestingDevices() { if (testingController) { inputDevice = InputSystem.GetDevice <Gamepad>(); gamepad = inputDevice as Gamepad; inputType = InputType.GP; } else if (testingMouseAndKeyboard) { inputDevice = InputSystem.GetDevice <Keyboard>(); keyboard = inputDevice as Keyboard; mouse = InputSystem.GetDevice <Mouse>(); inputType = InputType.KB; inputUser = InputUser.PerformPairingWithDevice(mouse, inputUser); } inputUser = InputUser.PerformPairingWithDevice(inputDevice, inputUser); inputUser.AssociateActionsWithUser(controls); }
void AddPlayer(InputUser user) { Transform spawnPoint = GameObject.Find("SpawnPoint" + user.index).transform; GameObject playerInstance = Instantiate(playerPrefab, spawnPoint.position, spawnPoint.rotation); playerInstance.GetComponent <Player>().user = user; // Create a new instance of input actions to prevent InputUser from triggering actions on another InputUser. Controls controlsForThisUser = new Controls(); // you must enable the controls to use them controlsForThisUser.Enable(); // the real work is done for us in InputUser user.AssociateActionsWithUser(controlsForThisUser); playerInstance.GetComponent <PlayerMovement>().BindControls(controlsForThisUser.Player); // Creating an empty GameObject that will follow the player (for camera framing purposes) GameObject followGO = new GameObject("FollowTargetGroupElement"); followGO.AddComponent <FollowTargetGroupElements>(); followGO.GetComponent <FollowTargetGroupElements>().objectToFollow = playerInstance; followGO.GetComponent <FollowTargetGroupElements>().boundSize = new Vector2(40, 20); followGO.GetComponent <FollowTargetGroupElements>().weight = targetGroupWeight; // Add it to the camera's target group targetGroup.AddMember(followGO.transform, 1, targetGroupWeight); // Change the players overhead arrow color playerInstance.GetComponentInChildren <SpriteShapeRenderer>().color = playerColors[user.index]; // Add the Players Percentage UI if it doesn't exist if (user.index + 1 > ingameCanvas.transform.GetChild(0).childCount) { Instantiate(percentage, ingameCanvas.transform.GetChild(0)).GetComponent <Image>().color = playerColors[user.index]; } // Default percentage to zero UpdatePercentage(user.index, 0); UpdateLives(user.index, playerLives[user.index]); }
// Start is called before the first frame update void Awake() { cursorSpeed = 150f; //Should not hardcode this, temporary transform.position = new Vector3(15, 40, 82); mesh = GetComponent <MeshFilter>().mesh; CreateShape(); UpdateMesh(); selections = new GameObject[3]; selectInputArray = new float[3]; //Input for controlling the arrow inputAction = new PlayerInputActions(); //Here we handle multiple users _user = new InputUser(); if (playerNumber >= Gamepad.all.Count) { //This means that somehow, there are more players in the game then gamepads //Remember to throw an exception playerNumber = 0; } _user = InputUser.PerformPairingWithDevice(Gamepad.all[playerNumber]); _user.AssociateActionsWithUser(inputAction); //Setup input for Navigate movement value press AND release //inputAction.MenuControls.Navigate.performed += ctx => movementInput = ctx.ReadValue<Vector2>(); //inputAction.MenuControls.Navigate.canceled += ctx => movementInput = ctx.ReadValue<Vector2>(); inputAction.PlayerControls.Walk.performed += ctx => movementInput = ctx.ReadValue <Vector2>(); inputAction.PlayerControls.Walk.canceled += ctx => movementInput = ctx.ReadValue <Vector2>(); //Setup input for select input values. inputAction.PlayerControls.Spell0.performed += ctx => selectInputArray[0] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell1.performed += ctx => selectInputArray[1] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell2.performed += ctx => selectInputArray[2] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell0.canceled += ctx => selectInputArray[0] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell1.canceled += ctx => selectInputArray[1] = ctx.ReadValue <float>(); inputAction.PlayerControls.Spell2.canceled += ctx => selectInputArray[2] = ctx.ReadValue <float>(); DontDestroyOnLoad(this.gameObject); }
public void Init(InputUser user) { this.user = user; user.AssociateActionsWithUser(controls); }
public InputState(IInputActionCollection actions, InputControlScheme controlScheme) { User = InputUser.CreateUserWithoutPairedDevices(); User.AssociateActionsWithUser(actions); SwitchControlScheme(controlScheme); }
private void UnpairedDeviceUsed(InputControl control, InputEventPtr eventPtr) { if (!(control is ButtonControl) || control.device.displayName == "Keyboard" || control.device.displayName == "Mouse") { return; } Debug.Log("Device: " + control.device.displayName); InputUser user = InputUser.PerformPairingWithDevice(control.device); PlayerControls controlsForUser = new PlayerControls(); user.AssociateActionsWithUser(controlsForUser); controlsForUser.Enable(); if (players.Count == 0) { player1.GetComponent <Movement>().BindControls(controlsForUser); player1.SetActive(true); player1.transform.position = spawnPoint1.transform.position; players.Add(player1.GetComponent <Movement>()); GetComponent <Deathcount>().player1Deaths = 0; } else if (players.Count == 1) { player2.GetComponent <Movement>().BindControls(controlsForUser); player2.SetActive(true); player2.transform.position = spawnPoint2.transform.position; players.Add(player2.GetComponent <Movement>()); GetComponent <Deathcount>().player2Deaths = 0; } else if (players.Count == 2) { player3.GetComponent <Movement>().BindControls(controlsForUser); player3.SetActive(true); player3.transform.position = spawnPoint3.transform.position; players.Add(player3.GetComponent <Movement>()); GetComponent <Deathcount>().player3Deaths = 0; } else if (players.Count == 3) { player4.GetComponent <Movement>().BindControls(controlsForUser); player4.SetActive(true); player4.transform.position = spawnPoint4.transform.position; players.Add(player4.GetComponent <Movement>()); GetComponent <Deathcount>().player4Deaths = 0; } List <GameObject> tempPlayers = new List <GameObject>(); foreach (var item in players) { tempPlayers.Add(item.gameObject); } InputUser.listenForUnpairedDeviceActivity--; if (InputUser.listenForUnpairedDeviceActivity == 0) { StopJoining(); } }
void PlayerPressedStart(InputAction.CallbackContext value) { //check for max amount of players if (m_ControllerIds.Count == m_MaxPlayers) { Debug.Log("The maximum amount of players has already been reached."); } else { //check if controller is already used if (m_ControllerIds.Contains(m_GameInputControls.MenuControls.Start.activeControl.device.deviceId)) { Debug.Log("Device is already assigned to a player"); } //add a player else { InputDevice controller = m_GameInputControls.MenuControls.Start.activeControl.device; m_ControllerIds.Add(controller.deviceId); //setup the controls and user Controls gameInputControls = new Controls(); gameInputControls.MenuControls.Enable(); //we start in a menu InputUser user = InputUser.PerformPairingWithDevice(m_GameInputControls.MenuControls.Start.activeControl.device); user.AssociateActionsWithUser(gameInputControls); //spawn the player object and initiate it properly GameObject menu = Instantiate(m_SelectionMenu, m_MainLayout.transform); InputBehaviour inputBeh = menu.GetComponentInChildren <InputBehaviour>(); if (inputBeh != null) { inputBeh.SetInputUser(user, controller); inputBeh.RumbleController(0.8f, 0.66f); } CharacterSelection characterSelection = menu.GetComponentInChildren <CharacterSelection>(); if (characterSelection != null) { characterSelection.SetPlayerIndex(m_PlayerId); m_PlayerSelections.Add(characterSelection); } //set player id to the charactercontrol inputBeh.gameObject.GetComponent <CharacterControl>().PlayerId = m_PlayerId; //save the camera m_Cameras[m_PlayerId] = menu.GetComponentInChildren <Camera>(); //inc playerid ++m_PlayerId; //this setup has to be after the increment (has to do with the actual player numbers and not their spot in an array which starts at 0) SetupCameras(); Debug.Log("Player " + m_PlayerId + "joinend!"); } } if (m_PlayerId == 4) { m_HelpText.SetActive(false); } }