1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237 |
- 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 TweenOutline TweenForOutline(this Component comp)
- {
- return ManaAnim.TweenForOutline(comp.transform);
- }
- 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 TweenOutline TweenBacOutline(this Component comp)
- {
- return ManaAnim.TweenBacOutline(comp.transform);
- }
- 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 TweenOutline TweenReForOutline(this Component comp)
- {
- return ManaAnim.TweenReForOutline(comp.transform);
- }
- 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 TweenOutline TweenReBacOutline(this Component comp)
- {
- return ManaAnim.TweenReBacOutline(comp.transform);
- }
- 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 TweenOutline GetTweenOutline(this Component comp)
- {
- return ManaAnim.GetTweenOutline(comp.transform);
- }
- 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 TweenOutline CreateTweenOutline(this Component comp, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenOutline(comp.transform, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenOutline CreateTweenOutline(this Component comp, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenOutline(comp.transform, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenOutline CreateTweenOutline(this Component comp, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenOutline(comp.transform, origin, destination, duration, originActive, destActive, curve, cg);
- }
- public static TweenOutline CreateTweenOutline(this Component comp, Color destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false)
- {
- return ManaAnim.CreateTweenOutline(comp.transform, 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
- }
|