diff --git a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs index 900d1b98..e0359574 100644 --- a/Assets/Fungus/Flowchart/Scripts/Flowchart.cs +++ b/Assets/Fungus/Flowchart/Scripts/Flowchart.cs @@ -1,4 +1,5 @@ using UnityEngine; +using UnityEngine.EventSystems; using UnityEngine.Serialization; using System; using System.Linq; @@ -128,6 +129,8 @@ namespace Fungus */ public static List cachedFlowcharts = new List(); + protected static bool eventSystemPresent; + /** * Returns the next id to assign to a new flowchart item. * Item ids increase monotically so they are guaranteed to @@ -150,6 +153,41 @@ namespace Fungus return maxId + 1; } + protected virtual void OnLevelWasLoaded(int level) + { + // Reset the flag for checking for an event system as there may not be one in the newly loaded scene. + eventSystemPresent = false; + } + + protected virtual void Start() + { + CheckEventSystem(); + } + + // There must be an Event System in the scene for Say and Menu input to work. + // This method will automatically instantiate one if none exists. + protected virtual void CheckEventSystem() + { + if (eventSystemPresent) + { + return; + } + + EventSystem eventSystem = GameObject.FindObjectOfType(); + if (eventSystem == null) + { + // Auto spawn an Event System from the prefab + GameObject prefab = Resources.Load("EventSystem"); + if (prefab != null) + { + GameObject go = Instantiate(prefab) as GameObject; + go.name = "EventSystem"; + } + } + + eventSystemPresent = true; + } + public virtual void OnEnable() { if (!cachedFlowcharts.Contains(this)) diff --git a/Assets/Fungus/Narrative/Scripts/Commands/Menu.cs b/Assets/Fungus/Narrative/Scripts/Commands/Menu.cs index 6d0f2f36..d464a493 100644 --- a/Assets/Fungus/Narrative/Scripts/Commands/Menu.cs +++ b/Assets/Fungus/Narrative/Scripts/Commands/Menu.cs @@ -1,6 +1,5 @@ using UnityEngine; using UnityEngine.Serialization; -using UnityEngine.EventSystems; using System; using System.Collections; using System.Collections.Generic; @@ -32,12 +31,8 @@ namespace Fungus [Tooltip("A custom Menu Dialog to use to display this menu. All subsequent Menu commands will use this dialog.")] public MenuDialog setMenuDialog; - protected static bool eventSystemPresent; - public override void OnEnter() { - CheckEventSystem(); - if (setMenuDialog != null) { // Override the active menu dialog @@ -60,37 +55,6 @@ namespace Fungus Continue(); } - void OnLevelWasLoaded(int level) - { - // Reset the flag for checking for an event system as there may not be one - // in the newly loaded scene. - eventSystemPresent = false; - } - - // There must be an Event System in the scene for Menu input to work. - // This function will automatically instantiate one if none exists. - protected virtual void CheckEventSystem() - { - if (eventSystemPresent) - { - return; - } - - EventSystem eventSystem = GameObject.FindObjectOfType(); - if (eventSystem == null) - { - // Auto spawn an Event System from the prefab - GameObject prefab = Resources.Load("EventSystem"); - if (prefab != null) - { - GameObject go = Instantiate(prefab) as GameObject; - go.name = "EventSystem"; - } - } - - eventSystemPresent = true; - } - public override void GetConnectedBlocks(ref List connectedBlocks) { if (targetBlock != null)