using EasyTalk.Display;
using EasyTalk.Utils;
using UnityEngine;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
namespace EasyTalk.Display
{
///
/// This class implements the logic which handles player input controls for Dialogue Displays.
///
public class DialogueInputHandler : MonoBehaviour
{
///
/// The Dialogue Display to control.
///
[Tooltip("The Dialogue Display to control. If left unset, the input handler will attempt to retrieve a display from the GameObject on Awake.")]
[SerializeField] private AbstractDialogueDisplay dialogueDisplay;
#if ENABLE_INPUT_SYSTEM
///
/// The input action mapping used to process player input and control the dialogue display.
///
[Tooltip("The InputAction asset to use to detect player input events and control the dialogue system.")]
[SerializeField] InputActionAsset inputActions;
///
/// The name of the action which when triggered will cause the dialogue to continue forward in the currently active conversation (only applicable when displaying dialogue).
///
[Tooltip("The name of the input action which triggers the dialogue to continue playing to the next line/options.")]
[SerializeField] private string continueActionName = "Continue";
///
/// The name of the action which when triggered will select the next option (only applicable when options are being displayed).
///
[Tooltip("The name of the input action which triggers the dialogue display to select the next option whenever options are presented to the player.")]
[SerializeField] private string nextOptionActionName = "NextOption";
///
/// The name of the action which when triggered will select the previous option (only applicable when options are being displayed).
///
[Tooltip("The name of the input action which triggers the dialogue display to select the previous option whenever options are presented to the player.")]
[SerializeField] private string previousOptionActionName = "PreviousOption";
///
/// The name of the action which chooses the currently select option and signals the dialogue to continue down the path associated with
/// that option (only applicable when options are being displayed).
///
[Tooltip("The name of the input action which triggers the dialogue system to choose the currently selected option and continue playing.")]
[SerializeField] private string chooseOptionActionName = "ChooseCurrentOption";
///
/// The name of the action which triggers am exit of the currently running dialogue (only applicable if allowQuickExit is true).
///
[Tooltip("The name of the input action which exits the conversation immediately (only applicable if 'allowQuickExit' is set to true).")]
[SerializeField] private string exitConversationActionName = "ExitConversation";
///
/// The name of the action which selects an option in a certain direction along the X-axis (only applicable to directional displays when options are being presented).
///
[Tooltip("The name of the input action which triggers the selection of an option in a direction along a horizontal axis. (This is typically only used for directional option displays)")]
[SerializeField] private string selectOptionInXDirectionActionName = "SelectOptionInXDirection";
///
/// The name of the action which selects an option in a certain direction along the Y-axis (only applicable to directional displays when options are being presented).
///
[Tooltip("The name of the input action which triggers the selection of an option in a direction along a vertical axis. (This is typically only used for directional option displays)")]
[SerializeField] private string selectOptionInYDirectionActionName = "SelectOptionInYDirection";
///
/// The name of the action which will submit a player-entered string via a text input display and move on in the dialogue.
///
[Tooltip("The name of the action which will submit a player-entered string via a text input display and move on in the dialogue.")]
[SerializeField] private string playerStringSubmissionActionName = "SubmitText";
///
/// The name of the action which will move the text caret (cursor) to the right by one position when editing text in a text input display.
///
[Tooltip("The name of the action which will move the text caret (cursor) to the right by one position when editing text in a text input display.")]
[SerializeField] private string moveTextCursorRightActionName = "MoveTextCursorRight";
///
/// The name of the action which will move the text caret (cursor) to the left by one position when editing text in a text input display.
///
[Tooltip("The name of the action which will move the text caret (cursor) to the left by one position when editing text in a text input display.")]
[SerializeField] private string moveTextCursorLeftActionName = "MoveTextCursorLeft";
///
/// The name of the action which will change the current character to the next character in the input character list when editing text in a text input display.
///
[Tooltip("The name of the action which will change the current character to the next character in the input character list when editing text in a text input display.")]
[SerializeField] private string gotoNextTextCharacterActionName = "GotoNextTextCharacter";
///
/// The name of the action which will change the current character to the last character in the input character list when editing text in a text input display.
///
[Tooltip("The name of the action which will change the current character to the last character in the input character list when editing text in a text input display.")]
[SerializeField] private string gotoLastTextCharacterActionName = "GotoLastTextCharacter";
#else
///
/// The name of the input which triggers the dialogue to continue (only applicable when dialogue is being displayed).
///
[SerializeField] private string continueButtonName = "Submit";
///
/// The name of the input which triggers the dialogue to submit a player's input string (from a text input display), when applicable.
///
[Tooltip("The name of the input which triggers the dialogue to submit a player's input string (from a text input display), when applicable.")]
[SerializeField] private string playerStringSubmissionButtonName = "Submit";
///
/// The name of the input which chooses the currently selected option (only applicable when options are being presented).
///
[SerializeField] private string chooseSelectedOptionButtonName = "Submit";
///
/// The name of the input which causes the dialogue to exit (only applicable when allowQuickExit is set to true).
///
[SerializeField] private string quickExitButtonName = "Cancel";
///
/// The name of the horizontal input axis. This is used to select options when they are being shown.
///
[SerializeField] private string horizontalAxisName = "Horizontal";
///
/// The name of the horizontal input axis for the DPAD. This is used to select options when they are being shown.
///
[SerializeField] private string dpadHorizontalAxisName = "DPAD_Horizontal";
///
/// The name of the vertical input axis. This is used to select options when they are being shown.
///
[SerializeField] private string verticalAxisName = "Vertical";
///
/// The name of the vertical input axis for the DPAD. This is used to select options when they are being shown.
///
[SerializeField] private string dpadVerticalAxisName = "DPAD_Vertical";
///
/// The amount of time which must pass in order for the input axis controls to be usable again after a prior action is triggered (such as selecting an option).
///
private float axisResetTime = 0.3f;
///
/// A flag used to keep track of whether warning messages have been made when reading input so that messages aren't resent repeatedly during gameplay.
///
private bool inputWarningSent = false;
///
/// A flag indicating whether the axis controls are ready to be triggered to choose an option based on user input.
///
private bool allowAxisTrigger = false;
///
/// Keeps track of the last time an input axis was triggered.
///
private float lastAxisTriggerTime;
#endif
private void Awake()
{
SetupUtils.SetUpEventSystem();
if (dialogueDisplay == null)
{
dialogueDisplay = GetComponent();
}
#if ENABLE_INPUT_SYSTEM
SetupInputs();
#endif
}
///
/// The update loop handles user input if using the old input system.
///
private void Update()
{
#if !ENABLE_INPUT_SYSTEM //Handle inputs using the old input manager system.
HandleUserInput();
#endif
}
///
/// Disables the player input controls on the dialogue display when using the new input system.
///
private void OnDisable()
{
#if ENABLE_INPUT_SYSTEM //Disable the input actions (if using the new input system).
if (inputActions != null) { inputActions.Disable(); }
#endif
}
///
/// Enables the player input controls on the dialogue display when using the new input system.
///
private void OnEnable()
{
#if ENABLE_INPUT_SYSTEM //Enable the input actions (if using the new input system).
if (inputActions != null) { inputActions.Enable(); }
#endif
}
#if ENABLE_INPUT_SYSTEM
///
/// Sets up each input action to call the approrate dialogue control methods when those inputs are actvated by the player.
///
protected void SetupInputs()
{
//Add actions to handle user input using the new input system.
if (inputActions != null)
{
SetUpContinueAction();
SetUpNextOptionAction();
SetUpPreviousOptionAction();
SetUpChooseOptionAction();
SetUpExitConversationAction();
SetUpSelectOptionInXDirectionAction();
SetUpSelectOptionInYDirectionAction();
SetUpPlayerStringAction();
SetUpMoveTextCursorRightAction();
SetUpMoveTextCursorLeftAction();
SetUpGotoNextCharacterAction();
SetUpGotoLastCharacterAction();
}
}
///
/// Sets up the input action for selecting an option along the vertical axis direction.
///
private void SetUpSelectOptionInYDirectionAction()
{
InputAction selectOptionInYDirectionAction = inputActions.FindAction(selectOptionInYDirectionActionName);
if (selectOptionInYDirectionAction != null)
{
selectOptionInYDirectionAction.performed += delegate
{
if (dialogueDisplay.IsOptionSelectionAllowed)
{
SelectOptionFromInputDirection();
}
};
}
}
///
/// Sets up the input action for selecting an option along the horizontal axis direction.
///
private void SetUpSelectOptionInXDirectionAction()
{
InputAction selectOptionInXDirectionAction = inputActions.FindAction(selectOptionInXDirectionActionName);
if (selectOptionInXDirectionAction != null)
{
selectOptionInXDirectionAction.performed += delegate
{
if (dialogueDisplay.IsOptionSelectionAllowed)
{
SelectOptionFromInputDirection();
}
};
}
}
///
/// Sets up the input action for exiting the dialogue conversation.
///
private void SetUpExitConversationAction()
{
InputAction exitConversationAction = inputActions.FindAction(exitConversationActionName);
if (exitConversationAction != null)
{
exitConversationAction.performed += delegate
{
if (dialogueDisplay.IsQuickExitAllowed)
{
dialogueDisplay.DisableOptionSelection();
dialogueDisplay.DisableContinue();
dialogueDisplay.ExitDialogue();
}
};
}
}
///
/// Sets up the input action for finalizing and choosing the currently selected option.
///
private void SetUpChooseOptionAction()
{
InputAction chooseOptionAction = inputActions.FindAction(chooseOptionActionName);
if (chooseOptionAction != null)
{
chooseOptionAction.performed += delegate
{
if (!dialogueDisplay.IsCurrentlyInConversation && !dialogueDisplay.GetOptionDisplay().IsHidden && dialogueDisplay.IsOptionSelectionAllowed)
{
dialogueDisplay.ChooseSelectedOption();
}
};
}
}
///
/// Sets up the input action for selecting the previous option.
///
private void SetUpPreviousOptionAction()
{
InputAction previousOptionAction = inputActions.FindAction(previousOptionActionName);
if (previousOptionAction != null)
{
previousOptionAction.performed += delegate
{
if (!dialogueDisplay.IsCurrentlyInConversation && !dialogueDisplay.GetOptionDisplay().IsHidden && dialogueDisplay.IsOptionSelectionAllowed)
{
dialogueDisplay.SelectPreviousOption();
}
};
}
}
///
/// Sets up the input action for selecting the next option.
///
private void SetUpNextOptionAction()
{
InputAction nextOptionAction = inputActions.FindAction(nextOptionActionName);
if (nextOptionAction != null)
{
nextOptionAction.performed += delegate
{
if (!dialogueDisplay.IsCurrentlyInConversation && !dialogueDisplay.GetOptionDisplay().IsHidden && dialogueDisplay.IsOptionSelectionAllowed)
{
dialogueDisplay.SelectNextOption();
}
};
}
}
///
/// Sets up the input action for continuing to the next part of the conversation when the player hits the continue button.
///
private void SetUpContinueAction()
{
InputAction continueAction = inputActions.FindAction(continueActionName);
if (continueAction != null)
{
continueAction.performed += delegate
{
if (dialogueDisplay.IsCurrentlyInConversation && dialogueDisplay.IsContinueAllowed)
{
dialogueDisplay.Continue();
}
};
}
}
///
/// Sets up the input action for submitting a player's string into a text input display.
///
private void SetUpPlayerStringAction()
{
InputAction playerStringAction = inputActions.FindAction(playerStringSubmissionActionName);
if (playerStringAction != null)
{
playerStringAction.performed += delegate
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
inputDisplay.TextInputEntered();
}
};
}
}
///
/// Sets up the input action for moving the text input caret to the right by one character.
///
private void SetUpMoveTextCursorRightAction()
{
InputAction moveCursorRightAction = inputActions.FindAction(moveTextCursorRightActionName);
if (moveCursorRightAction != null)
{
moveCursorRightAction.performed += delegate
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
inputDisplay.MoveCursorRight();
}
};
}
}
///
/// Sets up the input action for moving the text input caret to the left by one character.
///
private void SetUpMoveTextCursorLeftAction()
{
InputAction moveCursorLeftAction = inputActions.FindAction(moveTextCursorLeftActionName);
if (moveCursorLeftAction != null)
{
moveCursorLeftAction.performed += delegate
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
inputDisplay.MoveCursorLeft();
}
};
}
}
///
/// Sets up the input action to change the character at the current caret/cursor location in a text display to whatever the next character is.
///
private void SetUpGotoNextCharacterAction()
{
InputAction gotoNextCharacterAction = inputActions.FindAction(gotoNextTextCharacterActionName);
if (gotoNextCharacterAction != null)
{
gotoNextCharacterAction.performed += context =>
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
if (context.interaction is UnityEngine.InputSystem.Interactions.HoldInteraction)
{
inputDisplay.CycleNextCharacters();
}
else
{
inputDisplay.NextCharacter();
}
}
};
gotoNextCharacterAction.canceled += delegate
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
inputDisplay.StopCharacterCycling();
}
};
}
}
///
/// Sets up the input action to change the character at the current caret/cursor location in a text display to whatever the previous character is.
///
private void SetUpGotoLastCharacterAction()
{
InputAction gotoLastCharacterAction = inputActions.FindAction(gotoLastTextCharacterActionName);
if (gotoLastCharacterAction != null)
{
gotoLastCharacterAction.performed += context =>
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
if (context.interaction is UnityEngine.InputSystem.Interactions.HoldInteraction)
{
inputDisplay.CycleLastCharacters();
}
else
{
inputDisplay.LastCharacter();
}
}
};
gotoLastCharacterAction.canceled += delegate
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
inputDisplay.StopCharacterCycling();
}
};
}
}
#endif
///
/// Checks the value of the x and y axis inputs and attempts to select the option in the corresponding direction.
///
/// Returns true if an option was selected; false otherwise.
private bool SelectOptionFromInputDirection()
{
#if ENABLE_INPUT_SYSTEM
float xValue = inputActions[selectOptionInXDirectionActionName].ReadValue();
float yValue = inputActions[selectOptionInYDirectionActionName].ReadValue();
#else
float xValue = Input.GetAxis(horizontalAxisName);
float yValue = Input.GetAxis(verticalAxisName);
#endif
Vector2 direction = new Vector2(xValue, yValue);
if (!dialogueDisplay.IsCurrentlyInConversation && !dialogueDisplay.GetOptionDisplay().IsHidden && direction.magnitude > 0.5f)
{
return dialogueDisplay.SelectOptionInDirection(direction.normalized);
}
return false;
}
#if !ENABLE_INPUT_SYSTEM //Handle user input controls (uses the old input manager).
///
/// Handles user input controls when using the old input system.
///
private void HandleUserInput()
{
if (dialogueDisplay.CurrentController != null)
{
HandleContinueButton();
HandleChooseOption();
HandleExitConversation();
float horizontal = GetHorizontalAxisValue();
float vertical = GetVerticalAxisValue();
float dpadHorizontal = GetDPadHorizontalValue();
float dpadVertical = GetDPadVerticalValue();
float axisActivationThreshold = 0.2f;
if (Mathf.Abs(dpadHorizontal) > Mathf.Abs(horizontal)) { horizontal = dpadHorizontal; }
if (Mathf.Abs(dpadVertical) > Mathf.Abs(vertical)) { vertical = dpadVertical; }
CheckToAllowAxisTriggering(horizontal, vertical, axisActivationThreshold);
HandleSelectNextOption(horizontal, vertical, axisActivationThreshold);
HandleSelectPreviousOption(horizontal, vertical, axisActivationThreshold);
HandleSelectOptionInDirection(horizontal, vertical, axisActivationThreshold);
HandleMoveTextCursor(dpadHorizontal);
HandleChangeTextCharacter(dpadVertical);
HandlePlayerTextSubmission();
}
}
///
/// Sets the allowAxisTrigger flag to true if enough time has passed or if the horizontal and vertical axis inputs have moved back down below the activation threshold.
///
/// The horizontal axis input value.
/// The vertical axis input value.
/// The threshold value which the horizontal or vertical axis values must be below in order for allowAxisTrigger to be set to true (unless enough time has elapsed).
private void CheckToAllowAxisTriggering(float horizontal, float vertical, float axisActivationThreshold)
{
if ((horizontal < axisActivationThreshold && horizontal > -axisActivationThreshold) &&
(vertical < axisActivationThreshold && vertical > -axisActivationThreshold))
{
allowAxisTrigger = true;
}
else if ((Time.time - lastAxisTriggerTime > axisResetTime))
{
allowAxisTrigger = true;
}
}
///
/// When options are being presented to the player, this method attempts to select the option which corresponds to the current input axis direction (horizontal + vertical)
/// if the axis control is allowed to be triggered.
///
/// The horizontal axis input value.
/// The vertical axis input value.
/// The threshold value which the horizontal or vertical axis values must exceed in order for the action to be triggered.
private void HandleSelectOptionInDirection(float horizontal, float vertical, float axisActivationThreshold)
{
if ((Mathf.Abs(horizontal) > axisActivationThreshold || Mathf.Abs(vertical) > axisActivationThreshold) && allowAxisTrigger)
{
if (dialogueDisplay.IsOptionSelectionAllowed)
{
lastAxisTriggerTime = Time.time;
allowAxisTrigger = !SelectOptionFromInputDirection();
}
}
}
///
/// If 'allowQuickExit' is set to true, this method attempts to exit the dialogue conversation immediately whenever the input button mapped to 'quickExitButtonName' is pressed.
///
private void HandleExitConversation()
{
try
{
if (Input.GetButtonDown(quickExitButtonName))
{
if (dialogueDisplay.IsQuickExitAllowed)
{
dialogueDisplay.DisableOptionSelection();
dialogueDisplay.DisableContinue();
dialogueDisplay.ExitDialogue();
}
}
}
catch
{
if (!inputWarningSent)
{
Debug.LogWarning("Encountered an error when attempting to read input for the 'quick exit' button. Make sure there is a button configured in the Input Manager named '" + quickExitButtonName + "'");
}
inputWarningSent = true;
}
}
///
/// When presenting options, this method attempts to finalize and choose the currently selected option whenever the input button mapped to 'chooseSelectedOptionButtonName' is pressed.
///
private void HandleChooseOption()
{
try
{
if (Input.GetButtonDown(chooseSelectedOptionButtonName))
{
if (!dialogueDisplay.IsCurrentlyInConversation && !dialogueDisplay.GetOptionDisplay().IsHidden && dialogueDisplay.IsOptionSelectionAllowed)
{
dialogueDisplay.ChooseSelectedOption();
}
}
}
catch
{
if (!inputWarningSent)
{
Debug.LogWarning("Encountered an error when attempting to read input for the 'choose option' button. Make sure there is a button configured in the Input Manager named '" + chooseSelectedOptionButtonName + "'");
}
inputWarningSent = true;
}
}
///
/// When options are being presented to the player, this method attempts to select the previous option if the player is pressing the axis controls
/// in the configured direction and the control is allowed to be triggered.
///
/// The horizontal axis input value.
/// The vertical axis input value.
/// The threshold value which the horizontal or vertical axis values must exceed in order for the action to be triggered.
private void HandleSelectPreviousOption(float horizontal, float vertical, float axisActivationThreshold)
{
if ((horizontal < -axisActivationThreshold || vertical > axisActivationThreshold) && allowAxisTrigger)
{
if (!dialogueDisplay.IsCurrentlyInConversation && !dialogueDisplay.GetOptionDisplay().IsHidden && dialogueDisplay.IsOptionSelectionAllowed)
{
lastAxisTriggerTime = Time.time;
allowAxisTrigger = !dialogueDisplay.SelectPreviousOption();
}
}
}
///
/// When options are being presented to the player, this method attempts to select the next option if the player is pressing the axis controls
/// in the configured direction and the control is allowed to be triggered.
///
/// The horizontal axis input value.
/// The vertical axis input value.
/// The threshold value which the horizontal or vertical axis values must exceed in order for the action to be triggered.
private void HandleSelectNextOption(float horizontal, float vertical, float axisActivationThreshold)
{
if ((horizontal > axisActivationThreshold || vertical < -axisActivationThreshold) && allowAxisTrigger)
{
if (!dialogueDisplay.IsCurrentlyInConversation && !dialogueDisplay.GetOptionDisplay().IsHidden && dialogueDisplay.IsOptionSelectionAllowed)
{
lastAxisTriggerTime = Time.time;
allowAxisTrigger = !dialogueDisplay.SelectNextOption();
}
}
}
///
/// Retrieves the vertical axis value from the player's input controls (uses the axis mapped to 'dpadVerticalAxisName'). This is intended for DPAD input, but can be used for any alternative axis.
///
/// The vertical axis value. If there is no axis configured with the proper name, this method returns 0.
private float GetDPadVerticalValue()
{
try
{
float dpadVertical = Input.GetAxis(dpadVerticalAxisName);
return dpadVertical;
}
catch
{
if (!inputWarningSent)
{
Debug.LogWarning("Encountered an error when attempting to read input for D-Pad vertical axis. Make sure there is an axis configured in the Input Manager named '" + dpadVerticalAxisName + "'");
}
inputWarningSent = true;
}
return 0.0f;
}
///
/// Retrieves the horizontal axis value from the player's input controls (uses the axis mapped to 'dpadHorizontalAxisName'). This is intended for DPAD input, but can be used for any alternative axis.
///
/// The horizontal axis value. If there is no axis configured with the proper name, this method returns 0.
private float GetDPadHorizontalValue()
{
try
{
float dpadHorizontal = Input.GetAxis(dpadHorizontalAxisName);
return dpadHorizontal;
}
catch
{
if (!inputWarningSent)
{
Debug.LogWarning("Encountered an error when attempting to read input for D-Pad horizontal axis. Make sure there is an axis configured in the Input Manager named '" + dpadHorizontalAxisName + "'");
}
inputWarningSent = true;
}
return 0.0f;
}
///
/// Retrieves the vertical axis value from the player's input controls (uses the axis mapped to 'verticalAxisName').
///
/// The vertical axis value. If there is no axis configured with the proper name, this method returns 0.
private float GetVerticalAxisValue()
{
try
{
float vertical = Input.GetAxis(verticalAxisName);
return vertical;
}
catch
{
if (!inputWarningSent)
{
Debug.LogWarning("Encountered an error when attempting to read input for the vertical axis. Make sure there is an axis configured in the Input Manager named '" + verticalAxisName + "'");
}
inputWarningSent = true;
}
return 0.0f;
}
///
/// Retrieves the horizontal axis value from the player's input controls (uses the axis mapped to 'horizontalAxisName').
///
/// The horizontal axis value. If there is no axis configured with the proper name, this method returns 0.
private float GetHorizontalAxisValue()
{
try
{
float horizontal = Input.GetAxis(horizontalAxisName);
return horizontal;
}
catch
{
if (!inputWarningSent)
{
Debug.LogWarning("Encountered an error when attempting to read input for the horizontal axis. Make sure there is an axis configured in the Input Manager named '" + horizontalAxisName + "'");
}
inputWarningSent = true;
}
return 0.0f;
}
///
/// Checks to see if the player pressed the continue button. If they did and continuation is allowed, continues to the next part of the conversation.
///
private void HandleContinueButton()
{
try
{
if (Input.GetButtonDown(continueButtonName))
{
if (dialogueDisplay.IsCurrentlyInConversation && dialogueDisplay.IsContinueAllowed)
{
dialogueDisplay.Continue();
}
}
}
catch
{
if (!inputWarningSent)
{
Debug.LogWarning("Encountered an error when attempting to read input for continue button. Make sure there is a button configured in the Input Manager named '" + continueButtonName + "'");
}
inputWarningSent = true;
}
}
///
/// Checks to see if the player has pressed the button to submit text, and submits the player generated text, if applicable.
///
private void HandlePlayerTextSubmission()
{
if (Input.GetButtonDown(playerStringSubmissionButtonName))
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
inputDisplay.TextInputEntered();
}
}
}
///
/// Checks to see if the player pressed a button to change the caret (cursor) position to edit the text on a text input display.
///
private void HandleMoveTextCursor(float dpadHorizontal)
{
if(Mathf.Abs(dpadHorizontal) > 0.0f)
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
if(dpadHorizontal > 0.0f)
{
inputDisplay.MoveCursorRight();
}
else
{
inputDisplay.MoveCursorLeft();
}
}
}
}
///
/// Checks to see if the player pressed a button to change the text input character being input into a text display.
///
private void HandleChangeTextCharacter(float dpadVertical)
{
if(Mathf.Abs(dpadVertical) > 0.0f)
{
TextInputDisplay inputDisplay = dialogueDisplay.GetTextInputDisplay();
if (inputDisplay != null && inputDisplay.isActiveAndEnabled)
{
if(dpadVertical > 0.0f)
{
inputDisplay.NextCharacter();
}
else
{
inputDisplay.LastCharacter();
}
}
}
}
#endif
}
}