// Update is called once per frame void Update() { if (UtilsC.CheckPeerType(NetworkPeerType.Disconnected) && UtilsC.IsHostsExists()) { hostData = MasterServer.PollHostList(); } }
void Update() { // 当本客户端没有连接并且有主机地址存在的时候,拉取服务器列表 if (UtilsC.CheckPeerType(NetworkPeerType.Disconnected) && UtilsC.IsHostsExists()) { hostData = MasterServer.PollHostList(); } }
void LocalPlayerTriggerEnterC2S(NetworkPlayer player, int checkPointIndex) { // 在服务器端执行 if (UtilsC.CheckPeerType(NetworkPeerType.Server)) { OnCarEnterCheckPoint(player, checkPointIndex); } }
// 断掉连接 public void Disconnect(int timeout) { if (playerObjMap.ContainsKey(Network.player)) { playerObjMap.Remove(Network.player); } bool isServer = UtilsC.CheckPeerType(NetworkPeerType.Server); Network.Disconnect(timeout); if (isServer) { MasterServer.UnregisterHost(); } }
void OnGUI() { if (UIManager.C_USE_NEW_UI == false) { GUI.skin = guiskin; GUILayout.Label("Connection status: " + Network.peerType.ToString()); if (UtilsC.CheckPeerType(NetworkPeerType.Disconnected)) { switch (menuState) { // 选择赛车 case "setavatarstyle": SetAvatarStyle(); break; // 显示主菜单 case "menublock": MenuBlock(); break; // 建立比赛房间 case "hostgame": HostGame(); break; // 进入比赛房间 case "findgame": FindGame(); break; // case "offlinegame":OfflineGameSettings(); // break; // 设置玩家名称 case "setname": SetPlayerName(); break; // 消息出错 case "networkerror": MSG_Error(); break; // 尝试重连 case "tryingtoconnect": MSG_TryingToConnect(); break; // 设置玩家名称 default: SetPlayerName(); break; } } DrawCursor(); } }
void InGameMenu() { if (UtilsC.CheckPeerType(NetworkPeerType.Client)) { if (GUILayout.Button("Disconnect")) { networkConnection.Disconnect(200); } GUILayout.Label("Ping to server: " + Network.GetAveragePing(Network.connections[0])); } if (UtilsC.CheckPeerType(NetworkPeerType.Server)) { if (GUILayout.Button("Stop Server", GUILayout.MaxWidth(115))) { networkConnection.Disconnect(200); } if (Network.connections.Length > 0) { GUILayout.Label("Connections: " + Network.connections.Length); scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(170), GUILayout.Height(100)); for (int i = 0; i < Network.connections.Length; i++) { GUILayout.Label("Ping to " + i.ToString() + " player: " + Network.GetAveragePing(Network.connections[i])); if (GUILayout.Button("Kick " + i.ToString() + " player", GUILayout.MaxWidth(150))) { networkConnection.Kick(Network.connections[i], true); } } GUILayout.EndScrollView(); } else { GUILayout.Label("No Player Connected"); } } GUILayout.Label("You Name: " + networkConnection.playerName); if (networkConnection.usePassword && UtilsC.IsStringCorrect(networkConnection.password)) { GUILayout.Label("Server Password: " + networkConnection.password); } }
public void OnQuit() { if (UtilsC.CheckPeerType(NetworkPeerType.Client)) { networkConnection.Disconnect(200); } if (UtilsC.CheckPeerType(NetworkPeerType.Server)) { networkConnection.Disconnect(200); if (Network.connections.Length > 0) { for (int i = 0; i < Network.connections.Length; i++) { networkConnection.Kick(Network.connections[i], true); } } } }