-
Notifications
You must be signed in to change notification settings - Fork 0
/
Cam2D_Animation.lua
390 lines (342 loc) · 16.4 KB
/
Cam2D_Animation.lua
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
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
do
local camera2D = AK.Cam2D
camera2D.__index = camera2D
-- > SHOW FUNCTION
function camera2D:Show(object,value,speed)
value = value or 1
speed = speed or 0.05
if type(object) == "string" then
local item = CS.Get(object)
if type(value) == "number" then
local opacity = item.modelRenderer:GetOpacity()
if opacity < value then
local count = (value-opacity) / speed
AK.TaskList:Add(object,{count,speed,value},function(Table)
local this = CS.Get(Table.item)
local opacity = this.modelRenderer:GetOpacity()
this.modelRenderer:SetOpacity( opacity + Table.add )
if Table.boucle >= Table.boucle_max then
this.modelRenderer:SetOpacity( Table.valeur )
end
end)
else
--Error("L'opacité du modèle est supérieur à value")
end
end
elseif type(object) == "table" then
if type(value) == "number" then
for i = 1, #object do
local item = CS.Get(object[i])
local opacity = item.modelRenderer:GetOpacity()
if opacity < value then
local count = (value-opacity) / speed
AK.TaskList:Add(object[i],{count,speed,value},function(Table)
local this = CS.Get(Table.item)
local opacity = this.modelRenderer:GetOpacity()
this.modelRenderer:SetOpacity( opacity + Table.add )
if Table.boucle >= Table.boucle_max then
this.modelRenderer:SetOpacity( Table.valeur )
end
end)
else
--Error("L'opacité du modèle est supérieur à value")
end
end
end
end
end
function camera2D:Hide(object,value,speed)
value = value or 0
speed = speed or 0.05
if type(object) == "string" then
local item = CS.Get(object)
if type(value) == "number" then
local opacity = item.modelRenderer:GetOpacity()
if opacity > value then
local count = (opacity-value) / speed
AK.TaskList:Add(object,{count,speed,value},function(Table)
local this = CS.Get(Table.item)
local opacity = this.modelRenderer:GetOpacity()
this.modelRenderer:SetOpacity( opacity - Table.add )
if Table.boucle >= Table.boucle_max then
this.modelRenderer:SetOpacity( Table.valeur )
end
end)
else
--Error("L'opacité du modèle est inférieur à value")
end
end
elseif type(object) == "table" then
if type(value) == "number" then
for i = 1, #object do
local item = CS.Get(object[i])
local opacity = item.modelRenderer:GetOpacity()
if opacity > value then
local count = (opacity-value) / speed
AK.TaskList:Add(object[i],{count,speed,value},function(Table)
local this = CS.Get(Table.item)
local opacity = this.modelRenderer:GetOpacity()
this.modelRenderer:SetOpacity( opacity - Table.add )
if Table.boucle >= Table.boucle_max then
this.modelRenderer:SetOpacity( Table.valeur )
end
end)
else
--Error("L'opacité du modèle est supérieur à value")
end
end
end
end
end
-- > NewAnimation function
function camera2D:NewAnim(item,speed,resize,decalpos,decalscale,parent)
local lerpresize = resize or false
parent = parent or false
local comptype = nil
decalpos = decalpos or {}
decalscale = decalscale or {}
decalpos[1] = decalpos[1] or 0
decalpos[2] = decalpos[2] or 0
decalscale[1] = decalscale[1] or 0
decalscale[2] = decalscale[2] or 0
if type(item) == "string" then
local object = CS.Get(item)
if object ~= nil then
if self.LerpTab[item] == nil then
local pos = object.transform:GetLocalPosition()
local scale = object.transform:GetLocalScale()
self.LerpTab[item] = {
play = false,
state = false,
speed = speed,
auto = lerpresize,
defaut = pos,
decalinfo = {decalpos[1],decalpos[2]},
defautscale = scale,
scaleinfo = {decalscale[1],decalscale[2]},
lerp = Vector3:New( pos.x + decalpos[1] , pos.y + decalpos[2] , pos.z ),
lerpscale = Vector3:New( scale.x + decalscale[1] , scale.y + decalscale[2] , scale.z )
}
else
print(item.." possède déjà une animation.")
return false
end
else
print("L'object est inexistant, impossible d'ajouter une animation.")
return false
end
elseif type(item) == "table" then
for i = 1, #item do
local object = CraftStudio.FindGameObject(item[i])
if object ~= nil then
if self.LerpTab[item[i]] == nil then
local pos = object.transform:GetLocalPosition()
local scale = object.transform:GetLocalScale()
self.LerpTab[item[i]] = {
play = false,
state = false,
speed = speed,
auto = lerpresize,
defaut = pos,
decalinfo = {decalpos[1],decalpos[2]},
defautscale = scale,
scaleinfo = {decalscale[1],decalscale[2]},
lerp = Vector3:New( pos.x + decalpos[1] , pos.y + decalpos[2] , pos.z ),
lerpscale = Vector3:New( scale.x + decalscale[1] , scale.y + decalscale[2] , scale.z )
}
else
print(item[i].." possède déjà une animation.")
end
else
print("L'object ".. item[i] .." est inexistant, impossible d'ajouter une animation.")
end
end
end
end
-- > State anim or table group anim
function camera2D:StateAnim(item)
if type(item) == "string" then
if self.LerpTab[item] ~= nil then
if self.LerpTab[item].play then
return false
elseif not self.LerpTab[item].play then
return true
end
end
elseif type(item) == "table" then
local count = 0
local need = #item
for i = 1 ,#item do
if self.LerpTab[item[i]] ~= nil then
if self.LerpTab[item[i]].play then
-- do nothing
elseif not self.LerpTab[item[i]].play then
count = count + 1
end
end
if count == need then
return true
end
end
return false
end
end
function camera2D:Anim(item,easing)
easing = easing or "InOutCubic"
if type(item) == "string" then
if self.LerpTab[item] ~= nil then
if not self.LerpTab[item].play then
if self.LerpTab[item].state then
AK.TaskList:Add(item,{(self.LerpTab[item].speed*60),nil,easing},function(Table)
local Lerp_item = self.LerpTab[Table.item]
local object = CraftStudio.FindGameObject(Table.item)
local factor = Table.boucle / Table.boucle_max
local progression = (1 - (1 - factor) * (1 - factor))
object.transform:SetLocalPosition( Vector3.Lerp(
Lerp_item.lerp,
Lerp_item.defaut,
progression
) )
object.transform:SetLocalScale( Vector3.Lerp(
Lerp_item.lerpscale,
Lerp_item.defautscale,
progression
) )
if Table.boucle >= Table.boucle_max then
Lerp_item.play = false
end
end)
else
AK.TaskList:Add(item,{(self.LerpTab[item].speed*60),nil,easing},function(Table)
local Lerp_item = self.LerpTab[Table.item]
local object = CraftStudio.FindGameObject(Table.item)
local factor = Table.boucle / Table.boucle_max
local progression = (1 - (1 - factor) * (1 - factor))
do
local state = self.LerpTab[item].state
local POSdefaut = state and Lerp_item.defaut or Lerp_item.lerp
local POSlerp = state and Lerp_item.lerp or Lerp_item.defaut
object.transform:SetLocalPosition( Vector3.Lerp(
POSdefaut,
POSlerp,
progression
) )
end
object.transform:SetLocalScale( Vector3.Lerp(
Lerp_item.defautscale,
Lerp_item.lerpscale,
progression
) )
if Table.boucle >= Table.boucle_max then
Lerp_item.play = false
end
end)
end
self.LerpTab[item].play = true
self.LerpTab[item].state = not self.LerpTab[item].state
else
self.LerpTab[item].state = not self.LerpTab[item].state
AK.TaskList:Reverse(item)
end
else
print("Le lerp "..item.." n'existe pas")
return false
end
elseif type(item) == "table" then
for i = 1 , #item do
if self.LerpTab[item[i]] ~= nil then
if not self.LerpTab[item[i]].play then
if self.LerpTab[item[i]].state then
AK.TaskList:Add(item[i],{(self.LerpTab[item[i]].speed*60),nil},function(Table)
local Lerp_item = self.LerpTab[Table.item]
local object = CraftStudio.FindGameObject(Table.item)
local factor = Table.boucle / Table.boucle_max
local progression = (1 - (1 - factor) * (1 - factor))
object.transform:SetLocalPosition( Vector3.Lerp(
Lerp_item.lerp,
Lerp_item.defaut,
progression
) )
object.transform:SetLocalScale( Vector3.Lerp(
Lerp_item.lerpscale,
Lerp_item.defautscale,
progression
) )
if Table.boucle >= Table.boucle_max then
Lerp_item.play = false
end
end)
else
AK.TaskList:Add(item[i],{(self.LerpTab[item[i]].speed*60),nil},function(Table)
local Lerp_item = self.LerpTab[Table.item]
local object = CraftStudio.FindGameObject(Table.item)
local factor = Table.boucle / Table.boucle_max
local progression = (1 - (1 - factor) * (1 - factor))
object.transform:SetLocalPosition( Vector3.Lerp(
Lerp_item.defaut,
Lerp_item.lerp,
progression
) )
object.transform:SetLocalScale( Vector3.Lerp(
Lerp_item.defautscale,
Lerp_item.lerpscale,
progression
) )
if Table.boucle >= Table.boucle_max then
Lerp_item.play = false
end
end)
end
self.LerpTab[item[i]].play = true
self.LerpTab[item[i]].state = not self.LerpTab[item[i]].state
end
else
print("Le lerp "..item.." n'existe pas")
return false
end
end
end
end
function camera2D:OnAnim(item,parent,callback)
if type(item) ~= "table" then
item = {item}
end
parent = parent or false
callback = callback or Nil
for i=1,#item do
local object
-- > Si l'animation est parente ou non
if not parent then
object = CS.Get(item[i])
else
object = CS.Get(item[i]):GetParent()
end
-- > Si l'objet ne possède pas de script
if object:GetComponent("ScriptedBehavior") == nil then
self:AddScript(item,"OnClick")
end
-- > OnHover Action
object:OnHover(function(gameObject)
return callback(gameObject,object)
end)
--> Out Hover Action
object:OutHover(function(this,gameObject)
if AK.UI.LerpTab[item[i]].state then
this.toaction = true
end
local func = function(this,gameObject,index)
if this.toaction and AK.UI:StateAnim(item) then
print(index)
table.remove(this.OnNextCallback,index)
callback(gameObject)
end
end
if this.OnNextCallback == nil then
this.OnNextCallback = {func}
else
this.OnNextCallback[#this.OnNextCallback + 1] = func
end
end)
end
end
end