-
Notifications
You must be signed in to change notification settings - Fork 46
Expand file tree
/
Copy pathMenu.cs
More file actions
59 lines (46 loc) · 1.2 KB
/
Menu.cs
File metadata and controls
59 lines (46 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
using UnityEngine;
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<T>();
else
Instance.gameObject.SetActive(true);
MenuManager.Instance.OpenMenu(Instance, Instance.animInTime);
}
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, Instance.animOutTime);
}
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;
[Tooltip("Time to animate this menu in")]
public float animInTime = 0f;
[Tooltip("Time to animate this menu out")]
public float animOutTime = 0f;
public abstract void OnBackPressed();
}