diff --git a/CHANGELOG.md b/CHANGELOG.md index 403930d1..32fa2fd5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/). - `ActionsGenerator` will now generate C# warnings for non-private methods that are attributed as `YarnFunction` or `YarnCommand`. - `ActionsGenerator` still logs to a temporary location, but now into a `dev.yarnspinner.logs` folder inside the temporary location. - Auto-advancing `LineView`s will no longer attempt to advance dialogue that has been stopped. +- `DialogueAdvanceInput` now supports Virtual Button names in addition to KeyCodes and Input Actions + - this can be configured to work on button or keycode release or press. + - defaults to on release. ### Removed diff --git a/Editor/Editors/DialogueAdvanceInputEditor.cs b/Editor/Editors/DialogueAdvanceInputEditor.cs index caa63da3..e2f7de26 100644 --- a/Editor/Editors/DialogueAdvanceInputEditor.cs +++ b/Editor/Editors/DialogueAdvanceInputEditor.cs @@ -24,6 +24,8 @@ public class DialogueAdvanceInputEditor : UnityEditor.Editor private SerializedProperty dialogueViewProperty; private SerializedProperty continueActionTypeProperty; private SerializedProperty continueActionKeyCodeProperty; + private SerializedProperty continueActionButtonNameProperty; + private SerializedProperty continueActionOnButtonReleaseProperty; private SerializedProperty continueActionReferenceProperty; private SerializedProperty continueActionProperty; private SerializedProperty enableActionOnStartProperty; @@ -33,6 +35,8 @@ public void OnEnable() dialogueViewProperty = serializedObject.FindProperty(nameof(DialogueAdvanceInput.dialogueView)); continueActionTypeProperty = serializedObject.FindProperty(nameof(DialogueAdvanceInput.continueActionType)); continueActionKeyCodeProperty = serializedObject.FindProperty(nameof(DialogueAdvanceInput.continueActionKeyCode)); + continueActionButtonNameProperty = serializedObject.FindProperty(nameof(DialogueAdvanceInput.continueActionButtonName)); + continueActionOnButtonReleaseProperty = serializedObject.FindProperty(nameof(DialogueAdvanceInput.continueActionOnButtonRelease)); #if USE_INPUTSYSTEM && ENABLE_INPUT_SYSTEM continueActionReferenceProperty = serializedObject.FindProperty(nameof(DialogueAdvanceInput.continueActionReference)); @@ -56,6 +60,10 @@ public override void OnInspectorGUI() case (int)DialogueAdvanceInput.ContinueActionType.KeyCode: DrawInputActionTypeKeycode(); break; + + case (int)DialogueAdvanceInput.ContinueActionType.VirtualButton: + DrawInputActionTypeButton(); + break; case (int)DialogueAdvanceInput.ContinueActionType.InputSystemAction: DrawInputActionTypeAction(); @@ -100,11 +108,23 @@ private void DrawInputActionTypeKeycode() EditorGUI.indentLevel += 1; #if ENABLE_LEGACY_INPUT_MANAGER EditorGUILayout.PropertyField(continueActionKeyCodeProperty); + EditorGUILayout.PropertyField(continueActionOnButtonReleaseProperty); #else EditorGUILayout.HelpBox(LegacyInputSystemNotAvailableWarning, MessageType.Warning); #endif EditorGUI.indentLevel -= 1; + } + private void DrawInputActionTypeButton() + { + EditorGUI.indentLevel += 1; +#if ENABLE_LEGACY_INPUT_MANAGER + EditorGUILayout.PropertyField(continueActionButtonNameProperty); + EditorGUILayout.PropertyField(continueActionOnButtonReleaseProperty); +#else + EditorGUILayout.HelpBox(LegacyInputSystemNotAvailableWarning, MessageType.Warning); +#endif + EditorGUI.indentLevel -= 1; } private void DrawInputActionTypeNone() diff --git a/Runtime/Views/DialogueAdvanceInput.cs b/Runtime/Views/DialogueAdvanceInput.cs index c9e2012b..97f1741d 100644 --- a/Runtime/Views/DialogueAdvanceInput.cs +++ b/Runtime/Views/DialogueAdvanceInput.cs @@ -24,6 +24,21 @@ namespace Yarn.Unity /// public class DialogueAdvanceInput : MonoBehaviour { + /// + /// The button/keycode action type, should the button be fired on release or press? + /// + public enum ContinueButtonActionType + { + /// + /// Action will fire on key release + /// + Up, + /// + /// Action will fire on key pressed + /// + Down, + } + /// /// The type of input that this component is listening for in order to signal that its dialogue view should advance. /// @@ -45,6 +60,15 @@ public enum ContinueActionType /// KeyCode, + /// + /// The component is listening for a virtual button to be pressed. + /// + /// + /// This input will only be used if the legacy + /// Input Manager is enabled. + /// + VirtualButton, + /// /// The component is listening for the action configured in to be performed. @@ -97,6 +121,33 @@ public enum ContinueActionType [SerializeField] public KeyCode continueActionKeyCode = KeyCode.Space; + /// + /// The virtual button that this component is listening for. + /// + /// + /// + /// This value is only used when is + /// . + /// + /// + [SerializeField] + public string continueActionButtonName = "Jump"; + + /// + /// Should the continue action respond to key being pressed down or released. + /// + /// + /// + /// Defaults to firing the advancement on key released. + /// + /// + /// This value is only used when is + /// or . + /// + /// + [SerializeField] + public ContinueButtonActionType continueActionOnButtonRelease = ContinueButtonActionType.Up; // defaults to on release + #if USE_INPUTSYSTEM && ENABLE_INPUT_SYSTEM /// /// An that refers to the action that @@ -234,17 +285,33 @@ private void UserPerformedAdvanceAction(InputAction.CallbackContext obj) #if ENABLE_LEGACY_INPUT_MANAGER internal void Update() { - // We need to be configured to use a keycode to interrupt/continue - // lines. - if (continueActionType != ContinueActionType.KeyCode) + var advance = false; + + if (continueActionType == ContinueActionType.KeyCode) { - return; + if (this.continueActionOnButtonRelease == ContinueButtonActionType.Up) + { + advance = Input.GetKeyUp(continueActionKeyCode); + } + else + { + advance = Input.GetKeyDown(continueActionKeyCode); + } + } + else if (continueActionType == ContinueActionType.VirtualButton) + { + if (this.continueActionOnButtonRelease == ContinueButtonActionType.Up) + { + advance = Input.GetButtonUp(continueActionButtonName); + } + else + { + advance = Input.GetButtonDown(continueActionButtonName); + } } - // Has the keycode been pressed this frame? - if (Input.GetKeyUp(continueActionKeyCode)) + if (advance) { - // Indicate that we want to skip/continue. dialogueView.UserRequestedViewAdvancement(); } }