Beispiel #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);
            }
        }
Beispiel #2
0
 public void OnPlayerLeft(PlayerDevice playerDevice)
 {
     if (playerDevice.id == SlotNumber)
     {
         _playerDevice = null;
         Status = PlayerStatus.Disconnected;
     }
 }
Beispiel #3
0
 public void OnPlayerJoined(PlayerDevice playerDevice)
 {
     if (playerDevice.id == SlotNumber)
     {
         _playerDevice = playerDevice;
         Status = PlayerStatus.Connected;
     }
 }
Beispiel #4
0
        public void OnPlayerLeft(PlayerDevice playerData)
        {
            if (playerData.id == SlotNumber)
            {
                _playerData = null;

                gameObject.SetActive(false);
            }
        }
Beispiel #5
0
        public void OnPlayerJoined(PlayerDevice playerData)
        {
            if (playerData.id == SlotNumber)
            {
                _playerData = playerData;

                gameObject.SetActive(true);
            }
        }
Beispiel #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");
            }
        }
Beispiel #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");
            }
        }
Beispiel #8
0
 private void EndGame(PlayerDevice player)
 {
     _image.color = Colors[player.id];
     StartCoroutine(PlayAnim());
 }
Beispiel #9
0
 public void TryRemovePlayer(PlayerDevice player)
 {
     if (Players.Contains(player))
     {
         Players.Remove(player);
         InputSignals.PlayerRemoved.Dispatch(player);
     }
 }
Beispiel #10
0
 private void AddPlayer(PlayerDevice newPlayer)
 {
     Players.Add(newPlayer);
     InputSignals.PlayerJoined.Dispatch(newPlayer);
 }
Beispiel #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);
        }
Beispiel #12
0
 void RefreshXinputDevices()
 {
     XInputDevices.Clear();
     foreach (var xInputDevice in GetXInputDevices())
     {
         PlayerDevice newPlayer = new PlayerDevice()
         {
             id = xInputDevice.DeviceIndex,
             InControlDevice = xInputDevice
         };
         XInputDevices.Add(newPlayer);
     }
 }