void OnGUI() { if (optionsMenuOpen) { GUI.Box(new Rect(0, 0, Screen.width, Screen.height), ""); GUI.Box(new Rect(Screen.width / 2 - 10, Screen.height / 2 - 100, 100, 25), "Volume"); AudioListener.volume = Mathf.Pow(GUI.HorizontalSlider(new Rect(Screen.width / 2 + 100, Screen.height / 2 - 95, 200, 20), Mathf.Sqrt(AudioListener.volume), 0, 1), 2); GUI.Box(new Rect(Screen.width / 2 - 10, Screen.height / 2 - 60, 100, 25), "Sensitivity"); PlayerMove.sensitivity = GUI.HorizontalSlider(new Rect(Screen.width / 2 + 100, Screen.height / 2 - 55, 200, 20), PlayerMove.sensitivity, 0.025f, 6f); for (int i = 0; i < numBinds; i++) { if (settingBind[i]) { GUI.Button(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 100 + i * 25, 180, 25), bindInfo[i] + "..."); } else if (GUI.Button(new Rect(Screen.width / 2 - 200, Screen.height / 2 - 100 + i * 25, 180, 25), bindInfo[i] + "'" + getBindString(binds[i]) + "'")) { for (int n = 0; n < numBinds; n++) { settingBind[n] = false; } settingBind[i] = true; isSettingBind = true; } } if (GUI.Button(new Rect(Screen.width - 200, 200, 150, 50), "Resume")) { optionsMenuOpen = false; ChangeLockState(); return; } if (GUI.Button(new Rect(Screen.width / 2 - 150, Screen.height / 2 + 220, 140, 40), "Disconnect")) { // Disconnects from everything, resets all static variables. Also closes escape menu? RunGame.Disconnect(); ResetStaticVariables(); SceneManager.LoadScene(0); // Reloads map. } if (GUI.Button(new Rect(Screen.width / 2 + 10, Screen.height / 2 + 220, 140, 40), "Quit")) { Application.Quit(); } } }
void Update() { if ((RunGame.myClient != null && !OperationNetwork.isServer) || OperationNetwork.isDemo) { if (RunGame.myClient != null) { RunGame.myClient.ReadMessages(); } GetComponent <Interp>().InterpUpdate(); } if (Input.GetKeyDown(KeyCode.G)) { Time.timeScale = 0.02f; } else if (Input.GetKeyDown(KeyCode.H)) { Time.timeScale = 1; } if (OperationNetwork.isDemo) { if (Input.GetKeyDown(KeyCode.Alpha1)) { Time.timeScale *= 0.5f; } else if (Input.GetKeyDown(KeyCode.Alpha2)) { Time.timeScale *= 2; } else if (Input.GetKeyDown(KeyCode.Alpha3)) { Time.timeScale = 1; } // Read.. execute.. This will disconnect the client on the last ~10 seconds. try { byte[] readInData = new byte[OperationNetwork.maxDemoData]; // Just in case: int x = 0; while (OperationNetwork.lastTickLoaded < Interp.getTickNumber() + 5) // Only laods in 5 ticks ahead { OperationNetwork.timeReceivedForDemo = false; Buffer.BlockCopy(OperationNetwork.dataToReadIn, OperationNetwork.currentByte, readInData, 0, Math.Min(OperationNetwork.maxDemoData, OperationNetwork.dataToReadIn.Length - OperationNetwork.currentByte)); int oldByte = OperationNetwork.currentByte; OperationNetwork.clientReceivedData(readInData); // Any amount is fine, but more will generally be better x++; if (x > 100) { Debug.LogError("MAJOR DEMO FAILURE"); break; } } } catch (Exception e) { Debug.LogError(e); OperationNetwork.isDemo = false; // This is not necessarily stable: RunGame.Disconnect(); OptionsMenu.ResetStaticVariables(); SceneManager.LoadScene(0); // Reloads map. } } }