12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238 |
- 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 Int
- public static bool ToBool(this int integer)
- {
- if (integer == 0)
- {
- return false;
- }
- else if (integer == 1)
- {
- return true;
- }
- else
- {
- throw new Exception();
- }
- }
- #endregion
- #region Bool
- public static int ToInt(this bool boolean)
- {
- if (boolean)
- {
- return 1;
- }
- else
- {
- return 0;
- }
- }
- #endregion
- #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, bool remove = false)
- {
- if (list.Count == 0)
- {
- Debug.Log("Count is 0");
- }
- int index = UnityEngine.Random.Range(0, list.Count);
- if (remove)
- {
- T result = list[index];
- list.RemoveAt(index);
- return result;
- }
- else
- {
- return list[index];
- }
- }
- 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;
- }
- }
- public static void LastRemoveAt<T>(this List<T> list, int index)
- {
- list.RemoveAt(list.Count - 1 - index);
- }
- #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 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 Remove(this string str, int startIndex, int endIndex, bool empty)
- {
- if (startIndex > endIndex)
- {
- throw new Exception();
- }
- return str.Remove(startIndex, endIndex - startIndex + 1);
- }
- 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 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, float origin, float 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, float 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 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 StreamBacScale(this Component comp)
- {
- return ManaAnim.StreamBacScale(comp.transform);
- }
- public static StreamScale StreamReForScale(this Component comp)
- {
- return ManaAnim.StreamReForScale(comp.transform);
- }
- public static StreamScale StreamReBacScale(this Component comp)
- {
- return ManaAnim.StreamReBacScale(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> startActionList = null, List<UnityAction> finishActionList = null)
- {
- return ManaAnim.CreateStreamScale(comp.transform, delayList, durationList, destKvList, originActive, destActive, curve, cg, startActionList, finishActionList);
- }
- 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> startActionList = null, List<UnityAction> finishActionList = null)
- {
- return ManaAnim.CreateStreamScale(comp.transform, delayList, durationList, destList, originActive, destActive, curve, cg, startActionList, finishActionList);
- }
- #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 Material
- 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 float GetAlpha(this Material material, string propertyName)
- {
- Color color = material.GetColor(propertyName);
- return color.a;
- }
- #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 MoveRoot 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 MoveRoot 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
- }
|