using UnityEngine; using System.Collections.Generic; namespace DuloGames.UI { public class UIModalBoxManager : ScriptableObject { #region singleton private static UIModalBoxManager m_Instance; public static UIModalBoxManager Instance { get { if (m_Instance == null) m_Instance = Resources.Load("ModalBoxManager") as UIModalBoxManager; return m_Instance; } } #endregion [SerializeField] private GameObject m_ModalBoxPrefab; private List m_ActiveBoxes = new List(); /// /// Gets the modal box prefab. /// public GameObject prefab { get { return this.m_ModalBoxPrefab; } } /// /// Gets an array of the currently active modal boxes. /// public UIModalBox[] activeBoxes { get { // Do a cleanup this.m_ActiveBoxes.RemoveAll(item => item == null); return this.m_ActiveBoxes.ToArray(); } } /// /// Creates a modal box. /// /// Relative game object used to find the canvas. public UIModalBox Create(GameObject rel) { if (this.m_ModalBoxPrefab == null || rel == null) return null; Canvas canvas = UIUtility.FindInParents(rel); if (canvas != null) { GameObject obj = Instantiate(this.m_ModalBoxPrefab, canvas.transform, false); return obj.GetComponent(); } return null; } /// /// Register a box as active (Used internally). /// /// public void RegisterActiveBox(UIModalBox box) { if (!this.m_ActiveBoxes.Contains(box)) this.m_ActiveBoxes.Add(box); } /// /// Unregister an active box (Used internally). /// /// public void UnregisterActiveBox(UIModalBox box) { if (this.m_ActiveBoxes.Contains(box)) this.m_ActiveBoxes.Remove(box); } } }