public static TweenScript TnUguiAlpha(this RectTransform rectTrans, float?from, float to, float time, float delayTime = 0, bool isChild = false) { float fromTmp = from ?? 1; if (from == null) { if (rectTrans.GetComponent <Graphic>() != null) { fromTmp = from ?? rectTrans.GetComponent <Graphic>().color.a; } } TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.animGameObject = rectTrans.gameObject; tweenTmp.animType = AnimType.UGUI_Alpha; tweenTmp.fromFloat = fromTmp; tweenTmp.toFloat = to; tweenTmp.isChild = isChild; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
public static TweenScript TnRotate(this Transform trans, Vector3?from, Vector3 to, float time = 0.5f, float delayTime = 0, bool isLocal = true) { AnimType animType; Vector3 fromTmp; if (isLocal) { fromTmp = from ?? trans.localEulerAngles; animType = AnimType.LocalRotate; } else { fromTmp = from ?? trans.eulerAngles; animType = AnimType.Rotate; } TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.animGameObject = trans.gameObject; tweenTmp.animType = animType; tweenTmp.fromV3 = fromTmp; tweenTmp.toV3 = to; tweenTmp.isLocal = isLocal; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
/// <summary> /// 动画过度到目标颜色 /// </summary> public static TweenScript TnUguiColor(this RectTransform rectTrans, Color?from, Color to, float time = 0.5f, float delayTime = 0, bool isChild = false) { Color fromTmp = from ?? Color.white; if (from == null) { if (rectTrans.GetComponent <Graphic>() != null) { fromTmp = from ?? rectTrans.GetComponent <Graphic>().color; } } TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.animGameObject = rectTrans.gameObject; tweenTmp.animType = AnimType.UGUI_Color; tweenTmp.fromColor = fromTmp; tweenTmp.toColor = to; tweenTmp.isChild = isChild; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
public static void FinishAnim(TweenScript tweenData) { tweenData.currentTime = tweenData.totalTime; tweenData.executeUpdate(); tweenData.executeCallBack(); GetInstance().animList.Remove(tweenData); StackObjectPool <TweenScript> .PutObject(tweenData); }
public void FinishAnim() { currentTime = totalTime; executeUpdate(); executeCallBack(); TweenUtil.GetInstance().animList.Remove(this); StackObjectPool <TweenScript> .Push(this); }
/* * public static TweenScript ValueTo(AnimParamHash l_animHash) * { * TweenScript l_tmp = l_animHash.GetAnimData(); * l_tmp.Init(); * GetInstance().animList.Add(l_tmp); * return l_tmp; * } * public class AnimParamHash : Dictionary<AnimParamType, object> * { * public AnimParamHash(params object[] l_params) * { * for (int i = 0; i < l_params.Length; i += 2) * { * this[(AnimParamType)l_params[i]] = l_params[i + 1]; * } * } * public AnimParamHash SetData(params object[] l_params) * { * Clear(); * for (int i = 0; i < l_params.Length; i += 2) * { * this[(AnimParamType)l_params[i]] = l_params[i + 1]; * } * return this; * } * public TweenScript GetAnimData() * { * TweenScript DataTmp = StackObjectPool<TweenScript>.GetObject(); * foreach (var hash in this) * { * AnimParamType l_ParamType = hash.Key; * switch (l_ParamType) * { * //基础参数 * case AnimParamType.GameObj: * DataTmp.animGameObject = (GameObject)hash.Value; * break; * case AnimParamType.AnimType: * DataTmp.animType = (AnimType)hash.Value; * break; * case AnimParamType.Time: * DataTmp.totalTime = (float)hash.Value; * break; * case AnimParamType.InteType: * DataTmp.m_easeType = (Ease)hash.Value; * break; * case AnimParamType.RepeatType: * DataTmp.repeatType = (RepeatType)hash.Value; * break; * case AnimParamType.RepeatCount: * DataTmp.repeatCount = (int)hash.Value; * break; * case AnimParamType.DelayTime: * DataTmp.delayTime = (float)hash.Value; * break; * //From * case AnimParamType.FromV3: * DataTmp.fromV3 = (Vector3)hash.Value; * break; * case AnimParamType.FromV2: * DataTmp.fromV2 = (Vector2)hash.Value; * break; * case AnimParamType.FromColor: * DataTmp.fromColor = (Color)hash.Value; * break; * case AnimParamType.FromFloat: * DataTmp.fromFloat = (float)hash.Value; * break; * //To * case AnimParamType.ToV3: * DataTmp.toV3 = (Vector3)hash.Value; * break; * case AnimParamType.ToV2: * DataTmp.toV2 = (Vector2)hash.Value; * break; * case AnimParamType.ToColor: * DataTmp.toColor = (Color)hash.Value; * break; * case AnimParamType.ToFloat: * DataTmp.toFloat = (float)hash.Value; * break; * //动画回调 * case AnimParamType.CallBack: * DataTmp.animCallBack = (AnimCallBack)hash.Value; * break; * case AnimParamType.CallBackParams: * DataTmp.animParameter = (object[])hash.Value; * break; * //定制函数 * case AnimParamType.CustomMethodV3: * DataTmp.customMethodV3 = (AnimCustomMethodVector3)hash.Value; * break; * case AnimParamType.CustomMethodV2: * DataTmp.customMethodV2 = (AnimCustomMethodVector2)hash.Value; * break; * case AnimParamType.CustomMethodFloat: * DataTmp.customMethodFloat = (AnimCustomMethodFloat)hash.Value; * break; * //闪烁 * case AnimParamType.Space: * DataTmp.blinkTime = (float)hash.Value; * break; * //路径运动 * case AnimParamType.PathType: * DataTmp.m_pathType = (PathType)hash.Value; * break; * case AnimParamType.PathData: * DataTmp.pathPoints = (Vector3[])hash.Value; * break; * //其他设置 * case AnimParamType.IsIncludeChild: * DataTmp.isChild = (bool)hash.Value; * break; * case AnimParamType.IsLocal: * DataTmp.isLocal = (bool)hash.Value; * break; * case AnimParamType.IsIgnoreTimeScale: * DataTmp.isIgnoreTimeScale = (bool)hash.Value; * break; * } * } * return DataTmp; * } * } */ #endregion #region 功能函数 /// <summary> /// 停止一个动画 /// </summary> /// <param name="animGameObject">要停止的动画</param> /// <param name="isCallBack">是否触发回调</param> public static void StopAnim(TweenScript tweenData, bool isCallBack = false) { if (isCallBack) { tweenData.executeCallBack(); } GetInstance().animList.Remove(tweenData); StackObjectPool <TweenScript> .PutObject(tweenData); }
public static TweenScript TnAlphaTo(this Transform trans, float from, float to, float time = 0.5f, float delayTime = 0) { TweenScript tweenTmp = StackObjectPool <TweenScript> .Get(); tweenTmp.SetValue(from, to); tweenTmp.Init(trans.gameObject, AnimType.Alpha, time, delayTime); TweenUtil.GetInstance().AddTween(tweenTmp); return(tweenTmp); }
/// <summary> /// 动画移动到某位置 /// </summary> /// <returns></returns> public static TweenScript TnLocalMove(this Transform trans, Vector3 to, float time = 0.5f, float delayTime = 0) { TweenScript tweenTmp = StackObjectPool <TweenScript> .Get(); tweenTmp.SetValue(trans.localPosition, to); tweenTmp.isLocal = true; tweenTmp.Init(trans.gameObject, AnimType.Position, time, delayTime); TweenUtil.GetInstance().AddTween(tweenTmp); return(tweenTmp); }
/// <summary> /// 隐藏/显示 /// </summary> public static TweenScript TnBlink(this Transform trans, float space, float time = 0.5f, float delayTime = 0) { TweenScript tweenTmp = StackObjectPool <TweenScript> .Get(); tweenTmp.blinkTime = space; tweenTmp.Init(trans.gameObject, AnimType.Blink, time, delayTime); TweenUtil.GetInstance().AddTween(tweenTmp); return(tweenTmp); }
/// <summary> /// UGUI RectTransfrom 放大缩小 /// width/height /// </summary> public static TweenScript TnUiSize(this RectTransform rectTrans, Vector2 to, float time = 0.5f, float delayTime = 0) { Vector2 fromTmp = rectTrans.sizeDelta; TweenScript tweenTmp = StackObjectPool <TweenScript> .Get(); tweenTmp.SetValue(fromTmp, to); tweenTmp.Init(rectTrans.gameObject, AnimType.UiSize, time, delayTime); TweenUtil.GetInstance().AddTween(tweenTmp); return(tweenTmp); }
/// <summary> /// UGUI Move RectTransform .anchoredPosition3D /// </summary> public static TweenScript TnAnchoredPosition(this RectTransform rectTrans, Vector3 to, float time = 0.5f, float delayTime = 0) { TweenScript tweenTmp = StackObjectPool <TweenScript> .Get(); tweenTmp.SetValue(rectTrans.anchoredPosition3D, to); tweenTmp.Init(rectTrans.gameObject, AnimType.UiAnchoredPosition, time, delayTime); TweenUtil.GetInstance().AddTween(tweenTmp); return(tweenTmp); }
public static TweenScript TnRotate(this Transform trans, Vector3 to, float time = 0.5f, float delayTime = 0, bool isLocal = true) { TweenScript tweenTmp = StackObjectPool <TweenScript> .Get(); tweenTmp.SetValue(isLocal ? trans.localEulerAngles : trans.eulerAngles, to); tweenTmp.isLocal = isLocal; tweenTmp.Init(trans.gameObject, AnimType.Rotate, time, delayTime); TweenUtil.GetInstance().AddTween(tweenTmp); return(tweenTmp); }
public void AddTween(TweenScript tweenScript) { // 避免同一物体同一类型同时存在两次. var a = animList.Find(x => x.AnimObject == tweenScript.AnimObject && x.AnimType == tweenScript.AnimType); if (a != null) { animList.Remove(a); StackObjectPool <TweenScript> .Push(a); } animList.Add(tweenScript); }
public static TweenScript TnPathMove(this Transform trans, Vector3[] path, float time = 2, float delayTime = 0, bool isLocal = false, PathType pathType = PathType.CatmullRom) { TweenScript tweenTmp = StackObjectPool <TweenScript> .Get(); if (pathType == PathType.Line) { pathType = PathType.CatmullRom; } Vector3 fromV3; if (isLocal) { fromV3 = trans.transform.localPosition; } else { fromV3 = trans.transform.position; } if (path.Length < 2) { pathType = PathType.Line; //小于1个点。 Debug.LogError("Path point it's too short "); } else { Vector3[] realPath = new Vector3[path.Length + 1]; realPath[0] = fromV3; for (int i = 0; i < path.Length; i++) { realPath[i + 1] = path[i]; } tweenTmp.pathNodes = realPath; } tweenTmp.isLocal = isLocal; tweenTmp.pathType = pathType; tweenTmp.Init(trans.gameObject, AnimType.Position, time, delayTime); TweenUtil.GetInstance().AddTween(tweenTmp); return(tweenTmp); }
public static TweenScript CustomTweenFloat(UnityAction <float> method, float from, float to, float time = 0.5f, float delayTime = 0, LoopType repeatType = LoopType.Once, int repeatCount = -1) { TweenScript tweenTmp = StackObjectPool <TweenScript> .Get(); tweenTmp.SetValue(from, to); tweenTmp.customMethodFloat = new AnimCustomMethodFloat(); tweenTmp.customMethodFloat.AddListener(method); tweenTmp.SetLoopType(repeatType, repeatCount); tweenTmp.Init(null, AnimType.CustomFloat, time, delayTime); GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
/// <summary> /// 隐藏/显示 /// </summary> public static TweenScript TnBlink(this Transform trans, float space, float time = 0.5f, float delayTime = 0) { TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.animType = AnimType.Blink; tweenTmp.animGameObject = trans.gameObject; tweenTmp.blinkTime = space; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
public static TweenScript TnPathMove(this Transform trans, Vector3?from, Vector3[] path, float time = 2, float delayTime = 0, bool isLocal = false, PathType pathType = PathType.PathLinear) { TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); if (pathType == PathType.Line) { pathType = PathType.PathLinear; } if (isLocal) { tweenTmp.animType = AnimType.LocalPosition; // 动画类型 tweenTmp.fromV3 = from ?? trans.transform.localPosition; } else { tweenTmp.animType = AnimType.Position; tweenTmp.fromV3 = from ?? trans.transform.position; } if (path.Length < 2) { pathType = PathType.Line; //小于1个点。 Debug.LogError("Path point it's too short "); } else { Vector3[] realPath = new Vector3[path.Length + 1]; realPath[0] = tweenTmp.fromV3; for (int i = 0; i < path.Length; i++) { realPath[i + 1] = path[i]; } tweenTmp.pathPoints = realPath; } tweenTmp.animGameObject = trans.gameObject; tweenTmp.isLocal = isLocal; tweenTmp.pathType = pathType; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
/// <summary> /// 动画移动到某位置 /// </summary> /// <returns></returns> public static TweenScript TnLocalMove(this Transform trans, Vector3?from, Vector3 to, float time = 0.5f, float delayTime = 0) { TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.isLocal = true; tweenTmp.animGameObject = trans.gameObject; tweenTmp.animType = AnimType.LocalPosition; tweenTmp.fromV3 = from ?? trans.localPosition; tweenTmp.toV3 = to; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
/// <summary> /// 停止一个对象身上的所有动画 /// </summary> /// <param name="trans">要停止动画的对象</param> /// <param name="isCallBack">是否触发回调</param> public static void TnStop(this Transform trans, bool isCallBack = false) { for (int i = 0; i < TweenUtil.GetInstance().animList.Count; i++) { if (TweenUtil.GetInstance().animList[i].animGameObject == trans.gameObject) { if (isCallBack) { TweenScript dataTmp = TweenUtil.GetInstance().animList[i]; dataTmp.executeCallBack(); } TweenScript tweenData = TweenUtil.GetInstance().animList[i]; TweenUtil.GetInstance().animList.RemoveAt(i); i--; StackObjectPool <TweenScript> .PutObject(tweenData); } } }
/// <summary> /// UGUI RectTransfrom 放大缩小 /// width/height /// </summary> public static TweenScript TnUguiSize(this RectTransform rectTrans, Vector2?from, Vector2 to, float time = 0.5f, float delayTime = 0) { Vector2 fromTmp = from ?? rectTrans.GetComponent <RectTransform>().sizeDelta; TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.animGameObject = rectTrans.gameObject; tweenTmp.animType = AnimType.UGUI_Size; tweenTmp.fromV2 = fromTmp; tweenTmp.toV2 = to; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
public static TweenScript TnUguiRotate(this RectTransform rectTrans, Vector3 to, float time = 0.5f, float delayTime = 0) { Vector3 fromTmp = rectTrans.GetComponent <RectTransform>().eulerAngles; TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.animGameObject = rectTrans.gameObject; tweenTmp.animType = AnimType.UGUI_AnchoredRotate; tweenTmp.fromV3 = fromTmp; tweenTmp.toV3 = to; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
public void Update() { for (int i = 0; i < animList.Count; i++) { animList[i].executeUpdate(); if (animList[i].isDone == true) { TweenScript tweenTmp = animList[i]; if (!tweenTmp.AnimReplayLogic()) { animList.Remove(tweenTmp); i--; StackObjectPool <TweenScript> .PutObject(tweenTmp); } tweenTmp.executeCallBack(); } } }
public static TweenScript CustomTweenVector3(UnityAction <Vector3> method, Vector3 from, Vector3 to, float time = 0.5f, float delayTime = 0, LoopType repeatType = LoopType.Once, int repeatCount = -1) { TweenScript tweenTmp = StackObjectPool <TweenScript> .Get(); tweenTmp.SetValue(from, to); tweenTmp.customMethodV3 = new AnimCustomMethodVector3(); if (method != null) { tweenTmp.customMethodV3.AddListener(method); } tweenTmp.SetLoopType(repeatType, repeatCount); tweenTmp.Init(null, AnimType.CustomVector3, time, delayTime); GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
public static TweenScript TnAlphaTo(GameObject animObject, float from, float to, float time = 0.5f, float delayTime = 0, bool isChild = false) { TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.animGameObject = animObject; tweenTmp.animType = AnimType.Alpha; tweenTmp.fromFloat = from; tweenTmp.toFloat = to; tweenTmp.isChild = isChild; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
public static TweenScript TnColorTo(this Transform trans, Color from, Color to, float time = 0.5f, float delayTime = 0, bool isChild = false) { TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.animGameObject = trans.gameObject; tweenTmp.animType = AnimType.Color; tweenTmp.fromColor = from; tweenTmp.toColor = to; tweenTmp.isChild = isChild; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.Init(); TweenUtil.GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
public static TweenScript CustomTweenVector3(AnimCustomMethodVector3 method, Vector3 from, Vector3 to, float time = 0.5f, float delayTime = 0, bool IsIgnoreTimeScale = false, LoopType repeatType = LoopType.Once, int repeatCount = -1) { TweenScript tweenTmp = StackObjectPool <TweenScript> .GetObject(); tweenTmp.animType = AnimType.Custom_Vector3; tweenTmp.fromV3 = from; tweenTmp.toV2 = to; tweenTmp.customMethodV3 = method; tweenTmp.SetDelay(delayTime); tweenTmp.totalTime = time; tweenTmp.SetLoopType(repeatType, repeatCount); // l_tmp.isIgnoreTimeScale = IsIgnoreTimeScale; tweenTmp.Init(); GetInstance().animList.Add(tweenTmp); return(tweenTmp); }
public static void PutSODict(Dictionary <string, object> dict) { dict.Clear(); StackObjectPool <Dictionary <string, object> > .PutObject(dict); }
public static Dictionary <string, object> GetSODict() { return(StackObjectPool <Dictionary <string, object> > .GetObject()); }