Пример #1
0
        public void TryRegisterDevice(InputDevice device)
        {
            if (IsDeviceAdded(device))
            {
                return;
            }

            int playerId = -1;
            if (isXInputDevice(device))
            {
                XInputDevice xInputDevice = device as XInputDevice;
                playerId = xInputDevice.DeviceIndex;
            }
            else
            {
                playerId = NextId;
            }

            if (playerId >= 0)
            {
                PlayerDevice newPlayer = new PlayerDevice()
                {
                    id = playerId,
                    InControlDevice = device
                };
                AddPlayer(newPlayer);
            }
        }
Пример #2
0
 public void OnPlayerLeft(PlayerDevice playerDevice)
 {
     if (playerDevice.id == SlotNumber)
     {
         _playerDevice = null;
         Status = PlayerStatus.Disconnected;
     }
 }
Пример #3
0
 public void OnPlayerJoined(PlayerDevice playerDevice)
 {
     if (playerDevice.id == SlotNumber)
     {
         _playerDevice = playerDevice;
         Status = PlayerStatus.Connected;
     }
 }
Пример #4
0
        public void OnPlayerLeft(PlayerDevice playerData)
        {
            if (playerData.id == SlotNumber)
            {
                _playerData = null;

                gameObject.SetActive(false);
            }
        }
Пример #5
0
        public void OnPlayerJoined(PlayerDevice playerData)
        {
            if (playerData.id == SlotNumber)
            {
                _playerData = playerData;

                gameObject.SetActive(true);
            }
        }
Пример #6
0
        private void Spawn(PlayerDevice player)
        {
            int spawnPoint = Random.Range(0, SpawnPoints.Count);

            GameObject newPigeon = (GameObject) Instantiate(PigeonPrefab, SpawnPoints[spawnPoint].position, Quaternion.identity);
            SpawnPoints.RemoveAt(spawnPoint);

            newPigeon.transform.parent = transform;
            PigeonController controller = newPigeon.GetComponent<PigeonController>();

            if(controller != null)
            {
                newPigeon.name = "Pigeon " + player.id;
                controller.Player = player;
            }
            else
            {
                Debug.LogError("Prefab does not have a pigeon controller");
            }
        }
Пример #7
0
        private void Spawn(PlayerDevice player)
        {
            int spawnPoint = Random.Range(0, SpawnPoints.Count);

            GameObject newPlayer = (GameObject)Instantiate(CharacterPrefab, SpawnPoints[spawnPoint].position, Quaternion.identity);
            if (!AllowDebugSpawning)
            {
                SpawnPoints.RemoveAt(spawnPoint);
            }

            newPlayer.transform.parent = transform;
            CharacterController controller = newPlayer.GetComponent<CharacterController>();

            if (controller != null)
            {
                newPlayer.name = "Player " + player.id;
                controller.Player = player;
            }
            else
            {
                Debug.LogError("Prefab does not have a character controller");
            }
        }
Пример #8
0
 private void EndGame(PlayerDevice player)
 {
     _image.color = Colors[player.id];
     StartCoroutine(PlayAnim());
 }
Пример #9
0
 public void TryRemovePlayer(PlayerDevice player)
 {
     if (Players.Contains(player))
     {
         Players.Remove(player);
         InputSignals.PlayerRemoved.Dispatch(player);
     }
 }
Пример #10
0
 private void AddPlayer(PlayerDevice newPlayer)
 {
     Players.Add(newPlayer);
     InputSignals.PlayerJoined.Dispatch(newPlayer);
 }
Пример #11
0
        private void TryConnectXInputPlayer(PlayerDevice device)
        {
            foreach (var xinput in XInputDevices)
            {
                if (xinput.id == device.id)
                {
                    if (!xinput.InControlDevice.Equals(device.InControlDevice))
                    {
                        xinput.InControlDevice = device.InControlDevice;
                        InputSignals.PlayerDeviceChanged.Dispatch(xinput);
                    }
                    else
                    {
                        return;
                    }
                }
            }

            //Remove player if not found in XInputDevices as that player has lost connection to its device
            TryRemovePlayer(device);
        }
Пример #12
0
 void RefreshXinputDevices()
 {
     XInputDevices.Clear();
     foreach (var xInputDevice in GetXInputDevices())
     {
         PlayerDevice newPlayer = new PlayerDevice()
         {
             id = xInputDevice.DeviceIndex,
             InControlDevice = xInputDevice
         };
         XInputDevices.Add(newPlayer);
     }
 }