/// <summary> /// 停止一个动画 /// </summary> /// <param name="animGameObject">要停止的动画</param> /// <param name="isCallBack">是否触发回调</param> public static void StopAnim(AnimData animData, bool isCallBack = false) { if (GetInstance().animList.Contains(animData)) { if (isCallBack) { animData.ExecuteCallBack(); } GetInstance().animList.Remove(animData); } }
public static void ClearAllAnim(bool isCallBack = false) { for (int i = 0; i < GetInstance().animList.Count; i++) { AnimData animTmp = GetInstance().animList[i]; if (isCallBack) { animTmp.ExecuteCallBack(); } } GetInstance().animList.Clear(); }
public static AnimData Rotation(GameObject animObject, Quaternion?from, Quaternion to, float time = 0.5f, float delayTime = 0, bool isLocal = true, InterpType interp = InterpType.Default, bool IsIgnoreTimeScale = false, RepeatType repeatType = RepeatType.Once, int repeatCount = -1, AnimCallBack callBack = null, object[] parameter = null) { AnimType animType; Quaternion fromTmp; if (isLocal) { fromTmp = from ?? animObject.transform.localRotation; animType = AnimType.LocalRotation; } else { fromTmp = from ?? animObject.transform.rotation; animType = AnimType.Rotation; } AnimData l_tmp = new AnimData();; l_tmp.m_animGameObejct = animObject; l_tmp.m_animType = animType; l_tmp.m_fromQ4 = fromTmp; l_tmp.m_toQ4 = to; l_tmp.m_isLocal = isLocal; l_tmp.m_delayTime = delayTime; l_tmp.m_totalTime = time; l_tmp.m_interpolationType = interp; l_tmp.m_repeatType = repeatType; l_tmp.m_repeatCount = repeatCount; l_tmp.m_ignoreTimeScale = IsIgnoreTimeScale; l_tmp.m_callBack = callBack; l_tmp.m_parameter = parameter; l_tmp.Init(); GetInstance().animList.Add(l_tmp); return(l_tmp); }
/// <summary> /// 动画移动到某位置 /// </summary> /// <param name="animObject">动画对象</param> /// <param name="from">起点位置(可空,如为空则从当前位置开始)</param> /// <param name="to">终点位置</param> /// <param name="time">动画时间</param> /// <param name="isLocal">是否是用相对位置</param> /// <param name="interp">插值类型</param> /// <param name="IsIgnoreTimeScale">是否忽略时间缩放</param> /// <param name="repeatType">重复类型</param> /// <param name="repeatCount">重复次数</param> /// <param name="callBack">动画完成回调函数</param> /// <param name="parameter">动画完成回调函数传参</param> /// <returns></returns> public static AnimData Move(GameObject animObject, Vector3?from, Vector3 to, float delayTime = 0, float time = 0.5f, bool isLocal = true, InterpType interp = InterpType.Default, bool IsIgnoreTimeScale = false, RepeatType repeatType = RepeatType.Once, int repeatCount = -1, Transform toTransform = null, AnimCallBack callBack = null, object[] parameter = null) { Vector3 fromTmp; AnimType animType; if (isLocal) { fromTmp = from ?? animObject.transform.localPosition; animType = AnimType.LocalPosition; } else { fromTmp = from ?? animObject.transform.position; animType = AnimType.Position; } AnimData l_tmp = new AnimData();; l_tmp.m_animGameObejct = animObject; l_tmp.m_animType = animType; l_tmp.m_fromV3 = fromTmp; l_tmp.m_toV3 = to; l_tmp.m_isLocal = isLocal; l_tmp.m_toTransform = toTransform; l_tmp.m_delayTime = delayTime; l_tmp.m_totalTime = time; l_tmp.m_interpolationType = interp; l_tmp.m_repeatType = repeatType; l_tmp.m_repeatCount = repeatCount; l_tmp.m_ignoreTimeScale = IsIgnoreTimeScale; l_tmp.m_callBack = callBack; l_tmp.m_parameter = parameter; l_tmp.Init(); GetInstance().animList.Add(l_tmp); return(l_tmp); }
public static AnimData BezierMove(GameObject animObject, Vector3?from, Vector3 to, Vector3[] bezier_contral, float time = 0.5f, float delayTime = 0, RepeatType repeatType = RepeatType.Once, int repeatCount = -1, InterpType interp = InterpType.Default, bool isLocal = true, PathType bezierMoveType = PathType.Bezier2, AnimCallBack callBack = null, object[] parameter = null) { AnimData l_tmp = new AnimData();; if (isLocal) { l_tmp.m_animType = AnimType.LocalPosition; l_tmp.m_fromV3 = from ?? animObject.transform.localPosition; } else { l_tmp.m_animType = AnimType.Position; l_tmp.m_fromV3 = from ?? animObject.transform.position; } l_tmp.m_animGameObejct = animObject; l_tmp.m_toV3 = to; l_tmp.m_isLocal = isLocal; l_tmp.m_pathType = bezierMoveType; l_tmp.m_v3Contral = bezier_contral; l_tmp.m_delayTime = delayTime; l_tmp.m_totalTime = time; l_tmp.m_interpolationType = interp; l_tmp.m_repeatType = repeatType; l_tmp.m_repeatCount = repeatCount; l_tmp.m_callBack = callBack; l_tmp.m_parameter = parameter; l_tmp.Init(); GetInstance().animList.Add(l_tmp); return(l_tmp); }
/// <summary> /// 动画过度到目标颜色 /// </summary> /// <param name="animObject">动画对象</param> /// <param name="from">起始颜色(可空)</param> /// <param name="to">目标颜色</param> /// <param name="time">动画时间</param> /// <param name="isChild">是否影响子节点</param> /// <param name="interp">插值类型</param> /// <param name="IsIgnoreTimeScale">是否忽略时间缩放</param> /// <param name="repeatType">重复类型</param> /// <param name="repeatCount">重复次数</param> /// <param name="callBack">动画完成回调函数</param> /// <param name="parameter">动画完成回调函数传参</param> /// <returns></returns> public static AnimData UguiColor(GameObject animObject, Color?from, Color to, float time = 0.5f, float delayTime = 0, InterpType interp = InterpType.Default, bool isChild = true, bool IsIgnoreTimeScale = false, RepeatType repeatType = RepeatType.Once, int repeatCount = -1, AnimCallBack callBack = null, object[] parameter = null) { Color fromTmp = from ?? Color.white; if (from == null) { if (animObject.GetComponent <Graphic>() != null) { fromTmp = from ?? animObject.GetComponent <Graphic>().color; } } AnimData l_tmp = new AnimData(); l_tmp.m_animGameObejct = animObject; l_tmp.m_animType = AnimType.UGUI_Color; l_tmp.m_fromColor = fromTmp; l_tmp.m_toColor = to; l_tmp.m_isChild = isChild; l_tmp.m_delayTime = delayTime; l_tmp.m_totalTime = time; l_tmp.m_interpolationType = interp; l_tmp.m_repeatType = repeatType; l_tmp.m_repeatCount = repeatCount; l_tmp.m_ignoreTimeScale = IsIgnoreTimeScale; l_tmp.m_callBack = callBack; l_tmp.m_parameter = parameter; l_tmp.Init(); GetInstance().animList.Add(l_tmp); return(l_tmp); }
/// <summary> /// 停止一个对象身上的所有动画 /// </summary> /// <param name="animGameObject">要停止动画的对象</param> /// <param name="isCallBack">是否触发回调</param> public static void StopAnim(GameObject animGameObject, bool isCallBack = false) { for (int i = 0; i < GetInstance().animList.Count; i++) { if (GetInstance().animList[i].m_animGameObejct == animGameObject) { AnimData animData = GetInstance().animList[i]; if (isCallBack) { animData.ExecuteCallBack(); } GetInstance().removeList.Add(animData); } } for (int i = 0; i < GetInstance().removeList.Count; i++) { GetInstance().animList.Remove(GetInstance().removeList[i]); } GetInstance().removeList.Clear(); }
public AnimData GetAnimData() { AnimData DataTmp = SafeObjectPool <AnimData> .Instance.Allocate(); foreach (var hash in this) { AnimParamType l_ParamType = hash.Key; switch (l_ParamType) { //基础参数 case AnimParamType.GameObj: DataTmp.m_animGameObejct = (GameObject)hash.Value; break; case AnimParamType.AnimType: DataTmp.m_animType = (AnimType)hash.Value; break; case AnimParamType.Time: DataTmp.m_totalTime = (float)hash.Value; break; case AnimParamType.InteType: DataTmp.m_interpolationType = (InterpType)hash.Value; break; case AnimParamType.RepeatType: DataTmp.m_repeatType = (RepeatType)hash.Value; break; case AnimParamType.RepeatCount: DataTmp.m_repeatCount = (int)hash.Value; break; case AnimParamType.DelayTime: DataTmp.m_delayTime = (float)hash.Value; break; //From case AnimParamType.FromV3: DataTmp.m_fromV3 = (Vector3)hash.Value; break; case AnimParamType.FromV2: DataTmp.m_fromV2 = (Vector2)hash.Value; break; case AnimParamType.FromColor: DataTmp.m_fromColor = (Color)hash.Value; break; case AnimParamType.FromFloat: DataTmp.m_fromFloat = (float)hash.Value; break; //To case AnimParamType.ToV3: DataTmp.m_toV3 = (Vector3)hash.Value; break; case AnimParamType.ToV2: DataTmp.m_toV2 = (Vector2)hash.Value; break; case AnimParamType.ToColor: DataTmp.m_toColor = (Color)hash.Value; break; case AnimParamType.ToFloat: DataTmp.m_toFloat = (float)hash.Value; break; //动画回调 case AnimParamType.CallBack: DataTmp.m_callBack = (AnimCallBack)hash.Value; break; case AnimParamType.CallBackParams: DataTmp.m_parameter = (object[])hash.Value; break; //定制函数 case AnimParamType.CustomMethodV3: DataTmp.m_customMethodV3 = (AnimCustomMethodVector3)hash.Value; break; case AnimParamType.CustomMethodV2: DataTmp.m_customMethodV2 = (AnimCustomMethodVector2)hash.Value; break; case AnimParamType.CustomMethodFloat: DataTmp.m_customMethodFloat = (AnimCustomMethodFloat)hash.Value; break; //闪烁 case AnimParamType.Space: DataTmp.m_space = (float)hash.Value; break; //贝塞尔控制点 case AnimParamType.PathType: DataTmp.m_pathType = (PathType)hash.Value; break; case AnimParamType.V3Control: DataTmp.m_v3Contral = (Vector3[])hash.Value; break; case AnimParamType.floatControl: DataTmp.m_floatContral = (float[])hash.Value; break; //其他设置 case AnimParamType.IsIncludeChild: DataTmp.m_isChild = (bool)hash.Value; break; case AnimParamType.IsLocal: DataTmp.m_isLocal = (bool)hash.Value; break; case AnimParamType.IsIgnoreTimeScale: DataTmp.m_ignoreTimeScale = (bool)hash.Value; break; } } return(DataTmp); }