Tanoda
Menu.cs
Go to the documentation of this file.
1
4
5
7{
8 public abstract class Menu<T> : Menu where T : Menu<T>
9 {
10 public static T Instance { get; private set; }
11
12
13 protected virtual void Awake()
14 {
15 Instance = (T)this;
16 }
17
18 protected virtual void OnDestroy()
19 {
20 Instance = null;
21 }
22
23 protected static void Open()
24 {
25 GameObject clonedGameObject = null;
26 if (Instance == null)
27 {
28 MenuManager.Instance.CreateInstance(typeof(T).Name, out clonedGameObject);
29 MenuManager.Instance.OpenMenu(clonedGameObject.GetMenu());
30 }
31 else
32 {
33 Instance.gameObject.SetActive(true);
35 }
36 }
37
38 protected static void Close()
39 {
40 if (Instance == null)
41 {
42 Debug.LogErrorFormat("Trying to close menu {0} but Instance is null", typeof(T));
43 return;
44 }
45
47 }
48
49 public override void OnBackPressed()
50 {
51 Close();
52 }
53 }
54
55 public abstract class Menu : MonoBehaviour
56 {
57 [Tooltip("Destroy the Game Object when menu is closed (reduces memory usage)")]
58 public bool DestroyWhenClosed = true;
59
60 [Tooltip("Disable menus that are under this one in the stack")]
61 public bool DisableMenusUnderneath = true;
62
63 public abstract void OnBackPressed();
64 }
65}
UnityEngine.Debug Debug
Definition: TanodaServer.cs:19
virtual void OnDestroy()
Definition: Menu.cs:18
static void Open()
Definition: Menu.cs:23
virtual void Awake()
Definition: Menu.cs:13
override void OnBackPressed()
Definition: Menu.cs:49
static void Close()
Definition: Menu.cs:38
GameObject CreateInstance(string MenuName)
Definition: MenuManager.cs:56
void OpenMenu(Menu menuInstance)
Definition: MenuManager.cs:70
Credit Erdener Gonenc - @PixelEnvision.