private void Start() { var players = ReInput.players.Players; for (int i = 0; i < slots.Length; i++) { slots[i].Initialize(this); } joysticksCount = 0; for (int i = 0; i < players.Count; i++) { Rewired.Player player = players[i]; if (player.controllers.joystickCount > 0) { PlayerSelectionSlot slot = Array.Find(slots, x => x.Player == null); if (slot != null) { slot.AssignPlayer(players[i]); } } joysticksCount += player.controllers.joystickCount; } if (joysticksCount <= 0) { SelectKeyboard(slots[0]); SelectKeyboard(slots[1]); } }
private PlayerSelectionSlot FindNextDisabledSlot(bool includeSlotsWithJoysticks = true) { PlayerSelectionSlot result = null; bool found = false; int i = 0; while (!found && i < slots.Length) { if (!slots[i].HasJoined) { if (includeSlotsWithJoysticks || (!includeSlotsWithJoysticks && (slots[i].Player == null || slots[i].Player.controllers.joystickCount == 0))) { result = slots[i]; found = true; } } i++; } return(result); }
public void SlotReady(PlayerSelectionSlot slot, Color color) { players.Add(new PlayerEntry(slot, color)); if (players.Count >= 1) { startButton.interactable = true; } if (joysticksCount <= 0 && keyboardsCount >= 2 && players.Count >= 2) { OnGameStart(); } }
public void SelectKeyboard(PlayerSelectionSlot slot) { Rewired.Player joystickPlayerToRecycle = slot.Player; if (joystickPlayerToRecycle != null && joystickPlayerToRecycle.controllers.joystickCount <= 0) { joystickPlayerToRecycle = null; } Rewired.Player player = FindNextAvailableKeyboardPlayer(); if (player != null) { slot.AssignPlayer(player); if (joystickPlayerToRecycle != null) { PlayerSelectionSlot nextAvailableSlot = FindNextDisabledSlot(false); if (nextAvailableSlot != null) { nextAvailableSlot.AssignPlayer(joystickPlayerToRecycle); } } if (FindNextAvailableKeyboardPlayer() == null) { for (int i = 0; i < slots.Length; i++) { slots[i].IsKeyBoardAvailable(false); } } keyboardsCount++; } }
public PlayerEntry(PlayerSelectionSlot slot, Color color) { Slot = slot; Color = color; }