-
Notifications
You must be signed in to change notification settings - Fork 16
/
iTween.cs
8548 lines (7894 loc) · 269 KB
/
iTween.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
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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright (c) 2011 Bob Berkebile (pixelplacment)
// Please direct any bugs/comments/suggestions to http://pixelplacement.com
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
/*
TERMS OF USE - EASING EQUATIONS
Open source under the BSD License.
Copyright (c)2001 Robert Penner
All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
Neither the name of the author nor the names of contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#region Namespaces
using System;
using System.Collections;
using System.Reflection;
using UnityEngine;
#endregion
/// <summary>
/// <para>Version: 2.0.45</para>
/// <para>Author: Bob Berkebile (http://pixelplacement.com)</para>
/// <para>Support: http://itween.pixelplacement.com</para>
/// </summary>
public class iTween : MonoBehaviour
{
#region Variables
//repository of all living iTweens:
public static ArrayList tweens = new ArrayList();
//camera fade object:
private static GameObject cameraFade;
//status members (made public for visual troubleshooting in the inspector):
public string id, type, method;
public iTween.EaseType easeType;
public float time, delay;
public LoopType loopType;
public bool isRunning, isPaused;
/* GFX47 MOD START */
public string _name;
/* GFX47 MOD END */
//private members:
private float runningTime, percentage;
private float delayStarted; //probably not neccesary that this be protected but it shuts Unity's compiler up about this being "never used"
private bool kinematic, isLocal, loop, reverse, wasPaused, physics;
private Hashtable tweenArguments;
private Space space;
private delegate float EasingFunction(float start, float end, float value);
private delegate void ApplyTween();
private EasingFunction ease;
private ApplyTween apply;
private AudioSource audioSource;
private Vector3[] vector3s;
private Vector2[] vector2s;
private Color[,] colors;
private float[] floats;
private Rect[] rects;
private CRSpline path;
private Vector3 preUpdate;
private Vector3 postUpdate;
private NamedValueColor namedcolorvalue;
private float lastRealTime; // Added by PressPlay
private bool useRealTime; // Added by PressPlay
/// <summary>
/// The type of easing to use based on Robert Penner's open source easing equations (http://www.robertpenner.com/easing_terms_of_use.html).
/// </summary>
public enum EaseType
{
easeInQuad,
easeOutQuad,
easeInOutQuad,
easeInCubic,
easeOutCubic,
easeInOutCubic,
easeInQuart,
easeOutQuart,
easeInOutQuart,
easeInQuint,
easeOutQuint,
easeInOutQuint,
easeInSine,
easeOutSine,
easeInOutSine,
easeInExpo,
easeOutExpo,
easeInOutExpo,
easeInCirc,
easeOutCirc,
easeInOutCirc,
linear,
spring,
/* GFX47 MOD START */
//bounce,
easeInBounce,
easeOutBounce,
easeInOutBounce,
/* GFX47 MOD END */
easeInBack,
easeOutBack,
easeInOutBack,
/* GFX47 MOD START */
//elastic,
easeInElastic,
easeOutElastic,
easeInOutElastic,
/* GFX47 MOD END */
punch
}
/// <summary>
/// The type of loop (if any) to use.
/// </summary>
public enum LoopType
{
/// <summary>
/// Do not loop.
/// </summary>
none,
/// <summary>
/// Rewind and replay.
/// </summary>
loop,
/// <summary>
/// Ping pong the animation back and forth.
/// </summary>
pingPong
}
/// <summary>
/// Many shaders use more than one color. Use can have iTween's Color methods operate on them by name.
/// </summary>
public enum NamedValueColor
{
/// <summary>
/// The main color of a material. Used by default and not required for Color methods to work in iTween.
/// </summary>
_Color,
/// <summary>
/// The specular color of a material (used in specular/glossy/vertexlit shaders).
/// </summary>
_SpecColor,
/// <summary>
/// The emissive color of a material (used in vertexlit shaders).
/// </summary>
_Emission,
/// <summary>
/// The reflection color of the material (used in reflective shaders).
/// </summary>
_ReflectColor
}
#endregion
#region Defaults
/// <summary>
/// A collection of baseline presets that iTween needs and utilizes if certain parameters are not provided.
/// </summary>
public static class Defaults
{
//general defaults:
public static float time = 1f;
public static float delay = 0f;
public static NamedValueColor namedColorValue = NamedValueColor._Color;
public static LoopType loopType = LoopType.none;
public static EaseType easeType = iTween.EaseType.easeOutExpo;
public static float lookSpeed = 3f;
public static bool isLocal = false;
public static Space space = Space.Self;
public static bool orientToPath = false;
public static Color color = Color.white;
//update defaults:
public static float updateTimePercentage = .05f;
public static float updateTime = 1f * updateTimePercentage;
//cameraFade defaults:
public static int cameraFadeDepth = 999999;
//path look ahead amount:
public static float lookAhead = .05f;
public static bool useRealTime = false; // Added by PressPlay
//look direction:
public static Vector3 up = Vector3.up;
}
#endregion
#region #1 Static Registers
/// <summary>
/// Sets up a GameObject to avoid hiccups when an initial iTween is added. It's advisable to run this on every object you intend to run iTween on in its Start or Awake.
/// </summary>
/// <param name="target">
/// A <see cref="GameObject"/> to be the target to be initialized for iTween.
/// </param>
public static void Init(GameObject target)
{
MoveBy(target, Vector3.zero, 0);
}
/// <summary>
/// Instantly changes the amount(transparency) of a camera fade and then returns it back over time with MINIMUM customization options.
/// </summary>
/// <param name="amount">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for how transparent the Texture2D that the camera fade uses is.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> for the time in seconds the animation will take to complete.
/// </param>
public static void CameraFadeFrom(float amount, float time)
{
if (cameraFade)
{
CameraFadeFrom(Hash("amount", amount, "time", time));
}
else
{
Debug.LogError("iTween Error: You must first add a camera fade object with CameraFadeAdd() before atttempting to use camera fading.");
}
}
/// <summary>
/// Instantly changes the amount(transparency) of a camera fade and then returns it back over time with FULL customization options.
/// </summary>
/// <param name="amount">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for how transparent the Texture2D that the camera fade uses is.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete.
/// </param>
/// <param name="delay">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning.
/// </param>
/// <param name="easetype">
/// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation.
/// </param>
/// <param name="looptype">
/// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed.
/// </param>
/// <param name="onstart">
/// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation.
/// </param>
/// <param name="onstarttarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method.
/// </param>
/// <param name="onstartparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method.
/// </param>
/// <param name="onupdate">
/// A <see cref="System.String"/> for the name of a function to launch on every step of the animation.
/// </param>
/// <param name="onupdatetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method.
/// </param>
/// <param name="onupdateparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method.
/// </param>
/// <param name="oncomplete">
/// A <see cref="System.String"/> for the name of a function to launch at the end of the animation.
/// </param>
/// <param name="oncompletetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method.
/// </param>
/// <param name="oncompleteparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "oncomplete" method.
/// </param>
public static void CameraFadeFrom(Hashtable args)
{
//establish iTween:
if (cameraFade)
{
ColorFrom(cameraFade, args);
}
else
{
Debug.LogError("iTween Error: You must first add a camera fade object with CameraFadeAdd() before atttempting to use camera fading.");
}
}
/// <summary>
/// Changes the amount(transparency) of a camera fade over time with MINIMUM customization options.
/// </summary>
/// <param name="amount">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for how transparent the Texture2D that the camera fade uses is.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> for the time in seconds the animation will take to complete.
/// </param>
public static void CameraFadeTo(float amount, float time)
{
if (cameraFade)
{
CameraFadeTo(Hash("amount", amount, "time", time));
}
else
{
Debug.LogError("iTween Error: You must first add a camera fade object with CameraFadeAdd() before atttempting to use camera fading.");
}
}
/// <summary>
/// Changes the amount(transparency) of a camera fade over time with FULL customization options.
/// </summary>
/// <param name="amount">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for how transparent the Texture2D that the camera fade uses is.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete.
/// </param>
/// <param name="delay">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning.
/// </param>
/// <param name="easetype">
/// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation.
/// </param>
/// <param name="looptype">
/// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed.
/// </param>
/// <param name="onstart">
/// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation.
/// </param>
/// <param name="onstarttarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method.
/// </param>
/// <param name="onstartparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method.
/// </param>
/// <param name="onupdate">
/// A <see cref="System.String"/> for the name of a function to launch on every step of the animation.
/// </param>
/// <param name="onupdatetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method.
/// </param>
/// <param name="onupdateparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method.
/// </param>
/// <param name="oncomplete">
/// A <see cref="System.String"/> for the name of a function to launch at the end of the animation.
/// </param>
/// <param name="oncompletetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method.
/// </param>
/// <param name="oncompleteparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "oncomplete" method.
/// </param>
public static void CameraFadeTo(Hashtable args)
{
/*
CameraFadeAdd(Defaults.cameraFadeDepth);
//rescale cameraFade just in case screen size has changed to ensure it takes up the full screen:
cameraFade.guiTexture.pixelInset=new Rect(0,0,Screen.width,Screen.height);
*/
if (cameraFade)
{
//establish iTween:
ColorTo(cameraFade, args);
}
else
{
Debug.LogError("iTween Error: You must first add a camera fade object with CameraFadeAdd() before atttempting to use camera fading.");
}
}
/// <summary>
/// Returns a value to an 'oncallback' method interpolated between the supplied 'from' and 'to' values for application as desired. Requires an 'onupdate' callback that accepts the same type as the supplied 'from' and 'to' properties.
/// </summary>
/// <param name="from">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> or <see cref="Vector3"/> or <see cref="Vector2"/> or <see cref="Color"/> or <see cref="Rect"/> for the starting value.
/// </param>
/// <param name="to">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> or <see cref="Vector3"/> or <see cref="Vector2"/> or <see cref="Color"/> or <see cref="Rect"/> for the ending value.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete.
/// </param>
/// <param name="speed">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> can be used instead of time to allow animation based on speed (only works with Vector2, Vector3, and Floats)
/// </param>
/// <param name="delay">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning.
/// </param>
/// <param name="easetype">
/// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation.
/// </param>
/// <param name="looptype">
/// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed.
/// </param>
/// <param name="onstart">
/// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation.
/// </param>
/// <param name="onstarttarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method.
/// </param>
/// <param name="onstartparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method.
/// </param>
/// <param name="onupdate">
/// A <see cref="System.String"/> for the name of a function to launch on every step of the animation.
/// </param>
/// <param name="onupdatetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method.
/// </param>
/// <param name="onupdateparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method.
/// </param>
/// <param name="oncomplete">
/// A <see cref="System.String"/> for the name of a function to launch at the end of the animation.
/// </param>
/// <param name="oncompletetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method.
/// </param>
/// <param name="oncompleteparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "oncomplete" method.
/// </param>
public static void ValueTo(GameObject target, Hashtable args)
{
//clean args:
args = iTween.CleanArgs(args);
if (!args.Contains("onupdate") || !args.Contains("from") || !args.Contains("to"))
{
Debug.LogError("iTween Error: ValueTo() requires an 'onupdate' callback function and a 'from' and 'to' property. The supplied 'onupdate' callback must accept a single argument that is the same type as the supplied 'from' and 'to' properties!");
return;
}
else
{
//establish iTween:
args["type"] = "value";
if (args["from"].GetType() == typeof(Vector2))
{
args["method"] = "vector2";
}
else if (args["from"].GetType() == typeof(Vector3))
{
args["method"] = "vector3";
}
else if (args["from"].GetType() == typeof(Rect))
{
args["method"] = "rect";
}
else if (args["from"].GetType() == typeof(Single))
{
args["method"] = "float";
}
else if (args["from"].GetType() == typeof(Color))
{
args["method"] = "color";
}
else
{
Debug.LogError("iTween Error: ValueTo() only works with interpolating Vector3s, Vector2s, floats, ints, Rects and Colors!");
return;
}
//set a default easeType of linear if none is supplied since eased color interpolation is nearly unrecognizable:
if (!args.Contains("easetype"))
{
args.Add("easetype", EaseType.linear);
}
Launch(target, args);
}
}
/// <summary>
/// Changes a GameObject's alpha value instantly then returns it to the provided alpha over time with MINIMUM customization options. If a GUIText or GUITexture component is attached, it will become the target of the animation. Identical to using ColorFrom and using the "a" parameter.
/// </summary>
/// <param name="target">
/// A <see cref="GameObject"/> to be the target of the animation.
/// </param>
/// <param name="alpha">
/// A <see cref="System.Single"/> for the final alpha value of the animation.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> for the time in seconds the animation will take to complete.
/// </param>
public static void FadeFrom(GameObject target, float alpha, float time)
{
FadeFrom(target, Hash("alpha", alpha, "time", time));
}
/// <summary>
/// Changes a GameObject's alpha value instantly then returns it to the provided alpha over time with FULL customization options. If a GUIText or GUITexture component is attached, it will become the target of the animation. Identical to using ColorFrom and using the "a" parameter.
/// </summary>
/// <param name="alpha">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the initial alpha value of the animation.
/// </param>
/// <param name="amount">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the initial alpha value of the animation.
/// </param>
/// <param name="includechildren">
/// A <see cref="System.Boolean"/> for whether or not to include children of this GameObject. True by default.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete.
/// </param>
/// <param name="delay">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning.
/// </param>
/// <param name="easetype">
/// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation.
/// </param>
/// <param name="looptype">
/// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed.
/// </param>
/// <param name="onstart">
/// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation.
/// </param>
/// <param name="onstarttarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method.
/// </param>
/// <param name="onstartparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method.
/// </param>
/// <param name="onupdate">
/// A <see cref="System.String"/> for the name of a function to launch on every step of the animation.
/// </param>
/// <param name="onupdatetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method.
/// </param>
/// <param name="onupdateparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method.
/// </param>
/// <param name="oncomplete">
/// A <see cref="System.String"/> for the name of a function to launch at the end of the animation.
/// </param>
/// <param name="oncompletetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method.
/// </param>
/// <param name="oncompleteparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "oncomplete" method.
/// </param>
public static void FadeFrom(GameObject target, Hashtable args)
{
ColorFrom(target, args);
}
/// <summary>
/// Changes a GameObject's alpha value over time with MINIMUM customization options. If a GUIText or GUITexture component is attached, it will become the target of the animation. Identical to using ColorTo and using the "a" parameter.
/// </summary>
/// <param name="target">
/// A <see cref="GameObject"/> to be the target of the animation.
/// </param>
/// <param name="alpha">
/// A <see cref="System.Single"/> for the final alpha value of the animation.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> for the time in seconds the animation will take to complete.
/// </param>
public static void FadeTo(GameObject target, float alpha, float time)
{
FadeTo(target, Hash("alpha", alpha, "time", time));
}
/// <summary>
/// Changes a GameObject's alpha value over time with FULL customization options. If a GUIText or GUITexture component is attached, it will become the target of the animation. Identical to using ColorTo and using the "a" parameter.
/// </summary>
/// <param name="alpha">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the final alpha value of the animation.
/// </param>
/// <param name="amount">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the final alpha value of the animation.
/// </param>
/// <param name="includechildren">
/// A <see cref="System.Boolean"/> for whether or not to include children of this GameObject. True by default.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete.
/// </param>
/// <param name="delay">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning.
/// </param>
/// <param name="easetype">
/// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation.
/// </param>
/// <param name="looptype">
/// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed.
/// </param>
/// <param name="onstart">
/// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation.
/// </param>
/// <param name="onstarttarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method.
/// </param>
/// <param name="onstartparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method.
/// </param>
/// <param name="onupdate">
/// A <see cref="System.String"/> for the name of a function to launch on every step of the animation.
/// </param>
/// <param name="onupdatetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method.
/// </param>
/// <param name="onupdateparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method.
/// </param>
/// <param name="oncomplete">
/// A <see cref="System.String"/> for the name of a function to launch at the end of the animation.
/// </param>
/// <param name="oncompletetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method.
/// </param>
/// <param name="oncompleteparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "oncomplete" method.
/// </param>
public static void FadeTo(GameObject target, Hashtable args)
{
ColorTo(target, args);
}
/// <summary>
/// Changes a GameObject's color values instantly then returns them to the provided properties over time with MINIMUM customization options. If a GUIText or GUITexture component is attached, it will become the target of the animation.
/// </summary>
/// <param name="target">
/// A <see cref="GameObject"/> to be the target of the animation.
/// </param>
/// <param name="color">
/// A <see cref="Color"/> to change the GameObject's color to.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> for the time in seconds the animation will take to complete.
/// </param>
public static void ColorFrom(GameObject target, Color color, float time)
{
ColorFrom(target, Hash("color", color, "time", time));
}
/// <summary>
/// Changes a GameObject's color values instantly then returns them to the provided properties over time with FULL customization options. If a GUIText or GUITexture component is attached, it will become the target of the animation.
/// </summary>
/// <param name="color">
/// A <see cref="Color"/> to change the GameObject's color to.
/// </param>
/// <param name="r">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the color red.
/// </param>
/// <param name="g">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the color green.
/// </param>
/// <param name="b">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the color green.
/// </param>
/// <param name="a">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the alpha.
/// </param>
/// <param name="namedcolorvalue">
/// A <see cref="NamedColorValue"/> or <see cref="System.String"/> for the individual setting of the alpha.
/// </param>
/// <param name="includechildren">
/// A <see cref="System.Boolean"/> for whether or not to include children of this GameObject. True by default.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete.
/// </param>
/// <param name="delay">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning.
/// </param>
/// <param name="easetype">
/// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation.
/// </param>
/// <param name="looptype">
/// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed.
/// </param>
/// <param name="onstart">
/// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation.
/// </param>
/// <param name="onstarttarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method.
/// </param>
/// <param name="onstartparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method.
/// </param>
/// <param name="onupdate">
/// A <see cref="System.String"/> for the name of a function to launch on every step of the animation.
/// </param>
/// <param name="onupdatetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method.
/// </param>
/// <param name="onupdateparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method.
/// </param>
/// <param name="oncomplete">
/// A <see cref="System.String"/> for the name of a function to launch at the end of the animation.
/// </param>
/// <param name="oncompletetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method.
/// </param>
/// <param name="oncompleteparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "oncomplete" method.
/// </param>
public static void ColorFrom(GameObject target, Hashtable args)
{
Color fromColor = new Color();
Color tempColor = new Color();
//clean args:
args = iTween.CleanArgs(args);
//handle children:
if (!args.Contains("includechildren") || (bool)args["includechildren"])
{
foreach (Transform child in target.transform)
{
Hashtable argsCopy = (Hashtable)args.Clone();
argsCopy["ischild"] = true;
ColorFrom(child.gameObject, argsCopy);
}
}
//set a default easeType of linear if none is supplied since eased color interpolation is nearly unrecognizable:
if (!args.Contains("easetype"))
{
args.Add("easetype", EaseType.linear);
}
//set tempColor and base fromColor:
if (target.GetComponent(typeof(GUITexture)))
{
tempColor = fromColor = target.guiTexture.color;
}
else if (target.GetComponent(typeof(GUIText)))
{
tempColor = fromColor = target.guiText.material.color;
}
else if (target.renderer)
{
tempColor = fromColor = target.renderer.material.color;
}
else if (target.light)
{
tempColor = fromColor = target.light.color;
}
//set augmented fromColor:
if (args.Contains("color"))
{
fromColor = (Color)args["color"];
}
else
{
if (args.Contains("r"))
{
fromColor.r = (float)args["r"];
}
if (args.Contains("g"))
{
fromColor.g = (float)args["g"];
}
if (args.Contains("b"))
{
fromColor.b = (float)args["b"];
}
if (args.Contains("a"))
{
fromColor.a = (float)args["a"];
}
}
//alpha or amount?
if (args.Contains("amount"))
{
fromColor.a = (float)args["amount"];
args.Remove("amount");
}
else if (args.Contains("alpha"))
{
fromColor.a = (float)args["alpha"];
args.Remove("alpha");
}
//apply fromColor:
if (target.GetComponent(typeof(GUITexture)))
{
target.guiTexture.color = fromColor;
}
else if (target.GetComponent(typeof(GUIText)))
{
target.guiText.material.color = fromColor;
}
else if (target.renderer)
{
target.renderer.material.color = fromColor;
}
else if (target.light)
{
target.light.color = fromColor;
}
//set new color arg:
args["color"] = tempColor;
//establish iTween:
args["type"] = "color";
args["method"] = "to";
Launch(target, args);
}
/// <summary>
/// Changes a GameObject's color values over time with MINIMUM customization options. If a GUIText or GUITexture component is attached, they will become the target of the animation.
/// </summary>
/// <param name="target">
/// A <see cref="GameObject"/> to be the target of the animation.
/// </param>
/// <param name="color">
/// A <see cref="Color"/> to change the GameObject's color to.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> for the time in seconds the animation will take to complete.
/// </param>
public static void ColorTo(GameObject target, Color color, float time)
{
ColorTo(target, Hash("color", color, "time", time));
}
/// <summary>
/// Changes a GameObject's color values over time with FULL customization options. If a GUIText or GUITexture component is attached, they will become the target of the animation.
/// </summary>
/// <param name="color">
/// A <see cref="Color"/> to change the GameObject's color to.
/// </param>
/// <param name="r">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the color red.
/// </param>
/// <param name="g">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the color green.
/// </param>
/// <param name="b">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the color green.
/// </param>
/// <param name="a">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the individual setting of the alpha.
/// </param>
/// <param name="namedcolorvalue">
/// A <see cref="NamedColorValue"/> or <see cref="System.String"/> for the individual setting of the alpha.
/// </param>
/// <param name="includechildren">
/// A <see cref="System.Boolean"/> for whether or not to include children of this GameObject. True by default.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete.
/// </param>
/// <param name="delay">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning.
/// </param>
/// <param name="easetype">
/// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation.
/// </param>
/// <param name="looptype">
/// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed.
/// </param>
/// <param name="onstart">
/// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation.
/// </param>
/// <param name="onstarttarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method.
/// </param>
/// <param name="onstartparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method.
/// </param>
/// <param name="onupdate">
/// A <see cref="System.String"/> for the name of a function to launch on every step of the animation.
/// </param>
/// <param name="onupdatetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method.
/// </param>
/// <param name="onupdateparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method.
/// </param>
/// <param name="oncomplete">
/// A <see cref="System.String"/> for the name of a function to launch at the end of the animation.
/// </param>
/// <param name="oncompletetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method.
/// </param>
/// <param name="oncompleteparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "oncomplete" method.
/// </param>
public static void ColorTo(GameObject target, Hashtable args)
{
//clean args:
args = iTween.CleanArgs(args);
//handle children:
if (!args.Contains("includechildren") || (bool)args["includechildren"])
{
foreach (Transform child in target.transform)
{
Hashtable argsCopy = (Hashtable)args.Clone();
argsCopy["ischild"] = true;
ColorTo(child.gameObject, argsCopy);
}
}
//set a default easeType of linear if none is supplied since eased color interpolation is nearly unrecognizable:
if (!args.Contains("easetype"))
{
args.Add("easetype", EaseType.linear);
}
//establish iTween:
args["type"] = "color";
args["method"] = "to";
Launch(target, args);
}
/// <summary>
/// Instantly changes an AudioSource's volume and pitch then returns it to it's starting volume and pitch over time with MINIMUM customization options. Default AudioSource attached to GameObject will be used (if one exists) if not supplied.
/// </summary>
/// <param name="target">
/// A <see cref="GameObject"/> to be the target of the animation which holds the AudioSource to be changed.
/// </param>
/// <param name="volume"> for the target level of volume.
/// A <see cref="System.Single"/>
/// </param>
/// <param name="pitch"> for the target pitch.
/// A <see cref="System.Single"/>
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> for the time in seconds the animation will take to complete.
/// </param>
public static void AudioFrom(GameObject target, float volume, float pitch, float time)
{
AudioFrom(target, Hash("volume", volume, "pitch", pitch, "time", time));
}
/// <summary>
/// Instantly changes an AudioSource's volume and pitch then returns it to it's starting volume and pitch over time with FULL customization options. Default AudioSource attached to GameObject will be used (if one exists) if not supplied.
/// </summary>
/// <param name="audiosource">
/// A <see cref="AudioSource"/> for which AudioSource to use.
/// </param>
/// <param name="volume">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the target level of volume.
/// </param>
/// <param name="pitch">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the target pitch.
/// </param>
/// <param name="time">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will take to complete.
/// </param>
/// <param name="delay">
/// A <see cref="System.Single"/> or <see cref="System.Double"/> for the time in seconds the animation will wait before beginning.
/// </param>
/// <param name="easetype">
/// A <see cref="EaseType"/> or <see cref="System.String"/> for the shape of the easing curve applied to the animation.
/// </param>
/// <param name="looptype">
/// A <see cref="LoopType"/> or <see cref="System.String"/> for the type of loop to apply once the animation has completed.
/// </param>
/// <param name="onstart">
/// A <see cref="System.String"/> for the name of a function to launch at the beginning of the animation.
/// </param>
/// <param name="onstarttarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onstart" method.
/// </param>
/// <param name="onstartparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onstart" method.
/// </param>
/// <param name="onupdate">
/// A <see cref="System.String"/> for the name of a function to launch on every step of the animation.
/// </param>
/// <param name="onupdatetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "onupdate" method.
/// </param>
/// <param name="onupdateparams">
/// A <see cref="System.Object"/> for arguments to be sent to the "onupdate" method.
/// </param>
/// <param name="oncomplete">
/// A <see cref="System.String"/> for the name of a function to launch at the end of the animation.
/// </param>
/// <param name="oncompletetarget">
/// A <see cref="GameObject"/> for a reference to the GameObject that holds the "oncomplete" method.