/** * 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 UnityEngine; using UnityEngine.UI; using UnityEngine.Events; using System; using System.Collections; using System.Collections.Generic; using UnityEngine.EventSystems; using System.Linq; namespace Fungus { public class MenuDialog : MonoBehaviour { // Currently active Menu Dialog used to display Menu options public static MenuDialog activeMenuDialog; [Tooltip("Automatically select the first interactable button when the menu is shown.")] public bool autoSelectFirstButton = false; [NonSerialized] public Button[] cachedButtons; [NonSerialized] public Slider cachedSlider; public static MenuDialog GetMenuDialog() { if (activeMenuDialog == null) { // Use first Menu Dialog found in the scene (if any) MenuDialog md = GameObject.FindObjectOfType(); if (md != null) { activeMenuDialog = md; } if (activeMenuDialog == null) { // Auto spawn a menu dialog object from the prefab GameObject prefab = Resources.Load("MenuDialog"); if (prefab != null) { GameObject go = Instantiate(prefab) as GameObject; go.SetActive(false); go.name = "MenuDialog"; activeMenuDialog = go.GetComponent(); } } } return activeMenuDialog; } public virtual void Awake() { Button[] optionButtons = GetComponentsInChildren