Browse Source

Fixed using say in lua doesn't automatically spawn an EventSystem #571

master
Christopher 8 years ago
parent
commit
211b197f77
  1. 30
      Assets/Fungus/Scripts/Components/DialogInput.cs
  2. 2
      Assets/Fungus/Scripts/Components/Flowchart.cs
  3. 19
      Assets/Fungus/Scripts/Components/MenuDialog.cs

30
Assets/Fungus/Scripts/Components/DialogInput.cs

@ -51,8 +51,27 @@ namespace Fungus
protected virtual void Awake()
{
writer = GetComponent<Writer>();
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()
{
EventSystem eventSystem = GameObject.FindObjectOfType<EventSystem>();
if (eventSystem == null)
{
// Auto spawn an Event System from the prefab
GameObject prefab = Resources.Load<GameObject>("Prefabs/EventSystem");
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
go.name = "EventSystem";
}
}
}
protected virtual void Update()
{
if (EventSystem.current == null)
@ -62,17 +81,6 @@ namespace Fungus
if (currentStandaloneInputModule == null)
{
if (EventSystem.current == null)
{
// Auto spawn an Event System from the prefab
GameObject prefab = Resources.Load<GameObject>("Prefabs/EventSystem");
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
go.name = "EventSystem";
}
}
currentStandaloneInputModule = EventSystem.current.GetComponent<StandaloneInputModule>();
}

2
Assets/Fungus/Scripts/Components/Flowchart.cs

@ -89,6 +89,8 @@ namespace Fungus
#if UNITY_5_4_OR_NEWER
protected virtual void Awake()
{
CheckEventSystem();
UnityEngine.SceneManagement.SceneManager.activeSceneChanged += (A, B) => {
LevelWasLoaded();
};

19
Assets/Fungus/Scripts/Components/MenuDialog.cs

@ -35,6 +35,25 @@ namespace Fungus
// Don't auto disable buttons in the editor
Clear();
}
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()
{
EventSystem eventSystem = GameObject.FindObjectOfType<EventSystem>();
if (eventSystem == null)
{
// Auto spawn an Event System from the prefab
GameObject prefab = Resources.Load<GameObject>("Prefabs/EventSystem");
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
go.name = "EventSystem";
}
}
}
protected virtual void OnEnable()

Loading…
Cancel
Save