-
Notifications
You must be signed in to change notification settings - Fork 0
/
MenuAnimationEventManager.cs
77 lines (62 loc) · 1.44 KB
/
MenuAnimationEventManager.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
using System.Collections;
using System.Collections.Generic;
using GameArchiteture.Events;
using UIFramework;
using UnityEngine;
using UnityEngine.Serialization;
[RequireComponent(typeof(Menu))]
public class MenuAnimationEventManager : GameEventListenerBase, IMenuComponent
{
[EditScriptable]
public GameEvent OnEnter, OnEntered;
[EditScriptable]
public GameEvent OnLeave, OnLeft;
public bool DisableOnEnter;
private Menu _menu;
private void Awake()
{
Ini();
}
public bool Initialize { get; set; }
public void Ini()
{
if(Initialize) return;
Initialize = true;
_menu = GetComponent<Menu>();
if(DisableOnEnter)
_menu.onEnter.AddListener(() => _menu.SetActiveGO(false));
if (OnEntered)
{
_menu.waitEnterAnimationEnd = true;
OnEntered.RegisterListener(this);
}
if(OnEnter)
_menu.onEnter.AddListener(OnEnter.Raise);
if (OnLeft)
{
OnLeft.RegisterListener(this);
_menu.waitLeaveAnimationEnd = true;
}
if(OnLeave)
_menu.onLeave.AddListener(OnLeave.Raise);
}
public override void OnEventRaised(GameEvent gameEvent = null)
{
if (gameEvent == OnEntered)
{
_menu.SetActiveGO(true);
_menu.OnEntered();
}
else if(gameEvent == OnLeft)
{
_menu.OnLeft();
}
}
private void OnDestroy()
{
if(OnEntered)
OnEntered.UnregisterListener(this);
if(OnLeft)
OnLeft.UnregisterListener(this);
}
}