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