Browse Source

Spawn Event System from Flowchart instead of Menu command

Event System is now required by dialog click input
master
chrisgregan 9 years ago
parent
commit
e27753a668
  1. 38
      Assets/Fungus/Flowchart/Scripts/Flowchart.cs
  2. 36
      Assets/Fungus/Narrative/Scripts/Commands/Menu.cs

38
Assets/Fungus/Flowchart/Scripts/Flowchart.cs

@ -1,4 +1,5 @@
using UnityEngine; using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.Serialization; using UnityEngine.Serialization;
using System; using System;
using System.Linq; using System.Linq;
@ -128,6 +129,8 @@ namespace Fungus
*/ */
public static List<Flowchart> cachedFlowcharts = new List<Flowchart>(); public static List<Flowchart> cachedFlowcharts = new List<Flowchart>();
protected static bool eventSystemPresent;
/** /**
* Returns the next id to assign to a new flowchart item. * Returns the next id to assign to a new flowchart item.
* Item ids increase monotically so they are guaranteed to * Item ids increase monotically so they are guaranteed to
@ -150,6 +153,41 @@ namespace Fungus
return maxId + 1; 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<EventSystem>();
if (eventSystem == null)
{
// Auto spawn an Event System from the prefab
GameObject prefab = Resources.Load<GameObject>("EventSystem");
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
go.name = "EventSystem";
}
}
eventSystemPresent = true;
}
public virtual void OnEnable() public virtual void OnEnable()
{ {
if (!cachedFlowcharts.Contains(this)) if (!cachedFlowcharts.Contains(this))

36
Assets/Fungus/Narrative/Scripts/Commands/Menu.cs

@ -1,6 +1,5 @@
using UnityEngine; using UnityEngine;
using UnityEngine.Serialization; using UnityEngine.Serialization;
using UnityEngine.EventSystems;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Generic; 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.")] [Tooltip("A custom Menu Dialog to use to display this menu. All subsequent Menu commands will use this dialog.")]
public MenuDialog setMenuDialog; public MenuDialog setMenuDialog;
protected static bool eventSystemPresent;
public override void OnEnter() public override void OnEnter()
{ {
CheckEventSystem();
if (setMenuDialog != null) if (setMenuDialog != null)
{ {
// Override the active menu dialog // Override the active menu dialog
@ -60,37 +55,6 @@ namespace Fungus
Continue(); 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<EventSystem>();
if (eventSystem == null)
{
// Auto spawn an Event System from the prefab
GameObject prefab = Resources.Load<GameObject>("EventSystem");
if (prefab != null)
{
GameObject go = Instantiate(prefab) as GameObject;
go.name = "EventSystem";
}
}
eventSystemPresent = true;
}
public override void GetConnectedBlocks(ref List<Block> connectedBlocks) public override void GetConnectedBlocks(ref List<Block> connectedBlocks)
{ {
if (targetBlock != null) if (targetBlock != null)

Loading…
Cancel
Save