public static void MoveCursor(this UFEScreen screen, Vector3 direction, AudioClip moveCursorSound = null) { GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject; GameObject nextGameObject = null; if (currentGameObject != null && currentGameObject.activeInHierarchy) { Selectable currentSelectableObject = currentGameObject.GetComponent <Selectable>(); if (currentSelectableObject != null && currentSelectableObject.IsInteractable()) { Selectable nextSelectableObject = currentSelectableObject.FindSelectable(direction); if (nextSelectableObject != null) { nextGameObject = nextSelectableObject.gameObject; } } } if (nextGameObject == null) { nextGameObject = screen.FindFirstSelectableGameObject(); } if (currentGameObject != nextGameObject) { if (moveCursorSound != null) { UFE.PlaySound(moveCursorSound); } screen.HighlightOption(nextGameObject); } }
public static void SelectOption(this UFEScreen screen, AudioClip selectSound = null) { // Retrieve the current selected object... GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject; if (currentGameObject != null) { // Check if it's a button... Button currentButton = currentGameObject.GetComponent <Button>(); if (currentButton != null) { // In that case, raise the "On Click" event if (currentButton.onClick != null) { if (selectSound != null) { UFE.PlaySound(selectSound); } currentButton.onClick.Invoke(); } } else { // Otherwise, check if it's a toggle... Toggle currentToggle = currentGameObject.GetComponent <Toggle>(); if (currentToggle != null) { // In that case, change the state of the toggle... currentToggle.isOn = !currentToggle.isOn; } } } else { currentGameObject = screen.FindFirstSelectableGameObject(); if (selectSound != null) { UFE.PlaySound(selectSound); } screen.HighlightOption(currentGameObject); } }
private static void DefaultMoveCursorAction( this UFEScreen screen, Fix64 horizontalAxis, Fix64 verticalAxis, bool horizontalAxisDown, bool verticalAxisDown, bool confirmButtonDown, bool cancelButtonDown, AudioClip sound ) { bool axisDown = horizontalAxisDown || verticalAxisDown; //--------------------------------------------------------------------------------------------------------- // Retrieve the current selected GameObject. // If no GameObject is selected and the player press any button, select the first GameObject at the screen. //--------------------------------------------------------------------------------------------------------- GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject; if (currentGameObject == null && axisDown || confirmButtonDown || cancelButtonDown) { currentGameObject = screen.FindFirstSelectableGameObject(); } //--------------------------------------------------------------------------------------------------------- // Check if the current Selectable Object is a Slider //--------------------------------------------------------------------------------------------------------- Slider slider = currentGameObject != null?currentGameObject.GetComponent <Slider>() : null; //----------------------------------------------------------------------------------------------------- // If the current Selectable Object is a Slider, check if the user has pressed a button // in the same direction (horizontal / vertical) than the slider, change the slider value. // // If the current Selectable Object is not an Slider or if the user hasn't pressed a button // in the same direction (horizontal / vertical) than the slider, move the cursor //----------------------------------------------------------------------------------------------------- if (slider != null) { if (horizontalAxisDown && slider.direction == Slider.Direction.LeftToRight) { if (slider.wholeNumbers) { slider.value += FPMath.Sign(horizontalAxis); } else { slider.normalizedValue += FPMath.Sign(horizontalAxis) * UFEScreenExtensions.NormalizedSliderSpeed; } } else if (horizontalAxisDown && slider.direction == Slider.Direction.RightToLeft) { if (slider.wholeNumbers) { slider.value -= FPMath.Sign(horizontalAxis); } else { slider.normalizedValue -= FPMath.Sign(horizontalAxis) * UFEScreenExtensions.NormalizedSliderSpeed; } } else if (verticalAxisDown && slider.direction == Slider.Direction.BottomToTop) { if (slider.wholeNumbers) { slider.value += FPMath.Sign(verticalAxis); } else { slider.normalizedValue += FPMath.Sign(verticalAxis) * UFEScreenExtensions.NormalizedSliderSpeed; } } else if (verticalAxisDown && slider.direction == Slider.Direction.TopToBottom) { if (slider.wholeNumbers) { slider.value -= FPMath.Sign(verticalAxis); } else { slider.normalizedValue -= FPMath.Sign(verticalAxis) * UFEScreenExtensions.NormalizedSliderSpeed; } } else if (axisDown) { screen.MoveCursor(new Vector3((float)horizontalAxis, (float)verticalAxis), sound); } } else if (axisDown) { screen.MoveCursor(new Vector3((float)horizontalAxis, (float)verticalAxis), sound); } }