-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathExtensionMethods.cs
More file actions
684 lines (643 loc) · 27.7 KB
/
ExtensionMethods.cs
File metadata and controls
684 lines (643 loc) · 27.7 KB
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
// https://unity3d.com/learn/tutorials/topics/scripting/extension-methods
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public static class ExtensionMethods
{
/// <summary>
/// Returns a component of Type T by finding the existing one, or by instantiating one if not found.
/// </summary>
public static T EnsureComponent<T>(this GameObject go) where T : Component
{
return Wrj.Utils.EnsureComponent<T>(go);
}
/// <summary>
/// Returns a component of Type T by finding the existing one, or by instantiating one if not found.
/// </summary>
public static T EnsureComponent<T>(this Transform tform) where T : Component
{
return tform.gameObject.EnsureComponent<T>();
}
/// <summary>
/// Returns a component of Type T by finding the existing one, or by instantiating one if not found.
/// </summary>
public static T EnsureComponent<T>(this Component comp) where T : Component
{
return comp.gameObject.EnsureComponent<T>();
}
/// <summary>
/// <para>Runs an operation on every child of the game object recursively.</para>
///
/// Argument is a method that takes a GameObject.
/// </summary>
public static void PerChild(this GameObject go, Wrj.Utils.GameObjectAffector goa)
{
Wrj.Utils.AffectGORecursively(go, goa, true);
}
/// <summary>
/// Enable or disable GameObject in hierarchy.
/// </summary>
public static void ToggleActive(this GameObject go)
{
go.SetActive(!go.activeInHierarchy);
}
/// <summary>
/// Enable or disable GameObject in hierarchy.
/// </summary>
public static void ToggleActive(this Transform tForm)
{
tForm.gameObject.SetActive(!tForm.gameObject.activeInHierarchy);
}
/// <summary>
/// Returns a Vector3 with an axis forced as specified
/// </summary>
public static Vector3 With(this Vector3 orig, float? x = null, float? y = null, float? z = null)
{
return new Vector3(x ?? orig.x, y ?? orig.y, z ?? orig.z);
}
/// <summary>
/// Returns a Vector2 with an axis forced as specified
/// </summary>
public static Vector2 With(this Vector2 orig, float? x = null, float? y = null)
{
return new Vector2(x ?? orig.x, y ?? orig.y);
}
/// <summary>
/// Returns a Color with an channel forced as specified
/// </summary>
public static Color With(this Color orig, float? r = null, float? g = null, float? b = null, float? a = null)
{
return new Color(r ?? orig.r, g ?? orig.g, b ?? orig.b, a ?? orig.a);
}
public static void LocalEulerWith(this Transform tform, float? x = null, float? y = null, float? z = null)
{
tform.localEulerAngles = new Vector3(x ?? tform.localEulerAngles.x, y ?? tform.localEulerAngles.y, z ?? tform.localEulerAngles.z);
}
public static void LocalPositionWith(this Transform tform, float? x = null, float? y = null, float? z = null)
{
tform.localPosition = new Vector3(x ?? tform.localPosition.x, y ?? tform.localPosition.y, z ?? tform.localPosition.z);
}
public static void PositionWith(this Transform tform, float? x = null, float? y = null, float? z = null)
{
tform.position = new Vector3(x ?? tform.position.x, y ?? tform.position.y, z ?? tform.position.z);
}
/// <summary>
/// Returns the transforms position as moved in a direction relative to itself
/// </summary>
public static Vector3 PosInDir(this Transform tform, float forward = 0f, float right = 0f, float up = 0f)
{
return tform.position + tform.forward * forward + tform.right * right + tform.up * up;
}
/// <summary>
/// Sets the transforms position in a direction relative to itself
/// </summary>
public static void SetPosInDir(this Transform tform, float forward = 0f, float right = 0f, float up = 0f)
{
tform.position = tform.PosInDir(forward, right, up);
}
/// <summary>
/// Returns the transforms position as moved in a direction relative to the world
/// </summary>
public static Vector3 PosInWorldDir(this Transform tform, float forward = 0f, float right = 0f, float up = 0f)
{
return tform.position + Vector3.forward * forward + Vector3.right * right + Vector3.up * up;
}
/// <summary>
/// Sets the transforms position in a direction relative to the world
/// </summary>
public static void SetPosInWorldDir(this Transform tform, float forward = 0f, float right = 0f, float up = 0f)
{
tform.position = tform.PosInWorldDir(forward, right, up);
}
/// <summary>
/// Returns the transforms local position as moved in a direction relative to itself
/// </summary>
public static Vector3 LocalPosInDir(this Transform tform, float forward = 0f, float right = 0f, float up = 0f)
{
return tform.localPosition + tform.forward * forward + tform.right * right + tform.up * up;
}
/// <summary>
/// Sets the transforms local position in a direction relative to itself
/// </summary>
public static void SetLocalPosInDir(this Transform tform, float forward = 0f, float right = 0f, float up = 0f)
{
tform.localPosition = tform.LocalPosInDir(forward, right, up);
}
/// <summary>
/// Returns the transforms local position as moved in a direction relative to the world
/// </summary>
public static Vector3 LocalPosInWorldDir(this Transform tform, float forward = 0f, float right = 0f, float up = 0f)
{
return tform.localPosition + Vector3.forward * forward + Vector3.right * right + Vector3.up * up;
}
/// <summary>
/// Sets the transforms local position in a direction relative to the world
/// </summary>
public static void SetLocalPosInWorldDir(this Transform tform, float forward = 0f, float right = 0f, float up = 0f)
{
tform.localPosition = tform.LocalPosInWorldDir(forward, right, up);
}
/// <summary>
/// Returns a Vector3 using x, y and 0
/// </summary>
public static Vector3 ToVector3(this Vector2 v2)
{
return new Vector3(v2.x, v2.y, 0);
}
/// <summary>
/// Returns a Vector2 using x and y of the Vector3
/// </summary>
public static Vector2 ToVector2(this Vector3 v3)
{
return new Vector2(v3.x, v3.y);
}
public static Vector2 GetNormalizedPointInRect(this RectTransform rect, Vector2 point)
{
Vector3[] worldCorners = new Vector3[4];
rect.GetWorldCorners(worldCorners);
if (!RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, point, null, out Vector2 inResult) ||
!RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, worldCorners[0], null, out Vector2 left) ||
!RectTransformUtility.ScreenPointToLocalPointInRectangle(rect, worldCorners[2], null, out Vector2 right))
{
return default;
}
Vector2 resultPoint = new Vector2();
resultPoint.x = Mathf.InverseLerp(left.x, right.x, inResult.x);
resultPoint.y = Mathf.InverseLerp(right.y, left.y, inResult.y);
return resultPoint;
}
/// <summary>
/// Returns the angle represtented by a 2D direction
/// </summary>
public static float Angle(this Vector2 v2)
{
if (v2.x < 0)
{
return 360 - (Mathf.Atan2(v2.x, v2.y) * Mathf.Rad2Deg * -1);
}
else
{
return Mathf.Atan2(v2.x, v2.y) * Mathf.Rad2Deg;
}
}
/// <summary>
/// Returns a random element of a list.
/// </summary>
public static T GetRandom<T>(this List<T> list)
{
if (list.Count > 0)
{
return list[Random.Range(0, list.Count)];
}
return default(T);
}
/// <summary>
/// Returns a random element of an array.
/// </summary>
public static T GetRandom<T>(this T[] ar)
{
if (ar.Length > 0)
{
return ar[Random.Range(0, ar.Length)];
}
return default(T);
}
public static IList<T> Shuffle<T>(this IList<T> list, int size)
{
System.Random rnd = new System.Random();
var res = new T[size];
res[0] = list[0];
for (int i = 1; i < size; i++)
{
int j = rnd.Next(i);
res[i] = res[j];
res[j] = list[i];
}
return res;
}
public static IList<T> Shuffle<T>(this IList<T> list)
{ return list.Shuffle(list.Count); }
/// <summary>
/// <para>Converts to a multichannel clip with content only on the target channel</para>
/// <para>Clip channel count is based on current Audio Speaker Mode</para>
/// Useful for sending audio to a specific speaker in a surround sound configuration.
/// </summary>
/// <param name="originalClip"></param>
/// <param name="targetChannel"></param>
/// <returns>Multichannel audio clip with contents exclusively on the target channel</returns>
public static AudioClip SpeakerSpecificClip(this AudioClip originalClip, int targetChannel)
{
int numberOfChannels = 2;
switch (AudioSettings.speakerMode)
{
case AudioSpeakerMode.Mono:
numberOfChannels = 1;
break;
case AudioSpeakerMode.Quad:
numberOfChannels = 4;
break;
case AudioSpeakerMode.Surround:
numberOfChannels = 5;
break;
case AudioSpeakerMode.Mode5point1:
numberOfChannels = 6;
break;
case AudioSpeakerMode.Mode7point1:
numberOfChannels = 8;
break;
}
// ensure source clip has a sample, to prevent AudioClip.Create error
if (originalClip.length == 0)
{
originalClip = AudioClip.Create(originalClip.name, 1, originalClip.channels, originalClip.frequency, false);
}
// Create a new clip with the target amount of channels.
AudioClip clip = AudioClip.Create(originalClip.name + "_" + numberOfChannels, originalClip.samples, numberOfChannels, originalClip.frequency, false);
// Data for new clip
float[] audioData = new float[originalClip.samples * numberOfChannels];
// Original clip data
float[] originalAudioData = new float[originalClip.samples * originalClip.channels];
originalClip.GetData(originalAudioData, 0);
// Fill in the audio from the original clip into the target channel. Samples are interleaved by channel (L0, R0, L1, R1, etc).
int originalClipIndex = 0;
if (targetChannel < 0)
{
for (int ix = 0; ix < numberOfChannels; ix++)
{
originalClipIndex = 0;
for (int j = ix; j < audioData.Length; j += numberOfChannels)
{
audioData[j] = originalAudioData[originalClipIndex];
originalClipIndex += originalClip.channels;
}
}
}
else
{
for (int i = targetChannel; i < audioData.Length; i += numberOfChannels)
{
audioData[i] = originalAudioData[originalClipIndex];
originalClipIndex += originalClip.channels;
}
}
if (!clip.SetData(audioData, 0))
{
Debug.Log("Speaker-specific clip creation failed.");
return null;
}
return clip;
}
/// <summary>
/// Returns a log of items in a list.
/// </summary>
public static string Printable<T>(this List<T> list)
{
if (list.Count == 0) return "Empty List";
string str = "";
for (int i = 0; i < list.Count; i++)
{
str += i + ":{" + list[i].ToString() + "}";
if (i != list.Count - 1) str += ", \n";
}
return str + "\n";
}
/// <summary>
/// Returns a log of items in an array.
/// </summary>
public static string Printable<T>(this T[] array)
{
if (array.Length == 0) return "Empty Array";
string str = "";
for (int i = 0; i < array.Length; i++)
{
str += i + ":{" + array[i].ToString() + "}";
if (i != array.Length - 1) str += ", \n";
}
return str + "\n";
}
/// <summary>
/// Returns conversion to Unity Units/Meters from Feet
/// </summary>
public static float FeetToUnits(this float feet)
{
return Wrj.Utils.FromFeet(feet);
}
/// <summary>
/// Returns conversion to Feet from Unity Units/Meters
/// </summary>
public static float UnitsToFeet(this float units)
{
return Wrj.Utils.ToFeet(units);
}
/// <summary>
/// Returns conversion to Inches from Unity Units/Meters
/// </summary>
public static float InchesToUnits(this float inches)
{
return Wrj.Utils.FromInches(inches);
}
/// <summary>
/// Returns conversion to Unity Units/Meters from Inches
/// </summary>
public static float UnitsToInches(this float units)
{
return Wrj.Utils.ToInches(units);
}
/// <summary>
/// Prepends either "A" or "An" to a word depending on whether the first character is a vowel sound.
/// </summary>
/// <param name="capitalize"></param>
/// <returns>"An owl" or "A bear"</returns>
public static string PrependAn(this string word, bool capitalize = false)
{
string an = "";
bool isVowel = "aeiouAEIOU".IndexOf(word[0]) >= 0;
if (HasRulebreakingIndefiniteArticle(word))
{
isVowel = !isVowel;
}
if (isVowel)
{
an = Capitalize("an", capitalize);
}
else
{
an = Capitalize("a", capitalize);
}
return an + " " + word;
}
private static bool HasRulebreakingIndefiniteArticle(string word)
{
string list = " f h l m n r s u x 8 11 18 80 81 82 83 84 85 86 87 88 89 honest honesty hour heir honour honourable honor honorable herb use union university unit user unity universe uniform usage utility urine uranium unison euphoria utopia unanimity uterus euthanasia ewe ufo unicorn urea urethra euphemism eugenics usurper usability eunuch uni eucalyptus usury eulogy ubiquity universalism urinal universal ewer euro utensil ufology uniformitarianism upsilon ukulele urinalysis usurer ureter uridine ute eugenist eutectic eukaryote ufologist ululation usufruct eustasy unary uvula urus eucatastrophe uraeus ouabain one using ucalegon oncer usanian usufruction eusebius usar usufructuary amazigh usuress euouae ukase euclidianness uke uke uke ukie ureteroureterostomy usurping eustress unakas eudaemon ukrainian unidirectionality utahn unite uranism uranist eudemonia euth ute uranophobia euphoriant uvular ouija uropygium eugarie eugenesis uw iatmul eutripsia uey eugeny euglena ufo unigeniture univalence univalent utile utilitarian ubac eulachon unique usonian oaxaca uniquity eureka onesie universalism uberty uni ubication utonian ubicity euboean uniate euro utopographer esclop euro-american eumenides eucharist univocal euchologion euchre eunoia unix ";
return list.IndexOf(" " + word.ToLower()+ " ") >= 0;
}
private static string Capitalize(string word, bool capitalize)
{
if (!capitalize)
return char.ToLower(word[0]) + word.Substring(1);
return char.ToUpper(word[0]) + word.Substring(1);
}
public static string Capitalize(this string word)
{
return char.ToUpper(word[0]) + word.Substring(1);
}
/// <summary>
/// <para>Appends "s" or "es" based on common rules. Uses dictionary of common outliers.</para>
/// "Puma" -> "Pumas"; "Fox" -> "Foxes"; "Index" -> "Indices"
/// </summary>
public static string Pluralize(this string word, bool capitalize = false)
{
string foundIrregular = CheckForIrregularPlural(word);
if (foundIrregular != null)
{
return Capitalize(foundIrregular, capitalize);
}
char[] chars = word.ToCharArray();
char lastLetter = chars[chars.Length - 1];
char secondToLastLetter = chars[chars.Length - 2];
if ((lastLetter == 's' || lastLetter == 'z' || lastLetter == 'x') ||
(lastLetter == 'h' && (secondToLastLetter == 'c' || secondToLastLetter == 's')))
{
return word + "es";
}
if (lastLetter == 'y' && "aeiouAEIOU".IndexOf(secondToLastLetter) < 0)
{
return word.TrimEnd('y') + "ies";
}
return Capitalize(word + "s", capitalize);
}
private static string CheckForIrregularPlural(string word)
{
Dictionary<string, string> pluralMap = new Dictionary<string, string>()
{
{"addendum", "addenda"}, {"aircraft", "aircraft"}, {"alumna", "alumnae"}, {"alumnus", "alumni"}, {"analysis", "analyses"}, {"antenna", "antennae"}, {"antithesis", "antitheses"}, {"apex", "apices"}, {"appendix", "appendices"}, {"axis", "axes"}, {"bacillus", "bacilli"}, {"bacterium", "bacteria"}, {"basis", "bases"}, {"beau", "beaux"}, {"bison", "bison"}, {"bureau", "bureaux"}, {"cactus", "cacti"}, {"ch�teau", "ch�teaux"}, {"child", "children"}, {"codex", "codices"}, {"concerto", "concerti"}, {"corpus", "corpora"}, {"crisis", "crises"}, {"criterion", "criteria"}, {"curriculum", "curricula"}, {"datum", "data"}, {"deer", "deer"}, {"diagnosis", "diagnoses"}, {"die", "dice"}, {"dwarf", "dwarves"}, {"ellipsis", "ellipses"}, {"erratum", "errata"}, {"fez", "fezzes"}, {"fish", "fish"}, {"focus", "foci"}, {"foot", "feet"}, {"formula", "formulae"}, {"fungus", "fungi"}, {"genus", "genera"}, {"goose", "geese"}, {"graffito", "graffiti"}, {"grouse", "grouse"}, {"half", "halves"}, {"hoof", "hooves"}, {"hypothesis", "hypotheses"}, {"index", "indices"}, {"larva", "larvae"}, {"libretto", "libretti"}, {"loaf", "loaves"}, {"locus", "loci"}, {"louse", "lice"}, {"man", "men"}, {"matrix", "matrices"}, {"medium", "media"}, {"memorandum", "memoranda"}, {"minutia", "minutiae"}, {"moose", "moose"}, {"mouse", "mice"}, {"nebula", "nebulae"}, {"nucleus", "nuclei"}, {"oasis", "oases"}, {"offspring", "offspring"}, {"opus", "opera"}, {"ovum", "ova"}, {"ox", "oxen"}, {"parenthesis", "parentheses"}, {"phenomenon", "phenomena"}, {"phylum", "phyla"}, {"prognosis", "prognoses"}, {"quiz", "quizzes"}, {"radius", "radii"}, {"referendum", "referenda"}, {"salmon", "salmon"}, {"scarf", "scarves"}, {"self", "selves"}, {"series", "series"}, {"sheep", "sheep"}, {"shrimp", "shrimp"}, {"species", "species"}, {"stimulus", "stimuli"}, {"stratum", "strata"}, {"swine", "swine"}, {"syllabus", "syllabi"}, {"symposium", "symposia"}, {"synopsis", "synopses"}, {"tableau", "tableaux"}, {"thesis", "theses"}, {"thief", "thieves"}, {"tooth", "teeth"}, {"trout", "trout"}, {"tuna", "tuna"}, {"vertebra", "vertebrae"}, {"vertex", "vertices"}, {"vita", "vitae"}, {"vortex", "vortice"}, {"wife", "wives"}, {"wolf", "wolves"}, {"woman", "women"},
};
foreach (KeyValuePair<string, string> pair in pluralMap)
{
if (pair.Key == word.ToLower())
{
return pair.Value;
}
}
return null;
}
// Shorthand transform manipulation extensions, using MapToCurve
/// <summary>
/// <para>Move, rotate and scale the transform to the position of another over time.</para>
///
/// Strongly recommended that the target transform shares the parent of this transform.
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation[] SnapToSibling(this Transform tForm, Transform to, float duration)
{
return Wrj.Utils.MapToCurve.Linear.MatchSibling(tForm, to, duration);
}
/// <summary>
/// <para>Move, rotate and scale the transform to the position of another over time.</para>
///
/// Strongly recommended that the target transform shares the parent of this transform.
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation[] SnapToSibling(this GameObject go, Transform to, float duration)
{
return go.transform.SnapToSibling(to, duration);
}
/// <summary>
/// <para>Move, rotate and scale the transform to the position of another over time.</para>
///
/// Strongly recommended that the target transform shares the parent of this transform.
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation[] EaseSnapToSibling(this Transform tForm, Transform to, float duration)
{
return Wrj.Utils.MapToCurve.Ease.MatchSibling(tForm, to, duration);
}
/// <summary>
/// <para>Move, rotate and scale the transform to the position of another over time.</para>
///
/// Strongly recommended that the target transform shares the parent of this transform.
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation[] EaseSnapToSibling(this GameObject go, Transform to, float duration)
{
return go.transform.EaseSnapToSibling(to, duration);
}
/// <summary>
/// Move transform in local space over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Move(this Transform tForm, Vector3 to, float duration)
{
return Wrj.Utils.MapToCurve.Linear.MoveWorld(tForm, to, duration);
}
/// <summary>
/// Move transform in local space over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Move(this GameObject go, Vector3 to, float duration)
{
return go.transform.Move(to, duration);
}
/// <summary>
/// Move transform in local space over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation EaseMove(this Transform tForm, Vector3 to, float duration)
{
return Wrj.Utils.MapToCurve.Ease.MoveWorld(tForm, to, duration, false);
}
/// <summary>
/// Move transform in local space over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation EaseMove(this GameObject go, Vector3 to, float duration)
{
return go.transform.EaseMove(to, duration);
}
/// <summary>
/// Rotate transform over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation LinearRotate(this Transform tForm, Vector3 to, float duration)
{
return Wrj.Utils.MapToCurve.Linear.Rotate(tForm, to, duration);
}
/// <summary>
/// Rotate transform over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Rotate(this GameObject go, Vector3 to, float duration)
{
return go.transform.LinearRotate(to, duration);
}
/// <summary>
/// Rotate transform over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation EaseRotate(this Transform tForm, Vector3 to, float duration)
{
return Wrj.Utils.MapToCurve.Ease.Rotate(tForm, to, duration);
}
/// <summary>
/// Rotate transform over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation EaseRotate(this GameObject go, Vector3 to, float duration)
{
return go.transform.EaseRotate(to, duration);
}
/// <summary>
/// Change transforms scale over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Scale(this Transform tForm, Vector3 to, float duration)
{
return Wrj.Utils.MapToCurve.Linear.Scale(tForm, to, duration);
}
/// <summary>
/// Change transforms scale over time using a multiplier
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Scale(this Transform tForm, float to, float duration)
{
return Wrj.Utils.MapToCurve.Linear.Scale(tForm, tForm.localScale * to, duration);
}
/// <summary>
/// Change transforms scale over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Scale(this GameObject go, Vector3 to, float duration)
{
return go.transform.Scale(to, duration);
}
/// <summary>
/// Change transforms scale over time using a multiplier
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Scale(this GameObject go, float to, float duration)
{
return go.transform.Scale(to, duration);
}
/// <summary>
/// Change transforms scale over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation EaseScale(this Transform tForm, Vector3 to, float duration)
{
return Wrj.Utils.MapToCurve.Ease.Scale(tForm, to, duration);
}
/// <summary>
/// Change transforms scale over time using a multiplier
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation EaseScale(this Transform tForm, float to, float duration)
{
return Wrj.Utils.MapToCurve.Ease.Scale(tForm, tForm.localScale * to, duration);
}
/// <summary>
/// Change transforms scale over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation EaseScale(this GameObject go, Vector3 to, float duration)
{
return go.transform.EaseScale(to, duration);
}
/// <summary>
/// Change transforms scale over time using a multiplier
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation EaseScale(this GameObject go, float to, float duration)
{
return go.transform.EaseScale(to, duration);
}
/// <summary>
/// Change Color Over Time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Color(this Transform tForm, Color to, float duration)
{
return Wrj.Utils.MapToCurve.Linear.ChangeColor(tForm, to, duration);
}
/// <summary>
/// Change Color Over Time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Color(this GameObject go, Color to, float duration)
{
return go.transform.Color(to, duration);
}
/// <summary>
/// Change transparency over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Alpha(this Transform tForm, float to, float duration)
{
return Wrj.Utils.MapToCurve.Linear.FadeAlpha(tForm, to, duration);
}
/// <summary>
/// Change transparency over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Alpha(this GameObject go, float to, float duration)
{
return go.transform.Alpha(to, duration);
}
/// <summary>
/// Change image fillAmount over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation Fill(this Image img, float to, float duration)
{
return Wrj.Utils.MapToCurve.Linear.ChangeFill(img, to, duration);
}
/// <summary>
/// Change image fillAmount over time
/// </summary>
public static Wrj.Utils.MapToCurve.Manipulation EaseFill(this Image img, float to, float duration)
{
return Wrj.Utils.MapToCurve.Ease.ChangeFill(img, to, duration);
}
/// <summary>
/// Remap Float value from one range to another.
/// </summary>
public static float Remap(this float value, float sourceMin, float sourceMax, float destMin, float destMax )
{
return Wrj.Utils.Remap(value, sourceMin, sourceMax, destMin, destMax);
}
/// <summary>
/// Remap Float value from one range to another.
/// </summary>
public static float Remap(this int value, float sourceMin, float sourceMax, float destMin, float destMax )
{
return Wrj.Utils.Remap(value, sourceMin, sourceMax, destMin, destMax);
}
/// <summary>
/// Add an action to a selectable event
/// </summary>
/// <param name="selectable"></param>
/// <param name="eventTriggerType"></param>
/// <param name="onTriggerAction"></param>
public static void AddEventTrigger(this UnityEngine.UI.Selectable selectable, UnityEngine.EventSystems.EventTriggerType eventTriggerType, System.Action onTriggerAction)
{
UnityEngine.EventSystems.EventTrigger eventTrigger = selectable.gameObject.AddComponent<UnityEngine.EventSystems.EventTrigger>();
UnityEngine.EventSystems.EventTrigger.Entry pointerEvent = new UnityEngine.EventSystems.EventTrigger.Entry();
pointerEvent.eventID = eventTriggerType;
pointerEvent.callback.AddListener((x) => onTriggerAction());
eventTrigger.triggers.Add(pointerEvent);
}
}