Browse Source

Merge pull request #507 from ideka/master

Simplify DialogInput to use Unity's InputManager
master
Chris Gregan 8 years ago committed by GitHub
parent
commit
1b9feb16db
  1. 57
      Assets/Fungus/Narrative/Editor/DialogInputEditor.cs
  2. 12
      Assets/Fungus/Narrative/Editor/DialogInputEditor.cs.meta
  3. 5
      Assets/Fungus/Narrative/Resources/SayDialog.prefab
  4. 58
      Assets/Fungus/Narrative/Scripts/DialogInput.cs

57
Assets/Fungus/Narrative/Editor/DialogInputEditor.cs

@ -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();
}
}
}

12
Assets/Fungus/Narrative/Editor/DialogInputEditor.cs.meta

@ -1,12 +0,0 @@
fileFormatVersion: 2
guid: 2a336080b178f4c239754dd614d6d6b4
timeCreated: 1440156410
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:

5
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

58
Assets/Fungus/Narrative/Scripts/DialogInput.cs

@ -24,27 +24,14 @@ 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;
@ -55,6 +42,8 @@ namespace Fungus
protected float ignoreClickTimer;
protected StandaloneInputModule currentStandaloneInputModule;
/**
* Trigger next line input event from script.
*/
@ -93,37 +82,14 @@ 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;
}
if (currentStandaloneInputModule == null)
currentStandaloneInputModule = EventSystem.current.GetComponent<StandaloneInputModule>();
if (Input.GetButtonDown(currentStandaloneInputModule.submitButton) ||
(cancelEnabled && Input.GetButton(currentStandaloneInputModule.cancelButton)))
{
SetNextLineFlag();
}
switch (clickMode)
{

Loading…
Cancel
Save