protected override void OnGamePaused(bool isPaused) { base.OnGamePaused(isPaused); if (this.pauseScreen != null) { if (isPaused) { this.pause = (UFEScreen)GameObject.Instantiate(this.pauseScreen); this.pause.transform.SetParent(UFE.canvas != null ? UFE.canvas.transform : null, false); this.pause.OnShow(); } else if (this.pause != null) { if (!this.hiding) { AudioClip clip = this.GetStageMusic(UFE.config.selectedStage); if (clip != null) { UFE.PlayMusic(clip); } } this.pause.OnHide(); GameObject.Destroy(this.pause.gameObject); } } }
public static bool SpecialNavigationSystem( this UFEScreen screen, int player, MoveCursorCallback moveCursorCallback = null, ActionCallback confirmCallback = null, ActionCallback cancelCallback = null ) { //------------------------------------------------------------------------------------------------------------- // Retrieve the controller assigned to specified player //------------------------------------------------------------------------------------------------------------- AbstractInputController inputController = UFE.GetController(player); if (inputController != null && UFE.eventSystem != null && UFE.eventSystem.isActiveAndEnabled) { return(UFEScreenExtensions.SpecialNavigationSystem( inputController, inputController.GetAxisRaw(inputController.horizontalAxis), inputController.GetAxisRaw(inputController.verticalAxis), inputController.GetButtonDown(inputController.horizontalAxis), inputController.GetButtonDown(inputController.verticalAxis), inputController.GetButtonDown(UFE.config.inputOptions.confirmButton), inputController.GetButtonDown(UFE.config.inputOptions.cancelButton), moveCursorCallback, confirmCallback, cancelCallback )); } return(false); }
public static bool SpecialNavigationSystem( this UFEScreen screen, IDictionary <InputReferences, InputEvents> player1PreviousInputs, IDictionary <InputReferences, InputEvents> player1CurrentInputs, IDictionary <InputReferences, InputEvents> player2PreviousInputs, IDictionary <InputReferences, InputEvents> player2CurrentInputs, MoveCursorCallback moveCursorCallback = null, ActionCallback confirmCallback = null, ActionCallback cancelCallback = null ) { return (screen.SpecialNavigationSystem( player1PreviousInputs, player1CurrentInputs, moveCursorCallback, confirmCallback, cancelCallback ) || screen.SpecialNavigationSystem( player2PreviousInputs, player2PreviousInputs, moveCursorCallback, confirmCallback, cancelCallback )); }
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 bool DefaultNavigationSystem( this UFEScreen screen, IDictionary <InputReferences, InputEvents> player1PreviousInputs, IDictionary <InputReferences, InputEvents> player1CurrentInputs, IDictionary <InputReferences, InputEvents> player2PreviousInputs, IDictionary <InputReferences, InputEvents> player2CurrentInputs, AudioClip moveCursorSound = null, AudioClip confirmSound = null, AudioClip cancelSound = null, Action cancelAction = null ) { return (screen.DefaultNavigationSystem( player1PreviousInputs, player1CurrentInputs, moveCursorSound, confirmSound, cancelSound, cancelAction ) || screen.DefaultNavigationSystem( player2PreviousInputs, player2CurrentInputs, moveCursorSound, confirmSound, cancelSound, cancelAction )); }
protected virtual void ShowScreen(UFEScreen screen) { if (screen != null) { screen.gameObject.SetActive(true); screen.OnShow(); } }
protected virtual void HideScreen(UFEScreen screen) { if (screen != null) { screen.OnHide(); screen.gameObject.SetActive(false); } }
public static bool SpecialNavigationSystem( this UFEScreen screen, MoveCursorCallback moveCursorCallback = null, ActionCallback confirmCallback = null, ActionCallback cancelCallback = null ) { return (screen.SpecialNavigationSystem(1, moveCursorCallback, confirmCallback, cancelCallback) || screen.SpecialNavigationSystem(2, moveCursorCallback, confirmCallback, cancelCallback)); }
public static bool DefaultNavigationSystem( this UFEScreen screen, AudioClip moveCursorSound = null, AudioClip confirmSound = null, AudioClip cancelSound = null, Action cancelAction = null ) { return (screen.DefaultNavigationSystem(1, moveCursorSound, confirmSound, cancelSound, cancelAction) || screen.DefaultNavigationSystem(2, moveCursorSound, confirmSound, cancelSound, cancelAction)); }
public static Selectable FindSelectable(this UFEScreen screen, Vector3 direction) { GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject; if (currentGameObject == null) { return(screen.FindFirstSelectable()); } else { return(currentGameObject.FindSelectable(direction, screen.wrapInput) ?? screen.FindFirstSelectable()); } }
public static void HighlightOption(this UFEScreen screen, GameObject option, BaseEventData pointer = null) { UFE.eventSystem.SetSelectedGameObject(option, pointer); InputField nextInputField = option != null?option.GetComponent <InputField>() : null; if (nextInputField != null) { nextInputField.OnPointerClick(new PointerEventData(UFE.eventSystem)); nextInputField.selectionAnchorPosition = 0; nextInputField.selectionFocusPosition = 0; nextInputField.ActivateInputField(); nextInputField.Select(); } }
public static Selectable FindFirstSelectable(this UFEScreen screen) { List <Selectable> selectables = Selectable.allSelectables; Transform firstSelectableTransform = null; Selectable firstSelectable = null; for (int i = 0; i < selectables.Count; ++i) { Selectable currentSelectable = selectables[i]; if ( currentSelectable != null && currentSelectable.gameObject.activeInHierarchy && currentSelectable.IsInteractable() && screen.HasSelectable(currentSelectable) ) { Transform currentTransform = currentSelectable.transform; if (screen.firstSelectableGameObject != null) { if (currentSelectable.gameObject == screen.firstSelectableGameObject) { return(currentSelectable); } } else if ( firstSelectable == null || firstSelectableTransform == null || currentTransform.position.y > firstSelectableTransform.position.y || ( currentTransform.position.y == firstSelectableTransform.position.y && currentTransform.position.x < firstSelectableTransform.position.x ) ) { firstSelectable = currentSelectable; firstSelectableTransform = currentTransform; } } } return(firstSelectable); }
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); } }
public static void MoveCursor(this UFEScreen screen, Vector3 direction, AudioClip moveCursorSound = null) { GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject; GameObject nextGameObject = screen.FindSelectableGameObject(direction); if (nextGameObject == null) { nextGameObject = currentGameObject; } if (currentGameObject != nextGameObject) { if (moveCursorSound != null) { UFE.PlaySound(moveCursorSound); } screen.HighlightOption(nextGameObject); } }
private static bool HasSelectable(this UFEScreen screen, Selectable selectable) { if (selectable != null) { Transform t = selectable.transform; UFEScreen s; while (t != null) { s = t.GetComponent <UFEScreen>(); if (s == screen) { return(true); } t = t.parent; } } return(false); }
public static void HighlightOption(this UFEScreen screen, GameObject option, BaseEventData pointer = null) { UFE.eventSystem.SetSelectedGameObject(option, pointer); }
public static void HighlightOption(this UFEScreen screen, Selectable option, BaseEventData pointer = null) { screen.HighlightOption(option != null ? option.gameObject : null, pointer); }
public static bool DefaultNavigationSystem( this UFEScreen screen, IDictionary <InputReferences, InputEvents> previousInputs, IDictionary <InputReferences, InputEvents> currentInputs, AudioClip moveCursorSound = null, AudioClip confirmSound = null, AudioClip cancelSound = null, Action cancelAction = null ) { if (UFE.eventSystem != null && UFE.eventSystem.isActiveAndEnabled) { //--------------------------------------------------------------------------------------------------------- // First, check if the current Selectable Object is an Input Field, because it's a special case... //--------------------------------------------------------------------------------------------------------- GameObject currentGameObject = UFE.eventSystem.currentSelectedGameObject; InputField inputField = currentGameObject != null?currentGameObject.GetComponent <InputField>() : null; if (inputField != null) { //----------------------------------------------------------------------------------------------------- // If it's an Input Field, check if the user wants to write a text // or if he wants to move the caret or exit from the Input Field... //----------------------------------------------------------------------------------------------------- Vector3 direction = (Input.GetKeyDown(KeyCode.UpArrow) ? Vector3.up : Vector3.zero) + (Input.GetKeyDown(KeyCode.DownArrow) ? Vector3.down : Vector3.zero); if ( direction != Vector3.zero || Input.GetKeyDown(KeyCode.Tab) || Input.GetKeyDown(KeyCode.Return) || Input.GetKeyDown(KeyCode.KeypadEnter) ) { Selectable previousSelectable = inputField; Selectable nextSelectable = null; if (direction != Vector3.zero) { nextSelectable = currentGameObject.FindSelectable(direction, false); } if (nextSelectable == null || previousSelectable == nextSelectable) { nextSelectable = currentGameObject.FindSelectable(Vector3.right, false); if (nextSelectable == null || previousSelectable == nextSelectable) { nextSelectable = currentGameObject.FindSelectable(Vector3.down, false); if (nextSelectable == null || previousSelectable == nextSelectable) { nextSelectable = currentGameObject.FindSelectable(Vector3.left, false); if (nextSelectable == null || previousSelectable == nextSelectable) { nextSelectable = currentGameObject.FindSelectable(Vector3.up, false); } } } } screen.HighlightOption(nextSelectable); } else { inputField.OnUpdateSelected(new AxisEventData(UFE.eventSystem)); } return(true); } else { //----------------------------------------------------------------------------------------------------- // Otherwise, invoke the "Special Navigation System" with the default functions //----------------------------------------------------------------------------------------------------- return(screen.SpecialNavigationSystem( previousInputs, currentInputs, new MoveCursorCallback(screen.DefaultMoveCursorAction, moveCursorSound), new ActionCallback(UFE.eventSystem.currentSelectedGameObject.DefaultConfirmAction, confirmSound), new ActionCallback(cancelAction.DefaultCancelAction, cancelSound) )); } } return(false); }
protected override void OnGamePaused(bool isPaused) { base.OnGamePaused(isPaused); if (this.pauseScreen != null){ if (isPaused){ this.pause = (UFEScreen) GameObject.Instantiate(this.pauseScreen); this.pause.transform.SetParent(UFE.canvas != null ? UFE.canvas.transform : null, false); this.pause.OnShow(); }else if (this.pause != null){ if (!this.hiding){ UFE.PlayMusic(UFE.config.selectedStage.music); } this.pause.OnHide(); GameObject.Destroy(this.pause.gameObject); } } }
// ----------------- private void OnScreenChanged(UFEScreen old, UFEScreen newScreen) { //Debug.Log(ControlFreak2.CFUtils.LogPrefix() + "Screen change:" + (old != null ? old.GetType().Name : "NULL") + // " new:" + (newScreen != null ? newScreen.GetType().Name : "NULL")); }
public static GameObject FindFirstSelectableGameObject(this UFEScreen screen) { Selectable selectable = screen.FindFirstSelectable(); return(selectable != null ? selectable.gameObject : null); }
public static void StartStoryModeConversationBeforeBattleScreen(UFEScreen conversationScreen) { UFE.StartStoryModeConversationBeforeBattleScreen(conversationScreen, UFE.config.gameGUI.defaultFadeDuration); }
protected virtual bool IsVisible(UFEScreen screen) { return screen != null ? screen.IsVisible() : false; }
public static GameObject FindSelectableGameObject(this UFEScreen screen, Vector3 direction) { Selectable selectable = screen.FindSelectable(direction); return(selectable != null ? selectable.gameObject : null); }
public static void HideScreen(UFEScreen screen) { if (screen != null){ screen.OnHide(); GameObject.Destroy(screen.gameObject); } }
public static void StartStoryModeConversationBeforeBattleScreen(UFEScreen conversationScreen, float fadeTime) { CameraFade.StartAlphaFade(Color.black, false, fadeTime/2, 0, () => { UFE._StartStoryModeConversationBeforeBattleScreen(conversationScreen, fadeTime/2); }); }
private static void _StartStoryModeConversationBeforeBattleScreen(UFEScreen conversationScreen, float fadeTime) { if (conversationScreen != null){ CameraFade.StartAlphaFade(Color.black, true, fadeTime); UFE.EndGame(); UFE.HideScreen(UFE.currentScreen); UFE.ShowScreen(conversationScreen, delegate(){UFE.StartLoadingBattleScreen(fadeTime);}); }else{ UFE._StartLoadingBattleScreen(fadeTime); } }
public static bool SpecialNavigationSystem( this UFEScreen screen, IDictionary <InputReferences, InputEvents> previousInputs, IDictionary <InputReferences, InputEvents> currentInputs, MoveCursorCallback moveCursorCallback, ActionCallback confirmCallback, ActionCallback cancelCallback ) { Fix64 currentHorizontalAxis = 0f; Fix64 currentVerticalAxis = 0f; bool currentHorizontalButton = false; bool currentVerticalButton = false; bool currentConfirmButton = false; bool currentCancelButton = false; foreach (KeyValuePair <InputReferences, InputEvents> pair in currentInputs) { if (pair.Key.inputType == InputType.HorizontalAxis) { currentHorizontalAxis = pair.Value.axisRaw; currentHorizontalButton = pair.Value.button; } else if (pair.Key.inputType == InputType.VerticalAxis) { currentVerticalAxis = pair.Value.axisRaw; currentVerticalButton = pair.Value.button; } else { if (pair.Key.engineRelatedButton == UFE.config.inputOptions.confirmButton) { currentConfirmButton = pair.Value.button; } if (pair.Key.engineRelatedButton == UFE.config.inputOptions.cancelButton) { currentCancelButton = pair.Value.button; } } } bool previousHorizontalButton = false; bool previousVerticalButton = false; bool previousConfirmButton = false; bool previousCancelButton = false; foreach (KeyValuePair <InputReferences, InputEvents> pair in previousInputs) { if (pair.Key.inputType == InputType.HorizontalAxis) { previousHorizontalButton = pair.Value.button; } else if (pair.Key.inputType == InputType.VerticalAxis) { previousVerticalButton = pair.Value.button; } else { if (pair.Key.engineRelatedButton == UFE.config.inputOptions.confirmButton) { previousConfirmButton = pair.Value.button; } if (pair.Key.engineRelatedButton == UFE.config.inputOptions.cancelButton) { previousCancelButton = pair.Value.button; } } } bool horizontalAxisDown = currentHorizontalButton && !previousHorizontalButton; bool verticalAxisDown = currentVerticalButton && !previousVerticalButton; bool confirmButtonDown = currentConfirmButton && !previousConfirmButton; bool cancelButtonDown = currentCancelButton && !previousCancelButton; // UnityEngine.Debug.Log( // UFE.currentFrame + " | " + // previousHorizontalButton + " > " + currentHorizontalButton + " | " + // previousVerticalButton + " > " + currentVerticalButton // ); if (moveCursorCallback != null && moveCursorCallback.Action != null) { moveCursorCallback.Action( currentHorizontalAxis, currentVerticalAxis, horizontalAxisDown, verticalAxisDown, confirmButtonDown, cancelButtonDown, moveCursorCallback.Sound ); } if (confirmButtonDown) { if (confirmCallback != null && confirmCallback.Action != null) { confirmCallback.Action(confirmCallback.Sound); } return(true); } else if (cancelButtonDown) { if (cancelCallback != null && cancelCallback.Action != null) { cancelCallback.Action(cancelCallback.Sound); } return(true); } return(false); }
public static void DefaultNavigationSystem( this UFEScreen screen, AudioClip selectSound = null, AudioClip moveCursorSound = null, Action cancelAction = null, AudioClip cancelSound = null ) { // Retrieve the controller assigned to each player AbstractInputController p1InputController = UFE.GetPlayer1Controller(); AbstractInputController p2InputController = UFE.GetPlayer2Controller(); // Retrieve the values of the horizontal and vertical axis float p1HorizontalAxis = p1InputController.GetAxisRaw(p1InputController.horizontalAxis); float p1VerticalAxis = p1InputController.GetAxisRaw(p1InputController.verticalAxis); bool p1AxisDown = p1InputController.GetButtonDown(p1InputController.horizontalAxis) || p1InputController.GetButtonDown(p1InputController.verticalAxis); float p2HorizontalAxis = p2InputController.GetAxisRaw(p2InputController.horizontalAxis); float p2VerticalAxis = p2InputController.GetAxisRaw(p2InputController.verticalAxis); bool p2AxisDown = p2InputController.GetButtonDown(p2InputController.horizontalAxis) || p2InputController.GetButtonDown(p2InputController.verticalAxis); // Check if we should change the selected option if (p1AxisDown) { screen.MoveCursor(new Vector3(p1HorizontalAxis, p1VerticalAxis), moveCursorSound); } if (p1InputController.GetButtonDown(UFE.config.inputOptions.confirmButton)) { screen.SelectOption(selectSound); } else if (p1InputController.GetButtonDown(UFE.config.inputOptions.cancelButton)) { if (cancelSound != null) { UFE.PlaySound(cancelSound); } if (cancelAction != null) { cancelAction(); } } else { if (p2AxisDown) { screen.MoveCursor(new Vector3(p2HorizontalAxis, p2VerticalAxis), moveCursorSound); } if (p2InputController.GetButtonDown(UFE.config.inputOptions.confirmButton)) { screen.SelectOption(selectSound); } else if (p2InputController.GetButtonDown(UFE.config.inputOptions.cancelButton)) { if (cancelSound != null) { UFE.PlaySound(cancelSound); } if (cancelAction != null) { cancelAction(); } } } }
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); } }
protected virtual void HideScreen(UFEScreen screen) { if (screen != null){ screen.OnHide(); screen.gameObject.SetActive(false); } }
protected virtual bool IsVisible(UFEScreen screen) { return(screen != null?screen.IsVisible() : false); }
protected virtual void ShowScreen(UFEScreen screen) { if (screen != null){ screen.gameObject.SetActive(true); screen.OnShow(); } }
public static void ShowScreen(UFEScreen screen, Action nextScreenAction = null) { if (screen != null){ if (UFE.OnScreenChanged != null){ UFE.OnScreenChanged(UFE.currentScreen, screen); } UFE.currentScreen = (UFEScreen) GameObject.Instantiate(screen); UFE.currentScreen.transform.SetParent(UFE.canvas != null ? UFE.canvas.transform : null, false); StoryModeScreen storyModeScreen = UFE.currentScreen as StoryModeScreen; if (storyModeScreen != null){ storyModeScreen.nextScreenAction = nextScreenAction; } UFE.currentScreen.OnShow (); } }