private void OnGUI() { GUILayout.Label($"TPS {_totalTicksThisSecond}"); switch (Mode) { case Mode.Inactive: if (GUILayout.Button("Setup Server")) { StartServer(); } if (GUILayout.Button("Setup Client")) { StartClient(); } break; case Mode.Server: switch (_server.State) { case ServerState.Stopped: GUILayout.Label("Server stopped"); GUILayout.BeginHorizontal(); _ip = GUILayout.TextField(_ip, GUILayout.Width(120)); var tmp = GUILayout.TextField(_port.ToString(), GUILayout.Width(60)); if (ushort.TryParse(tmp, out var result)) { _port = result; } if (GUILayout.Button("Start!")) { var address = new Address(); address.Port = _port; address.SetHost(_ip); _server.StartServer(address); } GUILayout.EndHorizontal(); if (GUILayout.Button("localhost")) { _ip = "localhost"; } break; case ServerState.Starting: GUILayout.Label("Server starting"); break; case ServerState.Working: GUILayout.Label("Server working"); if (GUILayout.Button("Stop!")) { _server.StopServer(); } break; case ServerState.Stopping: GUILayout.Label("Server stopping"); break; } break; case Mode.Client: switch (_client.State) { case ClientState.Disconnected: GUILayout.Label("Disconnected"); GUILayout.BeginHorizontal(); _ip = GUILayout.TextField(_ip, GUILayout.Width(120)); var tmp = GUILayout.TextField(_port.ToString(), GUILayout.Width(60)); if (ushort.TryParse(tmp, out var result)) { _port = result; } if (GUILayout.Button("Connect!")) { var address = new Address(); address.Port = _port; address.SetHost(_ip); _client.Connect(address); } GUILayout.EndHorizontal(); if (GUILayout.Button("localhost")) { _ip = "localhost"; } break; case ClientState.Connecting: GUILayout.Label("Connecting"); if (GUILayout.Button("Cancel")) { _client.EnqueueRequest(NetworkThreadRequest.CancelConnect); } break; case ClientState.WaitingForId: GUILayout.Label("WaitingForId"); break; case ClientState.Connected: GUILayout.BeginHorizontal(); GUILayout.Label("Connected"); GUILayout.Label($"Ping {_client.CurPing}"); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); tmp = GUILayout.TextField(_tickRate.ToString(), GUILayout.Width(60)); if (ushort.TryParse(tmp, out result)) { if (result > 0) { _tickRate = result; } } if (GUILayout.Button("Set tickRate")) { _client.EnqueueCommand(new ClientSetTickrateCommand { Tickrate = _tickRate }); } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); tmp = GUILayout.TextField(_ping.ToString(), GUILayout.Width(60)); if (ushort.TryParse(tmp, out result)) { if (result > 0) { _ping = result; } } if (GUILayout.Button("Set ping")) { _client.ExtraPing = _ping; } if (GUILayout.Button("Set downloadPing")) { _client.ExtraDownloadPing = _ping; } GUILayout.EndHorizontal(); if (GUILayout.Button("Disconnect")) { _client.Disconnect(); _contexts.game.Reset(); _backGameContext.Reset(); } break; case ClientState.Disconnecting: GUILayout.Label("Disconnecting"); break; } break; } }
private void OnGUI() { GUILayout.Label($"TPS {_totalTicksThisSecond}"); switch (Mode) { case Mode.Inactive: if (GUILayout.Button("Setup Server")) { StartServer(); } if (GUILayout.Button("Setup Client")) { StartClient(); } break; case Mode.Server: switch (_server.State) { case ServerState.Stopped: GUILayout.Label("Server stopped"); GUILayout.BeginHorizontal(); _ip = GUILayout.TextField(_ip, GUILayout.Width(120)); var tmp = GUILayout.TextField(_port.ToString(), GUILayout.Width(60)); if (ushort.TryParse(tmp, out var result)) { _port = result; } if (GUILayout.Button("Start!")) { var address = new Address(); address.Port = _port; address.SetHost(_ip); _server.StartServer(address); } GUILayout.EndHorizontal(); if (GUILayout.Button("localhost")) { _ip = "localhost"; } break; case ServerState.Starting: GUILayout.Label("Server starting"); break; case ServerState.Working: GUILayout.Label("Server working"); if (GUILayout.Button("Stop!")) { _server.StopServer(); } break; case ServerState.Stopping: GUILayout.Label("Server stopping"); break; } break; case Mode.Client: switch (_client.State) { case ClientState.Disconnected: GUILayout.Label("Disconnected"); GUILayout.BeginHorizontal(); _ip = GUILayout.TextField(_ip, GUILayout.Width(120)); var tmp = GUILayout.TextField(_port.ToString(), GUILayout.Width(60)); if (ushort.TryParse(tmp, out var result)) { _port = result; } if (GUILayout.Button("Connect!")) { var address = new Address(); address.Port = _port; address.SetHost(_ip); _client.Connect(address); } GUILayout.EndHorizontal(); if (GUILayout.Button("localhost")) { _ip = "localhost"; } break; case ClientState.Connecting: GUILayout.Label("Connecting"); if (GUILayout.Button("Cancel")) { _client.EnqueueRequest(NetworkThreadRequest.CancelConnect); } break; case ClientState.WaitingForId: GUILayout.Label("WaitingForId"); break; case ClientState.Connected: GUILayout.BeginHorizontal(); GUILayout.Label("Connected"); tmp = GUILayout.TextField(_tickrate.ToString(), GUILayout.Width(60)); if (ushort.TryParse(tmp, out result)) { if (result > 0) { _tickrate = result; } } if (GUILayout.Button("Set tickRate")) { _client.EnqueueCommand(new ClientSetTickrateCommand { Tickrate = _tickrate }); } var str = "States :"; for (var i = 0; i < _client.StatesCount; i++) { str += "#"; } GUILayout.Label(str); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); _message = GUILayout.TextField(_message, GUILayout.Width(120)); if (GUILayout.Button("Send message")) { _client.EnqueueCommand(new ClientChatMessageCommand { Message = _message }); } if (GUILayout.Button("Request character")) { _client.EnqueueCommand(new ClientRequestCharacterCommand()); } GUILayout.EndHorizontal(); if (GUILayout.Button("Disconnect")) { _client.Disconnect(); } break; case ClientState.Disconnecting: GUILayout.Label("Disconnecting"); break; } break; } }