using UnityEngine; using UnityEngine.UIElements; using System.Collections.Generic; using System.Linq; using MegaKoop.Steam; namespace MegaKoop.UI { /// /// Professional Multiplayer Lobby Controller with Steam API Integration /// Senior-level implementation with proper state management /// public class MultiplayerLobbyController : MonoBehaviour { [Header("UI Document")] [SerializeField] private UIDocument uiDocument; [Header("Lobby Settings")] [SerializeField] private int maxPlayers = 4; [SerializeField] private string[] maxPlayersOptions = { "2", "3", "4", "8" }; // Root element private VisualElement root; // Panel private VisualElement multiplayerPanel; // Header Elements private Label lobbyStatusLabel; private VisualElement statusIndicator; // Lobby Code Section private VisualElement lobbyCodeSection; private Label lobbyCodeDisplay; private Button copyCodeButton; // Connection Section private VisualElement lobbyConnectionSection; private Button hostLobbyButton; private Button joinLobbyButton; private VisualElement joinLobbyContent; private VisualElement hostLobbyContent; private TextField lobbyCodeInput; private Button connectButton; private Button createLobbyButton; private DropdownField maxPlayersDropdown; private Toggle publicLobbyToggle; // Players Section private VisualElement playersSection; private Label playerCountLabel; private ScrollView playersListScrollView; private VisualElement playersList; private VisualElement emptyPlayersState; // Host Controls private VisualElement hostControlsSection; private Button inviteFriendsButton; private Button kickPlayerButton; // Player Ready Section private VisualElement playerReadySection; private Button toggleReadyButton; private Label readyIcon; private Label readyText; // Footer private Button startGameButton; private Button leaveLobbyButton; private Button backFromMultiplayerButton; // Lobby State private bool isHost = false; private bool isInLobby = false; private bool isPlayerReady = false; private List connectedPlayers = new List(); private string currentLobbyCode = ""; private string selectedPlayerSteamId = ""; // Steam Integration private SteamLobbyService steam; private void Start() { if (uiDocument == null) uiDocument = GetComponent(); if (uiDocument != null) { root = uiDocument.rootVisualElement; InitializeElements(); RegisterEvents(); EnsureSteamServices(); RegisterSteamEvents(); SetupInitialState(); } else { Debug.LogError("UIDocument not found on MultiplayerLobbyController!"); } } private void OnDisable() { UnregisterEvents(); UnregisterSteamEvents(); } #region Initialization private void InitializeElements() { // Panel multiplayerPanel = root.Q("MultiplayerPanel"); // Header lobbyStatusLabel = root.Q