123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621 |
- using UnityEngine;
- using UnityEngine.UI;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using Random = UnityEngine.Random;
- 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 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 Move
- public static void Shake(this Component comp, float duration, int repeat, Vector3 strength, Curve curve)
- {
- ManaAnim.Shake(comp.transform, duration, repeat, strength, curve);
- }
- public static void Move2D(this Component comp, Vector3 destination, float duration, bool local, Curve curve)
- {
- ManaAnim.Move2D(comp.transform, destination, duration, local, curve);
- }
- public static void Move3D(this Component comp, Vector3 destination, float duration, bool local, Curve curve)
- {
- ManaAnim.Move3D(comp.transform, destination, duration, local, 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 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);
- }
- #endregion
- #region Alpha
- 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 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 void AddScript<T>(this Component comp)
- {
- AddScript<T>(comp.gameObject);
- }
- public static void AddScript<T>(this GameObject go)
- {
- Component comp = go.AddComponent(typeof(T));
- if (comp is Regist)
- {
- ((Regist)comp).enabled = false;
- Initializer.RegistList.Add((Regist)comp);
- }
- }
- #endregion
- #region Active
- public static void SetActive(this Component comp, bool active)
- {
- comp.gameObject.SetActive(active);
- }
- #endregion
- #region Tween
- public static void TweenForSr(this Component comp)
- {
- ManaAnim.TweenForSr(comp.transform);
- }
- public static void TweenForCG(this Component comp)
- {
- ManaAnim.TweenForCG(comp.transform);
- }
- public static void TweenForVec(this Component comp)
- {
- ManaAnim.TweenForVec(comp.transform);
- }
- public static void TweenForGra(this Component comp)
- {
- ManaAnim.TweenForGra(comp.transform);
- }
- public static void TweenForText(this Component comp)
- {
- ManaAnim.TweenForText(comp.transform);
- }
- public static void TweenForRect(this Component comp)
- {
- ManaAnim.TweenForRect(comp.transform);
- }
- public static void TweenForScale(this Component comp)
- {
- ManaAnim.TweenForScale(comp.transform);
- }
- public static void TweenForAudio(this Component comp)
- {
- ManaAnim.TweenForAudio(comp.transform);
- }
- public static void TweenBacSr(this Component comp)
- {
- ManaAnim.TweenBacSr(comp.transform);
- }
- public static void TweenBacCG(this Component comp)
- {
- ManaAnim.TweenBacCG(comp.transform);
- }
- public static void TweenBacVec(this Component comp)
- {
- ManaAnim.TweenBacVec(comp.transform);
- }
- public static void TweenBacGra(this Component comp)
- {
- ManaAnim.TweenBacGra(comp.transform);
- }
- public static void TweenBacText(this Component comp)
- {
- ManaAnim.TweenBacText(comp.transform);
- }
- public static void TweenBacRect(this Component comp)
- {
- ManaAnim.TweenBacRect(comp.transform);
- }
- public static void TweenBacScale(this Component comp)
- {
- ManaAnim.TweenBacScale(comp.transform);
- }
- public static void TweenBacAudio(this Component comp)
- {
- ManaAnim.TweenBacAudio(comp.transform);
- }
- public static void TweenConForSr(this Component comp)
- {
- ManaAnim.TweenConForSr(comp.transform);
- }
- public static void TweenConForCG(this Component comp)
- {
- ManaAnim.TweenConForCG(comp.transform);
- }
- public static void TweenConForVec(this Component comp)
- {
- ManaAnim.TweenConForVec(comp.transform);
- }
- public static void TweenConForGra(this Component comp)
- {
- ManaAnim.TweenConForGra(comp.transform);
- }
- public static void TweenConForText(this Component comp)
- {
- ManaAnim.TweenConForText(comp.transform);
- }
- public static void TweenConForRect(this Component comp)
- {
- ManaAnim.TweenConForRect(comp.transform);
- }
- public static void TweenConForScale(this Component comp)
- {
- ManaAnim.TweenConForScale(comp.transform);
- }
- public static void TweenConForAudio(this Component comp)
- {
- ManaAnim.TweenConForAudio(comp.transform);
- }
- public static void TweenConBacSr(this Component comp)
- {
- ManaAnim.TweenConBacSr(comp.transform);
- }
- public static void TweenConBacCG(this Component comp)
- {
- ManaAnim.TweenConBacCG(comp.transform);
- }
- public static void TweenConBacVec(this Component comp)
- {
- ManaAnim.TweenConBacVec(comp.transform);
- }
- public static void TweenConBacGra(this Component comp)
- {
- ManaAnim.TweenConBacGra(comp.transform);
- }
- public static void TweenConBacText(this Component comp)
- {
- ManaAnim.TweenConBacText(comp.transform);
- }
- public static void TweenConBacRect(this Component comp)
- {
- ManaAnim.TweenConBacRect(comp.transform);
- }
- public static void TweenConBacScale(this Component comp)
- {
- ManaAnim.TweenConBacScale(comp.transform);
- }
- public static void TweenConBacAudio(this Component comp)
- {
- ManaAnim.TweenConBacAudio(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 TweenText GetTweenText(this Component comp)
- {
- return ManaAnim.GetTweenText(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 TweenSr CreateTweenSr(this Component comp, float origin, float destination, float duration, bool group, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenSr(comp.transform, origin, destination, duration, group, originActive, destActive, curve);
- }
- public static TweenSr CreateTweenSr(this Component comp, float destination, float duration, bool group, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenSr(comp.transform, destination, duration, group, originActive, destActive, curve);
- }
- public static TweenSr CreateTweenSr(this Component comp, Color origin, Color destination, float duration, bool group, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenSr(comp.transform, origin, destination, duration, group, originActive, destActive, curve);
- }
- public static TweenSr CreateTweenSr(this Component comp, Color destination, float duration, bool group, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenSr(comp.transform, destination, duration, group, originActive, destActive, curve);
- }
- 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)
- {
- return ManaAnim.CreateTweenGra(comp.transform, origin, destination, duration, originActive, destActive, curve);
- }
- public static TweenGra CreateTweenGra(this Component comp, float destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenGra(comp.transform, destination, duration, originActive, destActive, curve);
- }
- public static TweenGra CreateTweenGra(this Component comp, Color origin, Color destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenGra(comp.transform, origin, destination, duration, originActive, destActive, curve);
- }
- public static TweenGra CreateTweenGra(this Component comp, Color destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenGra(comp.transform, destination, duration, originActive, destActive, curve);
- }
- public static TweenVec CreateTweenVec2D(this Component comp, Vector3 origin, Vector3 destination, float duration, bool local, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenVec2D(comp.transform, origin, destination, duration, local, originActive, destActive, curve);
- }
- public static TweenVec CreateTweenVec2D(this Component comp, Vector3 destination, float duration, bool local, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenVec2D(comp.transform, destination, duration, local, originActive, destActive, curve);
- }
- public static TweenVec CreateTweenVec3D(this Component comp, Vector3 origin, Vector3 destination, float duration, bool local, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenVec3D(comp.transform, origin, destination, duration, local, originActive, destActive, curve);
- }
- public static TweenVec CreateTweenVec3D(this Component comp, Vector3 destination, float duration, bool local, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenVec3D(comp.transform, destination, duration, local, originActive, destActive, curve);
- }
- public static TweenText CreateTweenText(this Component comp, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenText(comp.transform, origin, destination, duration, originActive, destActive, curve);
- }
- public static TweenText CreateTweenText(this Component comp, float destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenText(comp.transform, destination, duration, originActive, destActive, curve);
- }
- public static TweenRect CreateTweenRect(this Component comp, Vector3 origin, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenRect(comp.transform, origin, destination, duration, originActive, destActive, curve);
- }
- public static TweenRect CreateTweenRect(this Component comp, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenRect(comp.transform, destination, duration, originActive, destActive, curve);
- }
- public static TweenScale CreateTweenScale(this Component comp, Vector3 origin, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenScale(comp.transform, origin, destination, duration, originActive, destActive, curve);
- }
- public static TweenScale CreateTweenScale(this Component comp, Vector3 destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenScale(comp.transform, destination, duration, originActive, destActive, curve);
- }
- public static TweenAudio CreateTweenAudio(this Component comp, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenAudio(comp.transform, origin, destination, duration, originActive, destActive, curve);
- }
- public static TweenAudio CreateTweenAudio(this Component comp, float destination, float duration, bool originActive, bool destActive, Curve curve)
- {
- return ManaAnim.CreateTweenAudio(comp.transform, destination, duration, originActive, destActive, curve);
- }
-
- #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 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 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 AddComponent
- public static T AddComponent<T>(this Component comp) where T : Component
- {
- return comp.transform.gameObject.AddComponent<T>();
- }
- #endregion
- }
|