void OnGUI() { if (!showGUI) { return; } GUILayout.BeginArea(new Rect(10 + offsetX, 40 + offsetY, 215, 9999)); if (!NetworkClient.isConnected && !NetworkServer.active) { if (!NetworkClient.active) { // LAN Host if (Application.platform != RuntimePlatform.WebGLPlayer) { if (GUILayout.Button("LAN Host")) { manager.StartHost(); } } // LAN Client + IP GUILayout.BeginHorizontal(); if (GUILayout.Button("LAN Client")) { manager.StartClient(); } manager.networkAddress = GUILayout.TextField(manager.networkAddress); GUILayout.EndHorizontal(); // LAN Server Only if (Application.platform == RuntimePlatform.WebGLPlayer) { // cant be a server in webgl build GUILayout.Box("( WebGL cannot be server )"); } else { if (GUILayout.Button("LAN Server Only")) { manager.StartServer(); } } } else { // Connecting GUILayout.Label("Connecting to " + manager.networkAddress + ".."); if (GUILayout.Button("Cancel Connection Attempt")) { manager.StopClient(); } } } else { // server / client status message if (NetworkServer.active) { GUILayout.Label("Server: active. Transport: " + Transport.activeTransport); } if (NetworkClient.isConnected) { GUILayout.Label("Client: address=" + manager.networkAddress); } } // client ready if (NetworkClient.isConnected && !ClientScene.ready) { if (GUILayout.Button("Client Ready")) { ClientScene.Ready(NetworkClient.connection); if (ClientScene.localPlayer == null) { ClientScene.AddPlayer(); } } } // stop if (NetworkServer.active || NetworkClient.isConnected) { if (GUILayout.Button("Stop")) { manager.StopHost(); } } GUILayout.EndArea(); }
public override void OnEnable() { mainVertPanel = new VerticalPanel { AnchorPreset = AnchorPresets.VerticalStretchLeft, Width = 250, TopMargin = offset.Y, LeftMargin = offset.X, BottomMargin = 0, Parent = uiRoot.GUI, }; hostBtn = new Button { Parent = mainVertPanel, Text = "Host a server", Visible = false, Font = font, }; clientPanel = new HorizontalPanel { Parent = mainVertPanel, Height = 30, Visible = false, }; clientBtn = new Button { Parent = clientPanel, Text = "Connect as client", Font = font, }; clientAddress = new TextBox { Parent = clientPanel, Font = font, }; serverBtn = new Button { Parent = mainVertPanel, Text = "Start Server", Visible = false, Font = font, }; connecting = new Label { Parent = mainVertPanel, Text = "Connecting to server", Visible = false, Font = font, }; cancelConnect = new Button { Parent = mainVertPanel, Text = "Cancel connection attempt", Visible = false, Font = font, }; transport = new Label { Parent = mainVertPanel, Text = "Transport is", Visible = false, Font = font, AutoHeight = true, Wrapping = TextWrapping.WrapWords, }; address = new Label { Parent = mainVertPanel, Text = "address is", Visible = false, Font = font, }; clientReadyBtn = new Button { Parent = mainVertPanel, Text = "Client Ready", Visible = false, Font = font, }; cancelHostBtn = new Button { Parent = mainVertPanel, Text = "Stop hosting", Visible = false, Font = font, }; cancelClientBtn = new Button { Parent = mainVertPanel, Text = "Disconnect", Visible = false, Font = font, }; cancelServerBtn = new Button { Parent = mainVertPanel, Text = "Stop server", Visible = false, Font = font, }; hostBtn.Clicked += () => { manager.StartHost(); }; clientBtn.Clicked += () => { manager.StartClient(); }; clientAddress.TextChanged += () => { manager.networkAddress = clientAddress.Text; }; serverBtn.Clicked += () => { manager.StartServer(); }; cancelConnect.Clicked += () => { manager.StopClient(); }; clientReadyBtn.Clicked += () => { ClientScene.Ready(NetworkClient.connection); if (ClientScene.localPlayer == null) { ClientScene.AddPlayer(NetworkClient.connection); } }; cancelHostBtn.Clicked += () => { manager.StopHost(); }; cancelClientBtn.Clicked += () => { manager.StopClient(); }; cancelServerBtn.Clicked += () => { manager.StopServer(); }; }
void OnGUI() { if (!showGUI) { return; } GUI.contentColor = Color.white; GUI.backgroundColor = Color.black; int HEIGHT = Screen.height; int WIDTH = Screen.width; Rect areaRect; { int w = WIDTH / 5; int h = (int)(HEIGHT * 0.9f); int x = (WIDTH - w) / 2; int y = (HEIGHT - h) / 2; areaRect = new Rect(x, y, w, h); } int MIN = 18; var newLineHeigth = GUILayout.Height(Mathf.Max(HEIGHT / 10, MIN)); var newLineHeigthHalved = GUILayout.Height(Mathf.Max(HEIGHT / 20, MIN)); GUILayout.BeginArea(areaRect); if (!NetworkClient.isConnected && !NetworkServer.active) { if (!NetworkClient.active) { // // LAN Host // if (Application.platform != RuntimePlatform.WebGLPlayer) // { // if (GUILayout.Button("LAN Host")) // { // manager.StartHost(); // } // } // LAN Client + IP //GUILayout.BeginHorizontal(); { const string defaulthost = "localhost"; const string networkAddressKey = "manager.networkAddress"; manager.networkAddress = GUILayout.TextField(PlayerPrefs.GetString("manager.networkAddress", defaulthost), newLineHeigthHalved); if (manager.networkAddress.Length == 0) { manager.networkAddress = defaulthost; } PlayerPrefs.SetString(networkAddressKey, manager.networkAddress); if (GUILayout.Button("START", newLineHeigth))//if (GUILayout.Button("LAN Client")) { manager.StartClient(); } } //GUILayout.EndHorizontal(); // LAN Server Only if (Application.platform == RuntimePlatform.WebGLPlayer) { // cant be a server in webgl build GUILayout.Box("( WebGL cannot be server )"); } else { GUILayout.FlexibleSpace(); if (GUILayout.Button("Start Server", newLineHeigthHalved)) { manager.StartServer(); } // if (GUILayout.Button("LAN Server Only")) manager.StartServer(); } } else { // Connecting GUILayout.Label("Connecting to " + manager.networkAddress + ".."); if (GUILayout.Button("Cancel Connection Attempt", newLineHeigth)) { manager.StopClient(); } } } else { // server / client status message if (NetworkServer.active) { GUILayout.Label("Server: active. Transport: " + Transport.activeTransport); } if (NetworkClient.isConnected) { GUILayout.Label("Client: address=" + manager.networkAddress); } } // client ready if (NetworkClient.isConnected && !ClientScene.ready) { if (GUILayout.Button("Client Ready", newLineHeigth)) { ClientScene.Ready(NetworkClient.connection); if (ClientScene.localPlayer == null) { ClientScene.AddPlayer(); } } } GUILayout.EndArea(); // stop //if (NetworkServer.active || NetworkClient.isConnected) if (NetworkClient.isConnected) { if (GUILayout.Button("Exit", newLineHeigthHalved, GUILayout.Width(WIDTH / 10))) { manager.StopHost(); } } if (NetworkServer.active) { GUILayout.BeginHorizontal(); GUILayout.Label(" GET MY IP: ", newLineHeigthHalved); GUILayout.TextField("https://www.whatismybrowser.com/detect/what-is-my-local-ip-address", newLineHeigthHalved); // GUILayout.Label(" LOCAL IPv4: ",newLineHeigthHalved); // GUILayout.Label(_localIPv4,newLineHeigthHalved); GUILayout.EndHorizontal(); } }