Ejemplo n.º 1
0
    private void Reset()
    {
        m_Score = 0;
        m_Move  = Vector2.zero;
        m_Look  = Vector2.zero;

        if (m_User.valid)
        {
            m_User.UnpairDevicesAndRemoveUser();
        }
    }
Ejemplo n.º 2
0
    /// <summary>
    /// Called when a new player enters the lobby.
    /// </summary>
    /// <param name="user">Device the player is entering the lobby with. We always require device
    /// activity for a join.</param>
    /// <remarks>
    /// This should only be called while in the lobby.
    /// </remarks>
    public void OnPlayerJoins(InputUser user)
    {
        Debug.Assert(state == State.InLobby, "Joining can only happen while in the lobby");
        Debug.Assert(FindPlayerControllerForUser(user) == null, "There should not be two different players associated with the same InputUser");
        Debug.Assert(user.pairedDevices.Count > 0, "User should have at least one device that the join was initiated with");

        // If we still have inactive player objects, use those and bring an inactive
        // player back to life.
        DemoPlayerController player;

        if (m_Players != null && m_ActivePlayerCount < m_Players.Length && m_Players[m_ActivePlayerCount] != null)
        {
            // Reuse a player we've previously created. Just reactivate it and wipe its state.
            player = m_Players[m_ActivePlayerCount];
            player.gameObject.SetActive(true);
        }
        else
        {
            // Otherwise create a new player.
            var playerObject = Instantiate(playerPrefab);
            player = playerObject.GetComponent <DemoPlayerController>();
            if (player == null)
            {
                throw new Exception("Missing DemoPlayerController component on " + playerObject);
            }
            player.PerformOneTimeInitialization();

            // Add to list.
            if (m_Players == null || m_Players.Length == m_ActivePlayerCount)
            {
                Array.Resize(ref m_Players, m_ActivePlayerCount + 10);
            }
            m_Players[m_ActivePlayerCount] = player;
        }

        // Attempt to join the player based on the devices we have. If the device the player
        // joins on is part of a control scheme that requires additional devices, we may not
        // have all required devices.
        Debug.Assert(player.state == DemoPlayerController.State.Inactive);
        if (!player.OnJoin(user))
        {
            ////TODO: display feedback about missing devices
            user.UnpairDevicesAndRemoveUser();
            return;
        }

        ++m_ActivePlayerCount;

        // Whenever we add or remove players, we need to update the split-screen configuration.
        UpdateSplitScreen();
    }
Ejemplo n.º 3
0
        public static void Delete(RemoteInput remoteInput)
        {
            uint      userId        = s_mapRemoteInputAndInputUserId[remoteInput];
            InputUser user          = InputUser.all.First(_user => _user.id == userId);
            var       arrayDeviceId = user.pairedDevices.Select(device => device.deviceId).ToArray();

            user.UnpairDevicesAndRemoveUser();
            foreach (var deviceId in arrayDeviceId)
            {
                InputSystem.RemoveDevice(InputSystem.GetDeviceById(deviceId));
            }
            s_mapRemoteInputAndInputUserId.Remove(remoteInput);
            s_listRemoteInput.Remove(remoteInput);
        }
        internal static void Delete(RemoteInput remoteInput)
        {
            if (remoteInput == null)
            {
                throw new ArgumentException("The instance of argument is null");
            }
            bool found = s_mapRemoteInputAndInputUserId.TryGetValue(remoteInput, out uint userId);

            if (!found)
            {
                throw new ArgumentException("The instance of argument is not found");
            }
            InputUser user          = InputUser.all.First(_user => _user.id == userId);
            var       arrayDeviceId = user.pairedDevices.Select(device => device.deviceId).ToArray();

            user.UnpairDevicesAndRemoveUser();
            foreach (var deviceId in arrayDeviceId)
            {
                InputSystem.RemoveDevice(InputSystem.GetDeviceById(deviceId));
            }
            s_mapRemoteInputAndInputUserId.Remove(remoteInput);
            s_listRemoteInput.Remove(remoteInput);
        }
Ejemplo n.º 5
0
    /// <summary>
    /// Called when there's a change in the input user setup in the system.
    /// </summary>
    /// <param name="user"></param>
    /// <param name="change"></param>
    /// <param name="device"></param>
    private void OnUserChange(InputUser user, InputUserChange change, InputDevice device)
    {
        var player = FindPlayerControllerForUser(user);

        switch (change)
        {
        // A player has switched accounts. This will only happen on platforms that have user account
        // management (PS4, Xbox, Switch). On PS4, for example, this can happen at any time by the
        // player pressing the PS4 button and switching accounts. We simply update the information
        // we display for the player's active user account.
        case InputUserChange.AccountChanged:
        {
            if (player != null)
            {
                player.OnUserAccountChanged();
            }
            break;
        }

        // If the user has canceled account selection, we remove the user if there's no devices
        // already paired to it. This usually happens when a player initiates a join on a device on
        // Xbox or Switch, has the account picker come up, but then cancels instead of making an
        // account selection. In this case, we want to cancel the join.
        // NOTE: We are only adding DemoPlayerControllers once device pairing is complete
        case InputUserChange.AccountSelectionCanceled:
        {
            if (user.pairedDevices.Count == 0)
            {
                Debug.Assert(FindPlayerControllerForUser(user) == null);
                user.UnpairDevicesAndRemoveUser();
            }
            break;
        }

        // An InputUser gained a new device. If we're in the lobby and don't yet have a player
        // for the user, it means a new player has joined. We don't join players until they have
        // a device paired to them which is why we ignore InputUserChange.Added and only react
        // to InputUserChange.DevicePaired instead.
        case InputUserChange.DevicePaired:
        {
            if (state == State.InLobby && player == null)
            {
                OnPlayerJoins(user);
            }
            else if (player != null)
            {
                player.OnDevicesOrBindingsHaveChanged();
            }
            break;
        }

        // Some player ran out of battery or unplugged a wired device.
        case InputUserChange.DeviceLost:
        {
            Debug.Assert(player != null);
            player.OnDeviceLost();

            ////REVIEW: should we unjoin a user when losing devices in the lobby?
            ////TODO: we need a way for other players to be able to resolve the situation

            // If we're currently in-game, we pause the game until the player has re-gained control.
            if (isInGame)
            {
                PauseGame();
            }

            break;
        }

        // Some player has customized controls or had previously customized controls loaded.
        case InputUserChange.BindingsChanged:
        {
            player.OnDevicesOrBindingsHaveChanged();
            break;
        }
        }
    }
Ejemplo n.º 6
0
 public void Dispose()
 {
     gameplayInput.Dispose();
     uiInput.Dispose();
     user.UnpairDevicesAndRemoveUser();
 }