using UnityEngine; using UnityEngine.UI; using System; using System.Collections; using System.Collections.Generic; using UnityEngine.Events; using Random = UnityEngine.Random; public static class Extension { #region List public static T Last(this List list, int index) { return list[list.Count - 1 - index]; } public static T Random(this List list) { if (list.Count == 0) { Debug.Log("Count is 0"); } return list[UnityEngine.Random.Range(0, list.Count)]; } public static bool Valid(this List list) { if (list == null || list.Count == 0) { return false; } else { return true; } } public static bool UniqueAdd(this List list, T obj) { if (list.Contains(obj) == false) { list.Add(obj); 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 Zoom2D Zoom2D(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(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 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().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(this Component comp) { AddScript(comp.gameObject); } public static void AddScript(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 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 TweenText TweenForText(this Component comp) { return ManaAnim.TweenForText(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 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 TweenText TweenBacText(this Component comp) { return ManaAnim.TweenBacText(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 TweenNumber TweenBacNumber(this Component comp) { return ManaAnim.TweenBacNumber(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 TweenText TweenConForText(this Component comp) { return ManaAnim.TweenConForText(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 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 TweenText TweenConBacText(this Component comp) { return ManaAnim.TweenConBacText(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 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 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 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 TweenText CreateTweenText(this Component comp, float origin, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false) { return ManaAnim.CreateTweenText(comp.transform, origin, destination, duration, originActive, destActive, curve, cg); } public static TweenText CreateTweenText(this Component comp, float destination, float duration, bool originActive, bool destActive, Curve curve, bool cg = false) { return ManaAnim.CreateTweenText(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 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 Collider public static void SetCollider(this Component comp, bool active) { BoxCollider2D collider = comp.GetComponent(); if (collider) { collider.enabled = active; } } public static void SetCollider(this GameObject gameObject, bool active) { gameObject.GetComponent().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 UnityAction public static void SafeInvoke(this UnityAction action) { if (action != null) { action.Invoke(); } } #endregion #region AddComponent public static T AddComponent(this Component comp) where T : Component { return comp.transform.gameObject.AddComponent(); } #endregion }