-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathCharacterZoom.cs
230 lines (209 loc) · 8.53 KB
/
CharacterZoom.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
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
// This code is part of the Fungus library (https://github.com/snozbot/fungus)
// It is released for free under the MIT open source license (https://github.com/snozbot/fungus/blob/master/LICENSE)
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using System.Collections.Generic;
public enum RotateZoomType
{
/// <summary> Fade In effect sequence. </summary>
SetCharacterToDefault,
None
}
namespace Fungus
{
/// <summary>
/// Moves the camera to a location specified by a View object.
/// </summary>
[CommandInfo("Animation",
"Zoom Flip Character",
"Zoom the character on Stage. MUST BE PLACED UNDER PORTRAIT if there's portrait change or at least not too close")]
[AddComponentMenu("")]
public class CharacterZoom : Command
{
[SerializeField] RotateZoomType status = RotateZoomType.None;
[Tooltip("Character to zoom & scale")]
[SerializeField] protected Character character;
[Tooltip("Scale character")]
[SerializeField] protected Vector3 scaleCharacterUI = new Vector3(1f, 1f, 1f);
[Tooltip("Wait until the fade has finished before executing next command")]
[SerializeField] protected bool flipCharacter = false;
[Tooltip("Enable scale")]
[SerializeField] protected bool enableScale = true;
[Tooltip("Enable move")]
[SerializeField] protected bool enableMove = false;
[SerializeField] protected bool enableRotate = false;
[Tooltip("Move character")]
[SerializeField] protected Vector3 moveCharacterUI = new Vector3(0f, 0f, 0f);
[Tooltip("Rotate angle in floats")]
[SerializeField] protected float rotateAngle = 0f;
[Tooltip("Duration")]
[SerializeField] protected float scaleMoveDuration = 0.3f;
[Tooltip("Ease type for the scale tween.")]
[SerializeField] protected LeanTweenType easeType;
protected bool isCompleted = false;
protected bool rotIsTru = false;
[Tooltip("Wait until the fade has finished before executing next command")]
[SerializeField] protected bool waitUntilFinished = true;
protected virtual void SetDefaultCharScale()
{
for (int i = character.State.holder.transform.childCount - 1; i >= 0; i--)
{
var a = character.State.holder.transform.GetChild(i).gameObject;
var c = a.GetComponent<RectTransform>();
LeanTween.scale(c, Vector3.one, scaleMoveDuration).setRecursive(true).setEase(easeType).setOnComplete(() =>
{
isCompleted = true;
});
//Reset character rotation if any
LeanTween.rotateAround(c, Vector3.forward, 0, scaleMoveDuration).setEaseOutQuad().setOnComplete(() =>
{
c.rotation = Quaternion.identity;
rotIsTru = true;
});
}
}
protected virtual IEnumerator SetDefaultCharPosition()
{
for (int i = character.State.holder.transform.childCount - 1; i >= 0; i--)
{
var b = character.State.holder.transform.GetChild(i).gameObject;
var c = b.GetComponent<RectTransform>();
float newOffsetMinnX = c.offsetMin.x;
float newOffsetMinnY = c.offsetMin.y;
float newOffsetMaxxX = c.offsetMax.x;
float newOffsetMaxxY = c.offsetMax.y;
bool moveIsCompleted = false;
bool moveIsCompleted1 = false;
bool moveIsCompleted2 = false;
bool moveIsCompleted3 = false;
LeanTween.value(b, newOffsetMinnX, 0f, scaleMoveDuration).setOnUpdate((float val) =>
{
c.offsetMin = new Vector2(val, c.offsetMin.y);
}).setOnComplete(() =>
{
moveIsCompleted = true;
});
LeanTween.value(b, newOffsetMinnY, 0f, scaleMoveDuration).setOnUpdate((float val) =>
{
c.offsetMin = new Vector2(c.offsetMin.x, val);
}).setOnComplete(() =>
{
moveIsCompleted1 = true;
});
LeanTween.value(b, newOffsetMaxxX, 0f, scaleMoveDuration).setOnUpdate((float val) =>
{
c.offsetMax = new Vector2(val, c.offsetMax.y);
}).setOnComplete(() =>
{
moveIsCompleted2 = true;
});
LeanTween.value(b, newOffsetMaxxY, 0f, scaleMoveDuration).setOnUpdate((float val) =>
{
c.offsetMax = new Vector2(c.offsetMax.x, val);
}).setOnComplete(() =>
{
moveIsCompleted3 = true;
});
while(!moveIsCompleted && !moveIsCompleted1 && !moveIsCompleted2 && !moveIsCompleted3)
{
yield return null;
}
Stops();
}
}
protected virtual void Stops()
{
if(rotIsTru && isCompleted)
{
for (int i = character.State.holder.transform.childCount - 1; i >= 0; i--)
{
var b = character.State.holder.transform.GetChild(i).gameObject;
b.GetComponent<RectTransform>().anchoredPosition = Vector3.zero;
}
Continue();
StopAllCoroutines();
}
}
protected virtual IEnumerator Continues()
{
float addFloat = 0.1f;
yield return new WaitForSeconds(scaleMoveDuration + addFloat);
Continue();
yield break;
}
protected virtual void ZoomRotateCharacter()
{
if (character && character.State.portraitImage != null)
{
for (int i = character.State.holder.transform.childCount - 1; i >= 0; i--)
{
var b = character.State.holder.transform.GetChild(i).gameObject;
var c = b.GetComponent<RectTransform>();
if (enableScale)
{
LeanTween.scale(c, scaleCharacterUI, scaleMoveDuration).setRecursive(false).setEase(easeType);
}
if (enableMove)
{
LeanTween.move(c, moveCharacterUI, scaleMoveDuration).setRecursive(false).setEase(easeType);
}
if (flipCharacter)
{
LeanTween.scale(c, new Vector3(-scaleCharacterUI.x, scaleCharacterUI.y, scaleCharacterUI.z), scaleMoveDuration).setRecursive(false).setEase(easeType);
}
if(enableRotate)
{
LeanTween.rotateAround(c, Vector3.forward, rotateAngle, scaleMoveDuration).setRecursive(false).setEase(easeType);
}
StartCoroutine(Continues());
}
}
}
#region Public members
public override void OnEnter()
{
if (status == RotateZoomType.SetCharacterToDefault)
{
if(character != null)
{
Canvas.ForceUpdateCanvases();
StartCoroutine(SetDefaultCharPosition());
SetDefaultCharScale();
}
if (!waitUntilFinished)
{
Continue();
}
}
else
{
if (character != null)
{
Canvas.ForceUpdateCanvases();
ZoomRotateCharacter();
}
if (!waitUntilFinished)
{
Continue();
}
}
}
public override string GetSummary()
{
if (character == null)
{
return "Error: No character selected";
}
else
{
return character.name;
}
}
public override Color GetButtonColor()
{
return new Color32(216, 228, 170, 255);
}
#endregion
}
}