-
Notifications
You must be signed in to change notification settings - Fork 0
/
Menu.cs
104 lines (85 loc) · 2.56 KB
/
Menu.cs
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
using System.Reflection;
using UnityEngine;
namespace abMenuSystem
{
public abstract class Menu : MonoBehaviour
{
public const string MENU_EVENT_SHOWN = "MenuEvent.Shown";
public const string MENU_EVENT_HIDDEN = "MenuEvent.Hidden";
public abstract class MenuAnimatorBase
{
public abstract void AnimateShowing(System.Action endCallback);
public abstract void AnimateHiding(System.Action endCallback);
protected virtual void OnMenuAttached() { }
protected Menu GetMenu() { return _menu; }
void AttachMenu(Menu menu)
{
_menu = menu;
OnMenuAttached();
}
Menu _menu = null;
}
public delegate void OnEventCallback(string eventId, Menu menu);
public event OnEventCallback MenuChangeEvent;
public virtual void Show()
{
Active = true;
if (_transitionAnimator != null)
{
_transitionAnimator.AnimateShowing(OnShowFinished);
}
else
{
OnShowFinished();
}
}
public virtual void Hide()
{
if (_transitionAnimator != null)
{
_transitionAnimator.AnimateHiding(OnHideFinished);
}
else
{
OnHideFinished();
}
}
public void AttachAnimator<T>() where T : MenuAnimatorBase, new()
{
_transitionAnimator = new T();
if (_transitionAnimator != null)
{
var privateAttachMenuMethod = typeof(MenuAnimatorBase).GetMethod("AttachMenu", BindingFlags.NonPublic | BindingFlags.Instance);
if (privateAttachMenuMethod != null)
{
privateAttachMenuMethod.Invoke(_transitionAnimator, new object[] { this });
}
}
}
public bool Active
{
get
{
return gameObject.activeInHierarchy;
}
set
{
gameObject.SetActive(value);
}
}
protected void Notify(string evId)
{
MenuChangeEvent?.Invoke(evId, this);
}
void OnShowFinished()
{
Notify(MENU_EVENT_SHOWN);
}
void OnHideFinished()
{
Notify(MENU_EVENT_HIDDEN);
Active = false;
}
MenuAnimatorBase _transitionAnimator = null;
}
}