public void OnGUI() { if (_shouldClearFocus) { GUI.FocusControl(string.Empty); _shouldClearFocus = false; } // Draw the GUI. GUI.Box(MenuBounds, "GUI demo"); // Draw Spin button, and set up handling for it var spinButtonInteractor = _eyeXHost.GetInteractor(SpinButtonId); GUI.SetNextControlName(SpinButtonId); if (GUI.Button(SpinButtonBounds, "Take it for a spin") || spinButtonInteractor.IsActivated()) { // Either the button has been clicked, or the corresponding interactor has been activated StartCoroutine("ShowActivationFeedback", SpinButtonId); StartSpinning(); } else if (spinButtonInteractor.GetActivationFocusState() == ActivationFocusState.HasActivationFocus) { // else, if user is looking at button while pressing down activation key GUI.FocusControl(SpinButtonId); } // Draw Stop button, and set up handling for it var stopButtonInteractor = _eyeXHost.GetInteractor(StopButtonId); GUI.SetNextControlName(StopButtonId); if (GUI.Button(StopButtonBounds, "Stop it") || stopButtonInteractor.IsActivated()) { // Either the button has been clicked, or the corresponding interactor has been activated StartCoroutine("ShowActivationFeedback", StopButtonId); StopSpinning(); } else if (stopButtonInteractor.GetActivationFocusState() == ActivationFocusState.HasActivationFocus) { // else, if user is looking at button while pressing down activation key GUI.FocusControl(StopButtonId); } }
/// <summary> /// Update interactor location and act on events /// </summary> public void Update() { foreach (Transform menuItem in _menuItems) { var interactorId = menuItem.name; // Update location var interactor = _eyeXHost.GetInteractor(interactorId); interactor.Location = CreateLocation(menuItem, _gameMenu.IsVisible); // Check if activated if (interactor.IsActivated()) { HandleActivation(interactorId); } // Check if focus has changed var activationFocusState = interactor.GetActivationFocusState(); if (activationFocusState == ActivationFocusState.HasActivationFocus || activationFocusState == ActivationFocusState.HasTentativeActivationFocus) { HighlightMenuItem(menuItem); } else { RestoreMenuItem(menuItem); } // Manually bind the Right Shift key to trigger an activation mode on, on key down if (Input.GetKeyDown(KeyCode.RightShift)) { _eyeXHost.TriggerActivationModeOn(); } // Manually bind the Right Shift key to trigger an activation, on key up if (Input.GetKeyUp(KeyCode.RightShift)) { _eyeXHost.TriggerActivation(); } } }
protected virtual void Update() { var interactor = _eyeXHost.GetInteractor(_interactorId); UpdateInteractorLocation(interactor); }