123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191 |
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Events;
- using System;
- using System.Linq;
- using System.Collections;
- using System.Collections.Generic;
- using Random = UnityEngine.Random;
- public enum LocatePos
- {
- Left,
- Right,
- Center,
- Up,
- Down,
- Middle,
- }
- public static class Extension
- {
- #region List
- public static T Last<T>(this List<T> list, int index)
- {
- return list[list.Count - 1 - index];
- }
- public static T Prev<T>(this List<T> list, int index)
- {
- return list[(index + list.Count - 1)%list.Count];
- }
- public static T Next<T>(this List<T> list, int index)
- {
- return list[(index + 1)%list.Count];
- }
- public static T Random<T>(this List<T> list)
- {
- if (list.Count == 0)
- {
- Debug.Log("Count is 0");
- }
- return list[UnityEngine.Random.Range(0, list.Count)];
- }
- public static bool Valid<T>(this List<T> list)
- {
- if (list == null || list.Count == 0)
- {
- return false;
- }
- else
- {
- return true;
- }
- }
- public static bool UniqueAdd<T>(this List<T> list, T obj)
- {
- if (list.Contains(obj) == false)
- {
- list.Add(obj);
- return true;
- }
- else
- {
- return false;
- }
- }
- #endregion
- #region UGUI
- public static void Resize(this Image image, float ratioX, float ratioY)
- {
- Vector2 newSize = image.sprite.rect.size;
- newSize.x *= ratioX;
- newSize.y *= ratioY;
- image.rectTransform.sizeDelta = newSize;
- }
- #endregion
- #region Event
- public static void SetButtonEvent(this Button button, UnityAction onClick)
- {
- button.onClick = new Button.ButtonClickedEvent();
- button.onClick.AddListener(onClick);
- }
- public static void AddButtonEvent(this Button button, UnityAction onClick)
- {
- button.onClick.AddListener(onClick);
- }
- public static void PushButtonEvent(this Button button, UnityAction onClick)
- {
- Button.ButtonClickedEvent click = button.onClick;
- button.onClick = new Button.ButtonClickedEvent();
- button.onClick.AddListener(onClick);
- button.onClick.AddListener(click.Invoke);
- }
- public static void AddButtonEventOnetime(this Button button, UnityAction onClick)
- {
- onClick += () =>
- {
- button.onClick.RemoveListener(onClick);
- };
- button.onClick.AddListener(onClick);
- }
- public static void PushButtonEventOnetime(this Button button, UnityAction onClick)
- {
- onClick += () =>
- {
- button.onClick.RemoveListener(onClick);
- };
- Button.ButtonClickedEvent click = button.onClick;
- button.onClick = new Button.ButtonClickedEvent();
- button.onClick.AddListener(onClick);
- button.onClick.AddListener(click.Invoke);
- }
- #endregion
- #region Equal
- public static bool Equal(this int i1, int i2, int accuracy = 0)
- {
- if (Math.Abs(i1 - i2) < accuracy)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static bool Equal(this float f1, float f2, float accuracy = 0.0005f)
- {
- if (Math.Abs(f1 - f2) < accuracy)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static bool Equal(this Color c1, Color c2, float accuracy = 0.0005f)
- {
- if (Math.Abs(c1.r - c2.r) < accuracy && Math.Abs(c1.g - c2.g) < accuracy && Math.Abs(c1.b - c2.b) < accuracy && Math.Abs(c1.a - c2.a) < accuracy)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static bool Equal(this Vector2 v1, Vector2 v2, float accuracy = 0.0005f)
- {
- if (Math.Abs(v1.x - v2.x) < accuracy && Math.Abs(v1.y - v2.y) < accuracy)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- public static bool Equal(this Vector3 v1, Vector3 v2, float accuracy = 0.0005f)
- {
- if (Math.Abs(v1.x - v2.x) < accuracy && Math.Abs(v1.y - v2.y) < accuracy && Math.Abs(v1.z - v2.z) < accuracy)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- #endregion
- #region Move
- public static Shake Shake(this Component comp, float duration, int repeat, Vector3 strength, Curve curve)
- {
- return ManaAnim.Shake(comp.transform, duration, repeat, strength, curve);
- }
- public static Move2D Move2D(this Component comp, Vector3 destination, float duration, bool local, Curve curve)
- {
- return ManaAnim.Move2D(comp.transform, destination, duration, local, curve);
- }
- public static Move3D Move3D(this Component comp, Vector3 destination, float duration, bool local, Curve curve)
- {
- return ManaAnim.Move3D(comp.transform, destination, duration, local, curve);
- }
- public static Move2D MoveOffset2D(this Component comp, Vector3 offset, float duration, bool local, Curve curve)
- {
- return ManaAnim.MoveOffset2D(comp.transform, offset, duration, local, curve);
- }
- public static Move3D MoveOffset3D(this Component comp, Vector3 offset, float duration, bool local, Curve curve)
- {
- return ManaAnim.MoveOffset3D(comp.transform, offset, duration, local, curve);
- }
- public static Zoom2D Zoom2D(this Transform target, float origin, float destination, float duration, float stay, Transform targetZoom, Curve curve)
- {
- return ManaAnim.Zoom2D(target, origin, destination, duration, stay, targetZoom, curve);
- }
- public static Zoom2D Zoom2D(this Transform target, float destination, float duration, float stay, Transform targetZoom, Curve curve)
- {
- return ManaAnim.Zoom2D(target, destination, duration, stay, targetZoom, curve);
- }
- public static Shake GetShake(this Component comp)
- {
- return ManaAnim.GetShake(comp.transform);
- }
- public static Move2D GetMove2D(this Component comp)
- {
- return ManaAnim.GetMove2D(comp.transform);
- }
- public static Move3D GetMove3D(this Component comp)
- {
- return ManaAnim.GetMove3D(comp.transform);
- }
- public static Zoom2D GetZoom2D(this Component comp)
- {
- return ManaAnim.GetZoom2D(comp.transform);
- }
- public static Shake CreateShake(this Component comp)
- {
- return ManaAnim.CreateShake(comp.transform);
- }
- public static Move2D CreateMove2D(this Component comp)
- {
- return ManaAnim.CreateMove2D(comp.transform);
- }
- public static Move3D CreateMove3D(this Component comp)
- {
- return ManaAnim.CreateMove3D(comp.transform);
- }
- public static Zoom2D CreateZoom2D(this Component comp)
- {
- return ManaAnim.CreateZoom2D(comp.transform);
- }
- #endregion
- #region Alpha
- public static void SetAlpha(this Material material, float alpha, string propertyName)
- {
- Color color = material.GetColor(propertyName);
- color.a = alpha;
- material.SetColor(propertyName, color);
- }
- public static void SetAlpha(this Graphic graphic, float alpha)
- {
- graphic.color = new Color(graphic.color.r, graphic.color.g, graphic.color.b, alpha);
- }
- public static void SetAlpha(this TextMesh textMesh, float alpha)
- {
- textMesh.color = new Color(textMesh.color.r, textMesh.color.g, textMesh.color.b, alpha);
- }
- public static void SetAlpha(this SpriteRenderer sR, float alpha)
- {
- sR.color = new Color(sR.color.r, sR.color.g, sR.color.b, alpha);
- }
- #endregion
- #region String
- public static T ToEnum<T>(this string str)
- {
- return (T)Enum.Parse(typeof(T), str);
- }
- #endregion
- #region Sprite
- public static Sprite GetSprite(this Component comp)
- {
- return comp.GetComponent<Image>().sprite;
- }
- #endregion
- #region String
- public static string Replace(this string str, int startIndex, int endIndex, string newStr)
- {
- str = str.Remove(startIndex, endIndex - startIndex + 1);
- str = str.Insert(startIndex, newStr);
- return str;
- }
- public static string Between(this string str, int startIndex, int endIndex)
- {
- if (startIndex > endIndex)
- {
- return "";
- }
- else if (startIndex == endIndex)
- {
- return str[startIndex].ToString();
- }
- else
- {
- return str.Substring(startIndex, endIndex - startIndex + 1);
- }
- }
- #endregion
- #region Regist
- public static T AddScript<T>(this Component comp) where T : Component
- {
- return AddScript<T>(comp.gameObject);
- }
- public static T AddScript<T>(this GameObject go) where T : Component
- {
- Component comp = go.AddComponent(typeof(T));
- if (comp is Regist)
- {
- Regist regist = (Regist) comp;
- regist.enabled = false;
- regist.RegistImmed();
- Initializer.RegistList.Add(regist);
- return (T) comp;
- }
- else
- {
- throw new Exception();
- }
- }
- #endregion
- #region Active
- public static void SetActive(this Component comp, bool active)
- {
- comp.gameObject.SetActive(active);
- }
- #endregion
- #region Tween
- public static TweenSr TweenForSr(this Component comp)
- {
- return ManaAnim.TweenForSr(comp.transform);
- }
- public static TweenCG TweenForCG(this Component comp)
- {
- return ManaAnim.TweenForCG(comp.transform);
- }
- public static TweenVec TweenForVec(this Component comp)
- {
- return ManaAnim.TweenForVec(comp.transform);
- }
- public static TweenGra TweenForGra(this Component comp)
- {
- return ManaAnim.TweenForGra(comp.transform);
- }
- public static TweenFont TweenForFont(this Component comp)
- {
- return ManaAnim.TweenForFont(comp.transform);
- }
- public static TweenRect TweenForRect(this Component comp)
- {
- return ManaAnim.TweenForRect(comp.transform);
- }
- public static TweenScale TweenForScale(this Component comp)
- {
- return ManaAnim.TweenForScale(comp.transform);
- }
- public static TweenAudio TweenForAudio(this Component comp)
- {
- return ManaAnim.TweenForAudio(comp.transform);
- }
- public static TweenAudio TweenForAudio(this AudioSource audioSource)
- {
- return ManaAnim.TweenForAudio(audioSource);
- }
- public static TweenNumber TweenForNumber(this Component comp)
- {
- return ManaAnim.TweenForNumber(comp.transform);
- }
- public static TweenSr TweenBacSr(this Component comp)
- {
- return ManaAnim.TweenBacSr(comp.transform);
- }
- public static TweenCG TweenBacCG(this Component comp)
- {
- return ManaAnim.TweenBacCG(comp.transform);
- }
- public static TweenVec TweenBacVec(this Component comp)
- {
- return ManaAnim.TweenBacVec(comp.transform);
- }
- public static TweenGra TweenBacGra(this Component comp)
- {
- return ManaAnim.TweenBacGra(comp.transform);
- }
- public static TweenFont TweenBacFont(this Component comp)
- {
- return ManaAnim.TweenBacFont(comp.transform);
- }
- public static TweenRect TweenBacRect(this Component comp)
- {
- return ManaAnim.TweenBacRect(comp.transform);
- }
- public static TweenScale TweenBacScale(this Component comp)
- {
- return ManaAnim.TweenBacScale(comp.transform);
- }
- public static TweenAudio TweenBacAudio(this Component comp)
- {
- return ManaAnim.TweenBacAudio(comp.transform);
- }
- public static TweenAudio TweenBacAudio(this AudioSource audioSource)
- {
- return ManaAnim.TweenBacAudio(audioSource);
- }
- public static TweenNumber TweenBacNumber(this Component comp)
- {
- return ManaAnim.TweenBacNumber(comp.transform);
- }
- public static TweenSr TweenReForSr(this Component comp)
- {
- return ManaAnim.TweenReForSr(comp.transform);
- }
- public static TweenCG TweenReForCG(this Component comp)
- {
- return ManaAnim.TweenReForCG(comp.transform);
- }
- public static TweenVec TweenReForVec(this Component comp)
- {
- return ManaAnim.TweenReForVec(comp.transform);
- }
- public static TweenGra TweenReForGra(this Component comp)
- {
- return ManaAnim.TweenReForGra(comp.transform);
- }
- public static TweenFont TweenReForFont(this Component comp)
- {
- return ManaAnim.TweenReForFont(comp.transform);
- }
- public static TweenRect TweenReForRect(this Component comp)
- {
- return ManaAnim.TweenReForRect(comp.transform);
- }
- public static TweenScale TweenReForScale(this Component comp)
- {
- return ManaAnim.TweenReForScale(comp.transform);
- }
- public static TweenAudio TweenReForAudio(this Component comp)
- {
- return ManaAnim.TweenReForAudio(comp.transform);
- }
- public static TweenAudio TweenReForAudio(this AudioSource audioSource)
- {
- return ManaAnim.TweenReForAudio(audioSource);
- }
- public static TweenNumber TweenReForNumber(this Component comp)
- {
- return ManaAnim.TweenReForNumber(comp.transform);
- }
- public static TweenSr TweenReBacSr(this Component comp)
- {
- return ManaAnim.TweenReBacSr(comp.transform);
- }
- public static TweenCG TweenReBacCG(this Component comp)
- {
- return ManaAnim.TweenReBacCG(comp.transform);
- }
- public static TweenVec TweenReBacVec(this Component comp)
- {
- return ManaAnim.TweenReBacVec(comp.transform);
- }
- public static TweenGra TweenReBacGra(this Component comp)
- {
- return ManaAnim.TweenReBacGra(comp.transform);
- }
- public static TweenFont TweenReBacFont(this Component comp)
- {
- return ManaAnim.TweenReBacFont(comp.transform);
- }
- public static TweenRect TweenReBacRect(this Component comp)
- {
- return ManaAnim.TweenReBacRect(comp.transform);
- }
- public static TweenScale TweenReBacScale(this Component comp)
- {
- return ManaAnim.TweenReBacScale(comp.transform);
- }
- public static TweenAudio TweenReBacAudio(this Component comp)
- {
- return ManaAnim.TweenReBacAudio(comp.transform);
- }
- public static TweenAudio TweenReBacAudio(this AudioSource audioSource)
- {
- return ManaAnim.TweenReBacAudio(audioSource);
- }
- public static TweenNumber TweenReBacNumber(this Component comp)
- {
- return ManaAnim.TweenReBacNumber(comp.transform);
- }
- public static TweenSr TweenConForSr(this Component comp)
- {
- return ManaAnim.TweenConForSr(comp.transform);
- }
- public static TweenCG TweenConForCG(this Component comp)
- {
- return ManaAnim.TweenConForCG(comp.transform);
- }
- public static TweenVec TweenConForVec(this Component comp)
- {
- return ManaAnim.TweenConForVec(comp.transform);
- }
- public static TweenGra TweenConForGra(this Component comp)
- {
- return ManaAnim.TweenConForGra(comp.transform);
- }
- public static TweenFont TweenConForFont(this Component comp)
- {
- return ManaAnim.TweenConForFont(comp.transform);
- }
- public static TweenRect TweenConForRect(this Component comp)
- {
- return ManaAnim.TweenConForRect(comp.transform);
- }
- public static TweenScale TweenConForScale(this Component comp)
- {
- return ManaAnim.TweenConForScale(comp.transform);
- }
- public static TweenAudio TweenConForAudio(this Component comp)
- {
- return ManaAnim.TweenConForAudio(comp.transform);
- }
- public static TweenAudio TweenConForAudio(this AudioSource audioSource)
- {
- return ManaAnim.TweenConForAudio(audioSource);
- }
- public static TweenNumber TweenConForNumber(this Component comp)
- {
- return ManaAnim.TweenConForNumber(comp.transform);
- }
- public static TweenSr TweenConBacSr(this Component comp)
- {
- return ManaAnim.TweenConBacSr(comp.transform);
- }
- public static TweenCG TweenConBacCG(this Component comp)
- {
- return ManaAnim.TweenConBacCG(comp.transform);
- }
- public static TweenVec TweenConBacVec(this Component comp)
- {
- return ManaAnim.TweenConBacVec(comp.transform);
- }
- public static TweenGra TweenConBacGra(this Component comp)
- {
- return ManaAnim.TweenConBacGra(comp.transform);
- }
- public static TweenFont TweenConBacFont(this Component comp)
- {
- return ManaAnim.TweenConBacFont(comp.transform);
- }
- public static TweenRect TweenConBacRect(this Component comp)
- {
- return ManaAnim.TweenConBacRect(comp.transform);
- }
- public static TweenScale TweenConBacScale(this Component comp)
- {
- return ManaAnim.TweenConBacScale(comp.transform);
- }
- public static TweenAudio TweenConBacAudio(this Component comp)
- {
- return ManaAnim.TweenConBacAudio(comp.transform);
- }
- public static TweenAudio TweenConBacAudio(this AudioSource audioSource)
- {
- return ManaAnim.TweenConBacAudio(audioSource);
- }
- public static TweenNumber TweenConBacNumber(this Component comp)
- {
- return ManaAnim.TweenConBacNumber(comp.transform);
- }
- public static TweenSr GetTweenSr(this Component comp)
- {
- return ManaAnim.GetTweenSr(comp.transform);
- }
- public static TweenCG GetTweenCG(this Component comp)
- {
- return ManaAnim.GetTweenCG(comp.transform);
- }
- public static TweenVec GetTweenVec(this Component comp)
- {
- return ManaAnim.GetTweenVec(comp.transform);
- }
- public static TweenGra GetTweenGra(this Component comp)
- {
- return ManaAnim.GetTweenGra(comp.transform);
- }
- public static TweenFont GetTweenFont(this Component comp)
- {
- return ManaAnim.GetTweenFont(comp.transform);
- }
- public static TweenRect GetTweenRect(this Component comp)
- {
- return ManaAnim.GetTweenRect(comp.transform);
- }
- public static TweenScale GetTweenScale(this Component comp)
- {
- return ManaAnim.GetTweenScale(comp.transform);
- }
- public static TweenAudio GetTweenAudio(this Component comp)
- {
- return ManaAnim.GetTweenAudio(comp.transform);
- }
- public static TweenAudio GetTweenAudio(this AudioSource audioSource)
- {
- return ManaAnim.GetTweenAudio(audioSource);
- }
- public static TweenNumber GetTweenNumber(this Component comp)
- {
- return ManaAnim.GetTweenNumber(comp.transform);
- }
- public static TweenSr CreateTweenSr(this Component comp, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false, bool group = false)
- {
- return ManaAnim.CreateTweenSr(comp.transform, origin, destination, duration, originActive, destActive, curve, cg, group);
- }
- public static TweenSr CreateTweenSr(this Component comp, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false, bool group = false)
- {
- return ManaAnim.CreateTweenSr(comp.transform, destination, duration, originActive, destActive, curve, cg, group);
- }
- public static TweenSr CreateTweenSr(this Component comp, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false, bool group = false)
- {
- return ManaAnim.CreateTweenSr(comp.transform, origin, destination, duration, originActive, destActive, curve, cg, group);
- }
- public static TweenSr CreateTweenSr(this Component comp, Color destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false, bool group = false)
- {
- return ManaAnim.CreateTweenSr(comp.transform, destination, duration, originActive, destActive, curve, cg, group);
- }
- public static TweenCG CreateTweenCG(this Component comp, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenCG(comp.transform, origin, destination, duration, originActive, destActive, curve);
- }
- public static TweenCG CreateTweenCG(this Component comp, float destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenCG(comp.transform, destination, duration, originActive, destActive, curve);
- }
- public static TweenGra CreateTweenGra(this Component comp, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenGra(comp.transform, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenGra CreateTweenGra(this Component comp, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenGra(comp.transform, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenGra CreateTweenGra(this Component comp, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenGra(comp.transform, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenGra CreateTweenGra(this Component comp, Color destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenGra(comp.transform, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenVec CreateTweenVec2D(this Component comp, Vector3 origin, Vector3 destination, float duration, bool local, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenVec2D(comp.transform, origin, destination, duration, local, originActive, destActive, curve, cg);
- }
- public static TweenVec CreateTweenVec2D(this Component comp, Vector3 destination, float duration, bool local, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenVec2D(comp.transform, destination, duration, local, originActive, destActive, curve, cg);
- }
- public static TweenVec CreateTweenVec3D(this Component comp, Vector3 origin, Vector3 destination, float duration, bool local, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenVec3D(comp.transform, origin, destination, duration, local, originActive, destActive, curve, cg);
- }
- public static TweenVec CreateTweenVec3D(this Component comp, Vector3 destination, float duration, bool local, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenVec3D(comp.transform, destination, duration, local, originActive, destActive, curve, cg);
- }
- public static TweenVec CreateTweenVecOffset2D(this Component comp, Vector3 offset, float duration, bool local, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenVecOffset2D(comp.transform, offset, duration, local, originActive, destActive, curve, cg);
- }
- public static TweenVec CreateTweenVecOffset3D(this Component comp, Vector3 offset, float duration, bool local, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenVecOffset3D(comp.transform, offset, duration, local, originActive, destActive, curve, cg);
- }
- public static TweenFont CreateTweenFont(this Component comp, int origin, int destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenFont(comp.transform, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenFont CreateTweenFont(this Component comp, int destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenFont(comp.transform, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenRect CreateTweenRect(this Component comp, Vector3 origin, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenRect(comp.transform, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenRect CreateTweenRect(this Component comp, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenRect(comp.transform, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenScale CreateTweenScale(this Component comp, Vector3 origin, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenScale(comp.transform, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenScale CreateTweenScale(this Component comp, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenScale(comp.transform, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenAudio CreateTweenAudio(this Component comp, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenAudio(comp.transform, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenAudio CreateTweenAudio(this Component comp, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenAudio(comp.transform, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenAudio CreateTweenAudio(this AudioSource audioSource, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenAudio(audioSource, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenAudio CreateTweenAudio(this AudioSource audioSource, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenAudio(audioSource, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenNumber CreateTweenNumber(this Component comp, int origin, int destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenNumber(comp.transform, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenNumber CreateTweenNumber(this Component comp, int destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenNumber(comp.transform, destination, duration, originActive, destActive, curve, cg);
- }
- #endregion
- #region Stream
- public static StreamScale StreamForScale(this Component comp)
- {
- return ManaAnim.StreamForScale(comp.transform);
- }
- public static StreamScale GetStreamScale(this Component comp)
- {
- return ManaAnim.GetStreamScale(comp.transform);
- }
- public static StreamScale CreateStreamScale(this Component comp, List<float> delayList, List<float> durationList, List<VecPair> destKvList, bool originActive, bool destActive, Curve curve, bool cg = false, List<UnityAction> actionList = null)
- {
- return ManaAnim.CreateStreamScale(comp.transform, delayList, durationList, destKvList, originActive, destActive, curve, cg, actionList);
- }
- public static StreamScale CreateStreamScale(this Component comp, List<float> delayList, List<float> durationList, List<Vector3> destList, bool originActive, bool destActive, Curve curve, bool cg = false, List<UnityAction> actionList = null)
- {
- return ManaAnim.CreateStreamScale(comp.transform, delayList, durationList, destList, originActive, destActive, curve, cg, actionList);
- }
- #endregion
- #region Collider
- public static void SetCollider(this Component comp, bool active)
- {
- BoxCollider2D collider = comp.GetComponent<BoxCollider2D>();
- if (collider)
- {
- collider.enabled = active;
- }
- }
- public static void SetCollider(this GameObject gameObject, bool active)
- {
- gameObject.GetComponent<BoxCollider2D>().enabled = active;
- }
- #endregion
- #region GetChild
- public static Transform GetChild(this Component comp, int index)
- {
- return comp.transform.GetChild(index);
- }
- public static Transform GetChild(this GameObject gameObject, int index)
- {
- return gameObject.transform.GetChild(index);
- }
- #endregion
- #region SetParent
- public static void SetParent(this Component comp, Transform par)
- {
- comp.transform.SetParent(par);
- }
- public static void SetParent(this GameObject go, Transform par)
- {
- go.transform.SetParent(par);
- }
- #endregion
- #region ScrollRect
- public static Move Locate(this ScrollRect scrollRect, int index, float duration, Curve curve, LocatePos locatePos)
- {
- LayoutGroup layoutGroup = scrollRect.content.GetComponent<LayoutGroup>();
- RectTransform tra1 = scrollRect.GetComponent<RectTransform>();
- Rect rect1 = tra1.rect;
- RectTransform tra2 = scrollRect.content.GetChild(index).GetComponent<RectTransform>();
- Rect rect2 = tra2.rect;
- if (locatePos == LocatePos.Up)
- {
- Vector3 itemPos = tra2.position + new Vector3(0, rect2.yMax, 0);
- Vector3 targetPos = tra1.position + new Vector3(0, rect1.yMax - layoutGroup.padding.top, 0);
- Vector3 offset = targetPos - itemPos;
- offset.x = 0;
- return scrollRect.content.MoveOffset2D(offset, duration, false, curve);
- }
- if (locatePos == LocatePos.Down)
- {
- Vector3 itemPos = tra2.position + new Vector3(0, rect2.yMin, 0);
- Vector3 targetPos = tra1.position + new Vector3(0, rect1.yMin + layoutGroup.padding.bottom, 0);
- Vector3 offset = targetPos - itemPos;
- offset.x = 0;
-
- return scrollRect.content.MoveOffset2D(offset, duration, false, curve);
- }
- else if (locatePos == LocatePos.Middle)
- {
- Vector3 itemPos = tra2.position + new Vector3(rect2.center.x, rect2.center.y, 0);
- Vector3 targetPos = tra1.position + new Vector3(rect1.center.x, rect1.center.y, 0);
- Vector3 offset = targetPos - itemPos;
- offset.x = 0;
- return scrollRect.content.MoveOffset2D(offset, duration, false, curve);
- }
- if (locatePos == LocatePos.Left)
- {
- Vector3 itemPos = tra2.position + new Vector3(rect2.xMin, 0, 0);
- Vector3 targetPos = tra1.position + new Vector3(rect1.xMin + layoutGroup.padding.left, 0, 0);
- Vector3 offset = targetPos - itemPos;
- offset.y = 0;
- return scrollRect.content.MoveOffset2D(offset, duration, false, curve);
- }
- if (locatePos == LocatePos.Right)
- {
- Vector3 itemPos = tra2.position + new Vector3(rect2.xMax, 0, 0);
- Vector3 targetPos = tra1.position + new Vector3(rect1.xMax - layoutGroup.padding.right, 0, 0);
- Vector3 offset = targetPos - itemPos;
- offset.y = 0;
- return scrollRect.content.MoveOffset2D(offset, duration, false, curve);
- }
- if (locatePos == LocatePos.Center)
- {
- Vector3 itemPos = tra2.position + new Vector3(rect2.center.x, rect2.center.y, 0);
- Vector3 targetPos = tra1.position + new Vector3(rect1.center.x, rect1.center.y, 0);
- Vector3 offset = targetPos - itemPos;
- offset.y = 0;
- return scrollRect.content.MoveOffset2D(offset, duration, false, curve);
- }
- throw new Exception();
- }
- public static Move Locate(this ScrollRect scrollRect, Transform item, float duration, Curve curve, LocatePos locatePos)
- {
- return scrollRect.Locate(item.GetSiblingIndex(), duration, curve, locatePos);
- }
- #endregion
- #region Transform
- public static void SetX(this Transform tra, float x)
- {
- tra.position = new Vector3(x, tra.position.y, tra.position.z);
- }
- public static void SetY(this Transform tra, float y)
- {
- tra.position = new Vector3(tra.position.x, y, tra.position.z);
- }
- public static void SetZ(this Transform tra, float z)
- {
- tra.position = new Vector3(tra.position.x, tra.position.y, z);
- }
- public static void SetLX(this Transform tra, float x)
- {
- tra.localPosition = new Vector3(x, tra.localPosition.y, tra.localPosition.z);
- }
- public static void SetLY(this Transform tra, float y)
- {
- tra.localPosition = new Vector3(tra.localPosition.x, y, tra.localPosition.z);
- }
- public static void SetLZ(this Transform tra, float z)
- {
- tra.localPosition = new Vector3(tra.localPosition.x, tra.localPosition.y, z);
- }
- public static void SetEX(this Transform tra, float x)
- {
- tra.eulerAngles = new Vector3(x, tra.eulerAngles.y, tra.eulerAngles.z);
- }
- public static void SetEY(this Transform tra, float y)
- {
- tra.eulerAngles = new Vector3(tra.eulerAngles.x, y, tra.eulerAngles.z);
- }
- public static void SetEZ(this Transform tra, float z)
- {
- tra.eulerAngles = new Vector3(tra.eulerAngles.x, tra.eulerAngles.y, z);
- }
- public static Vector3 GetScale(this Transform tra)
- {
- Vector3 scale = tra.localScale;
- while (tra.parent != null)
- {
- float x = scale.x * tra.parent.localScale.x;
- float y = scale.y * tra.parent.localScale.y;
- float z = scale.z * tra.parent.localScale.z;
- scale = new Vector3(x, y, z);
- tra = tra.parent;
- }
- return scale;
- }
- #endregion
- #region Dictionary
- public static T2 Random<T1, T2>(this Dictionary<T1, T2> dic)
- {
- return dic.Values.ToList().Random();
- }
- public static bool UniqueAdd<T1, T2>(this Dictionary<T1, T2> dic, T1 t1, T2 t2)
- {
- if (dic.ContainsKey(t1))
- {
- return false;
- }
- else
- {
- dic.Add(t1, t2);
- return true;
- }
- }
- #endregion
- #region UnityAction
- public static void SafeInvoke(this UnityAction action)
- {
- if (action != null)
- {
- action.Invoke();
- }
- }
- public static void SafeInvoke<T>(this UnityAction<T> action, T t)
- {
- if (action != null)
- {
- action.Invoke(t);
- }
- }
- #endregion
- #region AddComponent
- public static T AddComponent<T>(this Component comp) where T : Component
- {
- return comp.transform.gameObject.AddComponent<T>();
- }
- #endregion
- }
|