From 4b3a4bf32bde5798c2a385f37c96ff1e978447e2 Mon Sep 17 00:00:00 2001 From: Gerardo Marset Date: Mon, 27 Jun 2016 19:59:10 -0300 Subject: [PATCH] Simplify DialogInput to use Unity's InputManager. --- .../Narrative/Editor/DialogInputEditor.cs | 57 ------------------- .../Editor/DialogInputEditor.cs.meta | 12 ---- .../Narrative/Resources/SayDialog.prefab | 5 +- .../Fungus/Narrative/Scripts/DialogInput.cs | 51 +++-------------- 4 files changed, 11 insertions(+), 114 deletions(-) delete mode 100644 Assets/Fungus/Narrative/Editor/DialogInputEditor.cs delete mode 100644 Assets/Fungus/Narrative/Editor/DialogInputEditor.cs.meta diff --git a/Assets/Fungus/Narrative/Editor/DialogInputEditor.cs b/Assets/Fungus/Narrative/Editor/DialogInputEditor.cs deleted file mode 100644 index 3508c45b..00000000 --- a/Assets/Fungus/Narrative/Editor/DialogInputEditor.cs +++ /dev/null @@ -1,57 +0,0 @@ -/** - * This code is part of the Fungus library (http://fungusgames.com) maintained by Chris Gregan (http://twitter.com/gofungus). - * It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE) - */ - -using UnityEditor; -using UnityEngine; -using System.Collections; -using Rotorz.ReorderableList; -using System.Collections.Generic; - -namespace Fungus -{ - - [CustomEditor (typeof(DialogInput))] - public class DialogInputEditor : Editor - { - protected SerializedProperty clickModeProp; - protected SerializedProperty nextClickDelayProp; - protected SerializedProperty keyPressModeProp; - protected SerializedProperty shiftKeyEnabledProp; - protected SerializedProperty ignoreMenuClicksProp; - protected SerializedProperty keyListProp; - - protected virtual void OnEnable() - { - clickModeProp = serializedObject.FindProperty ("clickMode"); - nextClickDelayProp = serializedObject.FindProperty ("nextClickDelay"); - keyPressModeProp = serializedObject.FindProperty ("keyPressMode"); - shiftKeyEnabledProp = serializedObject.FindProperty ("shiftKeyEnabled"); - ignoreMenuClicksProp = serializedObject.FindProperty ("ignoreMenuClicks"); - keyListProp = serializedObject.FindProperty ("keyList"); - } - - public override void OnInspectorGUI() - { - serializedObject.Update(); - - DialogInput t = target as DialogInput; - - EditorGUILayout.PropertyField(clickModeProp); - EditorGUILayout.PropertyField(nextClickDelayProp); - EditorGUILayout.PropertyField(ignoreMenuClicksProp); - - EditorGUILayout.PropertyField(keyPressModeProp); - if (t.keyPressMode == DialogInput.KeyPressMode.KeyPressed) - { - EditorGUILayout.PropertyField(shiftKeyEnabledProp); - ReorderableListGUI.Title(new GUIContent("Key List", "Keycodes to check for user input")); - ReorderableListGUI.ListField(keyListProp); - } - - serializedObject.ApplyModifiedProperties(); - } - } - -} \ No newline at end of file diff --git a/Assets/Fungus/Narrative/Editor/DialogInputEditor.cs.meta b/Assets/Fungus/Narrative/Editor/DialogInputEditor.cs.meta deleted file mode 100644 index 3419bb5f..00000000 --- a/Assets/Fungus/Narrative/Editor/DialogInputEditor.cs.meta +++ /dev/null @@ -1,12 +0,0 @@ -fileFormatVersion: 2 -guid: 2a336080b178f4c239754dd614d6d6b4 -timeCreated: 1440156410 -licenseType: Free -MonoImporter: - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Fungus/Narrative/Resources/SayDialog.prefab b/Assets/Fungus/Narrative/Resources/SayDialog.prefab index c17c4f7f..1e9d05fe 100644 --- a/Assets/Fungus/Narrative/Resources/SayDialog.prefab +++ b/Assets/Fungus/Narrative/Resources/SayDialog.prefab @@ -416,10 +416,10 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: clickMode: 1 - keyPressMode: 2 shiftKeyEnabled: 1 nextClickDelay: 0 - keyList: 0900000020000000 + cancelEnabled: 1 + ignoreMenuClicks: 1 --- !u!114 &11486804 MonoBehaviour: m_ObjectHideFlags: 1 @@ -665,6 +665,7 @@ Canvas: m_ReceivesEvents: 1 m_OverrideSorting: 0 m_OverridePixelPerfect: 0 + m_SortingBucketNormalizedSize: 0 m_SortingLayerID: 0 m_SortingOrder: 1 m_TargetDisplay: 0 diff --git a/Assets/Fungus/Narrative/Scripts/DialogInput.cs b/Assets/Fungus/Narrative/Scripts/DialogInput.cs index c93fbc92..cdcadd75 100644 --- a/Assets/Fungus/Narrative/Scripts/DialogInput.cs +++ b/Assets/Fungus/Narrative/Scripts/DialogInput.cs @@ -24,27 +24,17 @@ namespace Fungus ClickOnButton // Click on continue button to advance } - public enum KeyPressMode - { - Disabled, // Key pressing disabled - AnyKey, // Press any key to continue - KeyPressed // Press one of specified keys to advance - } - [Tooltip("Click to advance story")] public ClickMode clickMode; - [Tooltip("Press a key to advance story")] - public KeyPressMode keyPressMode; - [Tooltip("Hold down shift while pressing a key to advance though story instantly")] public bool shiftKeyEnabled = true; [Tooltip("Delay between consecutive clicks. Useful to prevent accidentally clicking through story.")] public float nextClickDelay = 0f; - [Tooltip("Keycodes to check for key presses")] - public KeyCode[] keyList; + [Tooltip("Allow holding Cancel to fast forward text")] + public bool cancelEnabled = true; [Tooltip("Ignore input if a Menu dialog is currently active")] public bool ignoreMenuClicks = true; @@ -93,37 +83,12 @@ namespace Fungus protected virtual void Update() { - switch (keyPressMode) - { - case KeyPressMode.Disabled: - break; - case KeyPressMode.AnyKey: - if (Input.anyKeyDown) - { - SetNextLineFlag(); - } - break; - case KeyPressMode.KeyPressed: - foreach (KeyCode keyCode in keyList) - { - if (shiftKeyEnabled && - (Input.GetKey(KeyCode.LeftShift) || Input.GetKey(KeyCode.RightShift))) - { - if (Input.GetKey(keyCode)) - { - SetNextLineFlag(); - } - } - else - { - if (Input.GetKeyDown(keyCode)) - { - SetNextLineFlag(); - } - } - } - break; - } + StandaloneInputModule currentInputModule = EventSystem.current.GetComponent(); + if (Input.GetButtonDown(currentInputModule.submitButton) || + (cancelEnabled && Input.GetButton(currentInputModule.cancelButton))) + { + SetNextLineFlag(); + } switch (clickMode) {