Ejemplo n.º 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();
        }
    }