private void Start() { Gm.instance.State = GameState.Menu; _notificationText = notification.GetComponentInChildren <TextMeshProUGUI>(); _notificationJoinDelay = notification.GetComponentInChildren <LeanJoinDelay>(); _serverIp = serverIpGameObject.GetComponent <TMP_InputField>(); _serverPort = serverPortGameObject.GetComponent <TMP_InputField>(); playButton.OnClick.AddListener(() => Connect(new InputAction.CallbackContext())); _rtsControls = new Rts(); _rtsControls.Enable(); _rtsControls.UI.Submit.performed += Connect; debugToggle.onValueChanged.AddListener(Advanced); developmentToggle.On = bool.Parse(PlayerPrefs.GetString("development", "false")); developmentToggle.OnOff.AddListener(() => { PlayerPrefs.SetString("serverPort", "30020"); }); developmentToggle.OnOn.AddListener(() => { PlayerPrefs.SetString("serverPort", "30021"); }); username.text = PlayerPrefs.GetString("username"); // _serverIp.text = PlayerPrefs.GetString("serverIp"); // _serverPort.text = PlayerPrefs.GetString("serverPort"); singlePlayerButton.OnClick.AddListener(() => { secondMenu.Hide(); background.Hide(); Gm.instance.State = GameState.Play; settings.Show(); }); multiplayerButton.OnClick.AddListener(() => throw new NotImplementedException("Online mode in maintenance")); // TODO next // Pointless for mobile #if UNITY_STANDALONE || UNITY_EDITOR // Lock cursor withing window in standalone Cursor.lockState = CursorLockMode.Confined; void ReLock(InputAction.CallbackContext _) { Screen.fullScreen = true; Cursor.lockState = CursorLockMode.Confined; ShowNotification("Cursor locked again"); _rtsControls.Player.Fire.performed -= ReLock; } // Basically copy paste of how Google Stadia handle full screen :D _rtsControls.Player.DoubleCancel.performed += ctx => { ShowNotification($"Press and hold {_rtsControls.Player.LongCancel.activeControl.displayName}" + $" to unlock the cursor from the window"); }; // Can unlock cursor from the window in standalone by pressing escape _rtsControls.Player.LongCancel.performed += ctx => { Screen.fullScreen = false; Cursor.lockState = CursorLockMode.None; ShowNotification("Cursor unlocked from the window," + " click inside the window to re-lock the cursor"); // Can re-lock cursor from the window in standalone by pressing escape _rtsControls.Player.Fire.performed += ReLock; }; #elif UNITY_IOS || UNITY_ANDROID UnityEngine.InputSystem.EnhancedTouch.EnhancedTouchSupport.Enable(); #endif Sm.instance.ConnectionSucceed += OnConnectionSucceed; }
private void OnEnable() { _rtsControls.Enable(); }