com.unity.uiextensions/Scripts/MenuSystem/Menu.cs

61 lines
1.7 KiB
C#
Raw Normal View History

/// Credit BinaryX
/// Sourced from - http://forum.unity3d.com/threads/scripts-useful-4-6-scripts-collection.264161/page-2#post-1945602
/// Updated by ddreaper - removed dependency on a custom ScrollRect script. Now implements drag interfaces and standard Scroll Rect.
using UnityEngine.EventSystems;
namespace UnityEngine.UI.Extensions
{
public abstract class Menu<T> : Menu where T : Menu<T>
{
public static T Instance { get; private set; }
protected virtual void Awake()
{
Instance = (T)this;
}
protected virtual void OnDestroy()
{
Instance = null;
}
protected static void Open()
{
if (Instance == null)
MenuManager.Instance.CreateInstance(typeof(T).Name);
//MenuManager.Instance.CreateInstance<T>();
else
Instance.gameObject.SetActive(true);
MenuManager.Instance.OpenMenu(Instance);
}
protected static void Close()
{
if (Instance == null)
{
Debug.LogErrorFormat("Trying to close menu {0} but Instance is null", typeof(T));
return;
}
MenuManager.Instance.CloseMenu(Instance);
}
public override void OnBackPressed()
{
Close();
}
}
public abstract class Menu : MonoBehaviour
{
[Tooltip("Destroy the Game Object when menu is closed (reduces memory usage)")]
public bool DestroyWhenClosed = true;
[Tooltip("Disable menus that are under this one in the stack")]
public bool DisableMenusUnderneath = true;
public abstract void OnBackPressed();
}
}