-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUIObjectAnimator_LogicList.cs
175 lines (135 loc) · 5.84 KB
/
UIObjectAnimator_LogicList.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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
#region Header
/* ============================================
* 작성자 : Strix
* 작성일 : 2019-10-17 오전 11:23:33
* 개요 :
============================================ */
#endregion Header
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace UIFramework
{
public class UIAnimationLogicFactory
{
public List<IUIAnimationLogic> listUIAnimationLogic { get; private set; } = new List<IUIAnimationLogic>();
public void DoAdd_Animation_Collection<T>(IEnumerable<T> listAnimationLogic)
where T : IUIAnimationLogic
{
if (listAnimationLogic == null)
return;
foreach (T pLogic in listAnimationLogic)
{
if (pLogic == null)
continue;
listUIAnimationLogic.Add(pLogic);
}
}
}
/// <summary>
/// 범용적인 UIAnimation 로직의 Base Interface
/// <para><see cref="UIAnimation"/>에의해 관리되며 실행됩니다.</para>
/// </summary>
public interface IUIAnimationLogic
{
void IUIAnimationLogic_OnAwake(IUIObject pUIObject);
void IUIAnimationLogic_OnBeforeShow(IUIObject pUIObject);
IEnumerator IUIAnimationLogic_OnAnimation(IUIObject pUIObject, bool bIgnoreTimeScale);
void IUIAnimationLogic_OnDestroy(IUIObject pUIObject);
}
/// <summary>
/// UI Animation - Show 전용
/// </summary>
public interface IUIAnimationLogic_Show : IUIAnimationLogic { }
/// <summary>
/// UI Animation - Hide 전용
/// </summary>
public interface IUIAnimationLogic_Hide : IUIAnimationLogic { }
[System.Serializable]
public abstract class UIAnimationLogic_ComponentBase : MonoBehaviour, IUIAnimationLogic
{
public abstract void IUIAnimationLogic_OnAwake(IUIObject pUIObject);
public abstract void IUIAnimationLogic_OnBeforeShow(IUIObject pUIObject);
public abstract IEnumerator IUIAnimationLogic_OnAnimation(IUIObject pUIObject, bool bIgnoreTimeScale);
public virtual void IUIAnimationLogic_OnDestroy(IUIObject pUIObject) { }
}
/// <summary>
/// <see cref="IUIAnimationLogic"/> 컨테이너
/// </summary>
[System.Serializable]
public class UIAnimation
{
/* const & readonly declaration */
/* enum & struct declaration */
/* public - Field declaration */
public List<IUIAnimationLogic> listUIAnimationLogic { get; private set; } = new List<IUIAnimationLogic>();
/* protected & private - Field declaration */
List<Coroutine> _listExecuteCoroutine = new List<Coroutine>();
System.Func<IEnumerator, Coroutine> _OnStartCoroutine;
System.Action<Coroutine> _OnStopCoroutine;
IUIObject _pUIObject;
// ========================================================================== //
/* public - [Do] Function
* 외부 객체가 호출(For External class call)*/
public void DoInit(IUIObject pUIObject, System.Func<IEnumerator, Coroutine> OnStartCoroutine, System.Action<Coroutine> OnStopCoroutine, bool bClearLogicList = true)
{
_pUIObject = pUIObject;
_OnStartCoroutine = OnStartCoroutine;
_OnStopCoroutine = OnStopCoroutine;
if (bClearLogicList)
listUIAnimationLogic.Clear();
}
public void DoInit_Animation(UIAnimationLogicFactory pLogicFactory)
{
listUIAnimationLogic.AddRange(pLogicFactory.listUIAnimationLogic);
pLogicFactory.listUIAnimationLogic.ForEach(p => p.IUIAnimationLogic_OnAwake(_pUIObject));
}
public void DoAdd_Animation(IUIAnimationLogic pLogic)
{
listUIAnimationLogic.Add(pLogic);
pLogic.IUIAnimationLogic_OnAwake(_pUIObject);
}
public void DoClear_AnimationLogic()
{
listUIAnimationLogic.ForEach(p => p.IUIAnimationLogic_OnDestroy(_pUIObject));
listUIAnimationLogic.Clear();
}
public void Event_OnBeforeShow()
{
listUIAnimationLogic.ForEach(p => p.IUIAnimationLogic_OnBeforeShow(_pUIObject));
}
/// <summary>
/// 애니메이션들을 동시에 재생
/// </summary>
public IEnumerator PlayAnimationCoroutine_Concurrently(bool bIgnoreTimeScale)
{
for (int i = 0; i < _listExecuteCoroutine.Count; i++)
_OnStopCoroutine(_listExecuteCoroutine[i]);
_listExecuteCoroutine.Clear();
for (int i = 0; i < listUIAnimationLogic.Count; i++)
_listExecuteCoroutine.Add(_OnStartCoroutine(listUIAnimationLogic[i].IUIAnimationLogic_OnAnimation(_pUIObject, bIgnoreTimeScale)));
yield return _listExecuteCoroutine.GetEnumerator_Safe();
}
/// <summary>
/// 애니메이션을 하나씩 순차적으로 재생
/// </summary>
public IEnumerator PlayAnimationCoroutine_Sequential(bool bIgnoreTimeScale)
{
for (int i = 0; i < _listExecuteCoroutine.Count; i++)
_OnStopCoroutine(_listExecuteCoroutine[i]);
_listExecuteCoroutine.Clear();
for (int i = 0; i < listUIAnimationLogic.Count; i++)
{
if (listUIAnimationLogic[i] != null)
yield return listUIAnimationLogic[i].IUIAnimationLogic_OnAnimation(_pUIObject, bIgnoreTimeScale);
}
}
// ========================================================================== //
/* protected - Override & Unity API */
/* protected - [abstract & virtual] */
// ========================================================================== //
#region Private
#endregion Private
}
}