Exemple #1
0
    void Start()
    {
        GameData.networkPlayers.Clear();
        discoveredServers.Clear();

        roomListPanel.SetActive(!GameData.isHost);
        playerListPanel.SetActive(GameData.isHost);
        networkDiscovery = GetComponent <MyNetworkDiscovery>();
        networkDiscovery.OnServerFound.AddListener(OnDiscoveredServer);
        roomPanelBackBtn.onClick.AddListener(Back);
        playerPanelBackBtn.onClick.AddListener(Back);
        startGameBtn.gameObject.SetActive(false); // 开始不显示游戏开始按钮
        startGameBtn.onClick.AddListener(OnClickStartGame);
        MyNetworkRoomManager mamager = NetworkManager.singleton as MyNetworkRoomManager;

        mamager.onCreateRoomPlayer     = OnCreateRoomPlayer;
        mamager.onClientDisconnect     = OnClientDisconnect;
        mamager.onGameStartStateChange = OnGameStartStateChange;
        if (GameData.isHost)
        {
            roomName.text = $"[{GameData.playerName}的房间]";
            NetworkManager.singleton.StartHost();
            networkDiscovery.AdvertiseServer();
        }
        else
        {
            networkDiscovery.MyStartDiscovery();
        }
    }
Exemple #2
0
 private void Back()
 {
     if (roomListPanel.activeSelf)
     {
         // 从房间列表返回
         BackToOffline();
     }
     else
     {
         // 从用户列表返回
         if (GameData.isHost)
         {
             // 到离线界面
             BackToOffline();
         }
         else
         {
             // 到房间列表
             playerListPanel.SetActive(false);
             roomListPanel.SetActive(true);
             NetworkManager.singleton.StopClient();
             discoveredServers.Clear();
             networkDiscovery.MyStartDiscovery();
         }
     }
 }