为 ngui TweenPosition 添加 pingpongone
来源:互联网 发布:包装设计收费 知乎 编辑:程序博客网 时间:2024/05/19 17:26
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
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2015 Tasharen Entertainment
//----------------------------------------------
using
UnityEngine;
using
System.Collections;
using
System.Collections.Generic;
/// <summary>
/// Base class for all tweening operations.
/// </summary>
public
abstract
class
UITweener : MonoBehaviour
{
/// <summary>
/// Current tween that triggered the callback function.
/// </summary>
static
public
UITweener current;
public
enum
Method
{
Linear,
EaseIn,
EaseOut,
EaseInOut,
BounceIn,
BounceOut,
}
public
enum
Style
{
Once,
Loop,
PingPong,
PingPongOne
// by tin
}
/// <summary>
/// Tweening method used.
/// </summary>
[HideInInspector]
public
Method method = Method.Linear;
/// <summary>
/// Does it play once? Does it loop?
/// </summary>
[HideInInspector]
public
Style style = Style.Once;
/// <summary>
/// Optional curve to apply to the tween's time factor value.
/// </summary>
[HideInInspector]
public
AnimationCurve animationCurve =
new
AnimationCurve(
new
Keyframe(0f, 0f, 0f, 1f),
new
Keyframe(1f, 1f, 1f, 0f));
/// <summary>
/// Whether the tween will ignore the timescale, making it work while the game is paused.
/// </summary>
[HideInInspector]
public
bool
ignoreTimeScale =
true
;
/// <summary>
/// How long will the tweener wait before starting the tween?
/// </summary>
[HideInInspector]
public
float
delay = 0f;
/// <summary>
/// How long is the duration of the tween?
/// </summary>
[HideInInspector]
public
float
duration = 1f;
/// <summary>
/// Whether the tweener will use steeper curves for ease in / out style interpolation.
/// </summary>
[HideInInspector]
public
bool
steeperCurves =
false
;
/// <summary>
/// Used by buttons and tween sequences. Group of '0' means not in a sequence.
/// </summary>
[HideInInspector]
public
int
tweenGroup = 0;
/// <summary>
/// Event delegates called when the animation finishes.
/// </summary>
[HideInInspector]
public
List<EventDelegate> onFinished =
new
List<EventDelegate>();
// Deprecated functionality, kept for backwards compatibility
[HideInInspector]
public
GameObject eventReceiver;
[HideInInspector]
public
string
callWhenFinished;
bool
mStarted =
false
;
float
mStartTime = 0f;
float
mDuration = 0f;
float
mAmountPerDelta = 1000f;
float
mFactor = 0f;
/// <summary>
/// Amount advanced per delta time.
/// </summary>
public
float
amountPerDelta
{
get
{
if
(mDuration != duration)
{
mDuration = duration;
mAmountPerDelta = Mathf.Abs((duration > 0f) ? 1f / duration : 1000f) * Mathf.Sign(mAmountPerDelta);
}
return
mAmountPerDelta;
}
}
/// <summary>
/// Tween factor, 0-1 range.
/// </summary>
public
float
tweenFactor {
get
{
return
mFactor; }
set
{ mFactor = Mathf.Clamp01(value); } }
/// <summary>
/// Direction that the tween is currently playing in.
/// </summary>
public
AnimationOrTween.Direction direction {
get
{
return
amountPerDelta < 0f ? AnimationOrTween.Direction.Reverse : AnimationOrTween.Direction.Forward; } }
/// <summary>
/// This function is called by Unity when you add a component. Automatically set the starting values for convenience.
/// </summary>
void
Reset ()
{
if
(!mStarted)
{
SetStartToCurrentValue();
SetEndToCurrentValue();
}
}
/// <summary>
/// Update as soon as it's started so that there is no delay.
/// </summary>
protected
virtual
void
Start () { Update(); }
/// <summary>
/// Update the tweening factor and call the virtual update function.
/// </summary>
void
Update ()
{
float
delta = ignoreTimeScale ? RealTime.deltaTime : Time.deltaTime;
float
time = ignoreTimeScale ? RealTime.time : Time.time;
if
(!mStarted)
{
mStarted =
true
;
mStartTime = time + delay;
}
if
(time < mStartTime)
return
;
// Advance the sampling factor
mFactor += amountPerDelta * delta;
// Loop style simply resets the play factor after it exceeds 1.
if
(style == Style.Loop)
{
if
(mFactor > 1f)
{
mFactor -= Mathf.Floor(mFactor);
}
}
else
if
(style == Style.PingPong)
{
// Ping-pong style reverses the direction
if
(mFactor > 1f)
{
mFactor = 1f - (mFactor - Mathf.Floor(mFactor));
mAmountPerDelta = -mAmountPerDelta;
}
else
if
(mFactor < 0f)
{
mFactor = -mFactor;
mFactor -= Mathf.Floor(mFactor);
mAmountPerDelta = -mAmountPerDelta;
}
}
else
if
(style == Style.PingPongOne)
// by tin
{
// Ping-pong style reverses the direction
if
(mFactor > 1f)
{
mFactor = 1f - (mFactor - Mathf.Floor(mFactor));
mAmountPerDelta = -mAmountPerDelta;
}
else
if
(mFactor < 0f)
{
mFactor = -mFactor;
mFactor -= Mathf.Floor(mFactor);
mAmountPerDelta = -mAmountPerDelta;
enabled =
false
;
if
(onFinished !=
null
)
{
mTemp = onFinished;
onFinished =
new
List<EventDelegate>();
// Notify the listener delegates
EventDelegate.Execute(mTemp);
// Re-add the previous persistent delegates
for
(
int
i = 0; i < mTemp.Count; ++i)
{
EventDelegate ed = mTemp[i];
if
(ed !=
null
&& !ed.oneShot) EventDelegate.Add(onFinished, ed, ed.oneShot);
}
mTemp =
null
;
}
}
}
// If the factor goes out of range and this is a one-time tweening operation, disable the script
if
((style == Style.Once) && (duration == 0f || mFactor > 1f || mFactor < 0f))
{
mFactor = Mathf.Clamp01(mFactor);
Sample(mFactor,
true
);
enabled =
false
;
if
(current ==
null
)
{
UITweener before = current;
current =
this
;
if
(onFinished !=
null
)
{
mTemp = onFinished;
onFinished =
new
List<EventDelegate>();
// Notify the listener delegates
EventDelegate.Execute(mTemp);
// Re-add the previous persistent delegates
for
(
int
i = 0; i < mTemp.Count; ++i)
{
EventDelegate ed = mTemp[i];
if
(ed !=
null
&& !ed.oneShot) EventDelegate.Add(onFinished, ed, ed.oneShot);
}
mTemp =
null
;
}
// Deprecated legacy functionality support
if
(eventReceiver !=
null
&& !
string
.IsNullOrEmpty(callWhenFinished))
eventReceiver.SendMessage(callWhenFinished,
this
, SendMessageOptions.DontRequireReceiver);
current = before;
}
}
else
Sample(mFactor,
false
);
}
List<EventDelegate> mTemp =
null
;
/// <summary>
/// Convenience function -- set a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
/// </summary>
public
void
SetOnFinished (EventDelegate.Callback del) { EventDelegate.Set(onFinished, del); }
/// <summary>
/// Convenience function -- set a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
/// </summary>
public
void
SetOnFinished (EventDelegate del) { EventDelegate.Set(onFinished, del); }
/// <summary>
/// Convenience function -- add a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
/// </summary>
public
void
AddOnFinished (EventDelegate.Callback del) { EventDelegate.Add(onFinished, del); }
/// <summary>
/// Convenience function -- add a new OnFinished event delegate (here for to be consistent with RemoveOnFinished).
/// </summary>
public
void
AddOnFinished (EventDelegate del) { EventDelegate.Add(onFinished, del); }
/// <summary>
/// Remove an OnFinished delegate. Will work even while iterating through the list when the tweener has finished its operation.
/// </summary>
public
void
RemoveOnFinished (EventDelegate del)
{
if
(onFinished !=
null
) onFinished.Remove(del);
if
(mTemp !=
null
) mTemp.Remove(del);
}
/// <summary>
/// Mark as not started when finished to enable delay on next play.
/// </summary>
void
OnDisable () { mStarted =
false
; }
/// <summary>
/// Sample the tween at the specified factor.
/// </summary>
public
void
Sample (
float
factor,
bool
isFinished)
{
// Calculate the sampling value
float
val = Mathf.Clamp01(factor);
if
(method == Method.EaseIn)
{
val = 1f - Mathf.Sin(0.5f * Mathf.PI * (1f - val));
if
(steeperCurves) val *= val;
}
else
if
(method == Method.EaseOut)
{
val = Mathf.Sin(0.5f * Mathf.PI * val);
if
(steeperCurves)
{
val = 1f - val;
val = 1f - val * val;
}
}
else
if
(method == Method.EaseInOut)
{
const
float
pi2 = Mathf.PI * 2f;
val = val - Mathf.Sin(val * pi2) / pi2;
if
(steeperCurves)
{
val = val * 2f - 1f;
float
sign = Mathf.Sign(val);
val = 1f - Mathf.Abs(val);
val = 1f - val * val;
val = sign * val * 0.5f + 0.5f;
}
}
else
if
(method == Method.BounceIn)
{
val = BounceLogic(val);
}
else
if
(method == Method.BounceOut)
{
val = 1f - BounceLogic(1f - val);
}
// Call the virtual update
OnUpdate((animationCurve !=
null
) ? animationCurve.Evaluate(val) : val, isFinished);
}
/// <summary>
/// Main Bounce logic to simplify the Sample function
/// </summary>
float
BounceLogic (
float
val)
{
if
(val < 0.363636f)
// 0.363636 = (1/ 2.75)
{
val = 7.5685f * val * val;
}
else
if
(val < 0.727272f)
// 0.727272 = (2 / 2.75)
{
val = 7.5625f * (val -= 0.545454f) * val + 0.75f;
// 0.545454f = (1.5 / 2.75)
}
else
if
(val < 0.909090f)
// 0.909090 = (2.5 / 2.75)
{
val = 7.5625f * (val -= 0.818181f) * val + 0.9375f;
// 0.818181 = (2.25 / 2.75)
}
else
{
val = 7.5625f * (val -= 0.9545454f) * val + 0.984375f;
// 0.9545454 = (2.625 / 2.75)
}
return
val;
}
/// <summary>
/// Play the tween.
/// </summary>
[System.Obsolete(
"Use PlayForward() instead"
)]
public
void
Play () { Play(
true
); }
/// <summary>
/// Play the tween forward.
/// </summary>
public
void
PlayForward () { Play(
true
); }
/// <summary>
/// Play the tween in reverse.
/// </summary>
public
void
PlayReverse () { Play(
false
); }
/// <summary>
/// Manually activate the tweening process, reversing it if necessary.
/// </summary>
public
void
Play (
bool
forward)
{
mAmountPerDelta = Mathf.Abs(amountPerDelta);
if
(!forward) mAmountPerDelta = -mAmountPerDelta;
enabled =
true
;
Update();
}
/// <summary>
/// Manually reset the tweener's state to the beginning.
/// If the tween is playing forward, this means the tween's start.
/// If the tween is playing in reverse, this means the tween's end.
/// </summary>
public
void
ResetToBeginning ()
{
mStarted =
false
;
mFactor = (amountPerDelta < 0f) ? 1f : 0f;
Sample(mFactor,
false
);
}
/// <summary>
/// Manually start the tweening process, reversing its direction.
/// </summary>
public
void
Toggle ()
{
if
(mFactor > 0f)
{
mAmountPerDelta = -amountPerDelta;
}
else
{
mAmountPerDelta = Mathf.Abs(amountPerDelta);
}
enabled =
true
;
}
/// <summary>
/// Actual tweening logic should go here.
/// </summary>
abstract
protected
void
OnUpdate (
float
factor,
bool
isFinished);
/// <summary>
/// Starts the tweening operation.
/// </summary>
static
public
T Begin<T> (GameObject go,
float
duration)
where
T : UITweener
{
T comp = go.GetComponent<T>();
#if UNITY_FLASH
if
((
object
)comp ==
null
) comp = (T)go.AddComponent<T>();
#else
// Find the tween with an unset group ID (group ID of 0).
if
(comp !=
null
&& comp.tweenGroup != 0)
{
comp =
null
;
T[] comps = go.GetComponents<T>();
for
(
int
i = 0, imax = comps.Length; i < imax; ++i)
{
comp = comps[i];
if
(comp !=
null
&& comp.tweenGroup == 0)
break
;
comp =
null
;
}
}
if
(comp ==
null
)
{
comp = go.AddComponent<T>();
if
(comp ==
null
)
{
Debug.LogError(
"Unable to add "
+
typeof
(T) +
" to "
+ NGUITools.GetHierarchy(go), go);
return
null
;
}
}
#endif
comp.mStarted =
false
;
comp.duration = duration;
comp.mFactor = 0f;
comp.mAmountPerDelta = Mathf.Abs(comp.amountPerDelta);
comp.style = Style.Once;
comp.animationCurve =
new
AnimationCurve(
new
Keyframe(0f, 0f, 0f, 1f),
new
Keyframe(1f, 1f, 1f, 0f));
comp.eventReceiver =
null
;
comp.callWhenFinished =
null
;
comp.enabled =
true
;
return
comp;
}
/// <summary>
/// Set the 'from' value to the current one.
/// </summary>
public
virtual
void
SetStartToCurrentValue () { }
/// <summary>
/// Set the 'to' value to the current one.
/// </summary>
public
virtual
void
SetEndToCurrentValue () { }
}
0 0
- 为 ngui TweenPosition 添加 pingpongone
- unity3d ngui-TweenRotation-TweenPosition-TweenScale
- NGUI v2.0 Tweening_3:TweenPosition 位置间补类
- 为NGUI panel 添加 sorting layer
- 为NGUI panel 添加 sorting layer
- 【Unity3D游戏开发】NGUI之不相对于Anchor的位移动画TweenPosition (上) (二)
- 【Unity3D游戏开发】NGUI之不相对于Anchor的位移动画TweenPosition (下) (三)
- NGUI扩展:为面板(Panel)添加自定义图片遮罩
- NGUI动态添加
- NGUI 动态添加(改)
- NGUI动态添加widget
- NGUI 动态添加(改)
- NGUI动态添加
- NGUI动态添加 .
- NGUI动态添加UILabel
- 【学习笔记】NGUI中为Popup Menu添加点击事件响应
- Unity3D 新版NGUI事件添加
- 记录 NGUI UIToggle 事件添加
- grunt解决前后端跨域问题
- 毕设笔记--MySQL出现error 1045 access denied
- 结婚了
- mysql分组取每组前几条记录(排名) 附group by与order by的研究
- Android录制声音文件(音频),并播放
- 为 ngui TweenPosition 添加 pingpongone
- threshold的用法介绍
- Yii 中 jQuery 的引入问题
- Spring生命周期
- 编程题:串珠子
- 制作一个简单的Android版的音乐播放器
- UCOSIII移植到STM32上(待更)
- Retrofit原理简析
- NSNotificationCenter