动画效果如下:


展示图1 如下:

展示图2 如下:

展示图3 如下:

功能: 如上图所示 移动,旋转,缩放,渐变透明  都可并行实现

只要脑洞够大,创意动画效果随你实现。

注:所有动画都是用曲线【AnimationCurve】调整实现

请教问题可添加QQ:1768556826

图1曲线:大致如下

图2曲线: 大致如下

参数说明:

DelayTime = 延迟播放时间
Time = 播放时间

每个动画类型有【两个选择类型】 None ,Normal 和 【两个参数】 From 和 To;

None = 关闭   Normal = 开启,From = 开始值  To = 目标值

实现步骤分两种,分别针对为 单个物体 和 多个物体。

单个物体 实现步骤:(如上面 展示图3)

第一步:找个控件挂上 TweenContoller 脚本

第二步:勾选 自定义物体

选勾  【自定义物体】,参数  Play On Start = 运行时自动播放动画,Anim Game Obj = 目标物体

播放方式有两种

1: 选勾 Play On Start = 运行时自动播放动画

2:调用以下函数 播放动画:

最后一步:开启要进行的动画并且调整曲线

比如想实现边移动边旋转,则在移动(Move)和旋转(Rotate) 选择为 Normal,并且调整曲线即可(也可以使用默认曲线)

如下图:

然后运行,自动播放动画。

多个物体 实现步骤:(如上面 展示图1, 2)

第一步:找个控件挂上 TweenContoller 脚本

第二步:开启要进行的动画并且调整曲线

比如想实现边移动边旋转,则在移动(Move)和旋转(Rotate) 选择为 Normal,并且调整曲线即可(也可以使用默认曲线)

如下图:

最后一步:播放动画

.

整体代码如下:

一共有三个脚本文件:

TweenController(核心代码),TweenObjAttribute(物体属性脚本),TweenControllerEditor(编辑器显示脚本)

三个脚本都已上传

注:TweenControllerEditor文件 放到 Editor 文件目录下

TweenController.cs (核心代码)

/****************** UI 曲线动画控制器(动画完成时可回调函数) ***************************** *   Leon Kim*   *   可用曲线 调整 动画表现方式,支持多个物体,多种动画混合 (比如 物体 移动位置的同时 播放旋转)*   *   *   单个物体时: (可无代码, 直接在TweenController组件上 选勾 自定义物体 并且拖拽即可)*   可用代码 控制开启*   StartTween()  (当勾选 自定义物体里面的 Play On Start时 运行时会调 StartTween()函数并开始播放)*   *   *   多个物体时:(以下都是代码接口)*   InitTweenType() 所有动画类型 还原成 初始开启模式*   OpenTweenType() 选择开启哪些动画类型 比如只开启 缩放和移动动画*   *   (1) StartMove()  *   (2) StartScale() *   (3) StartRotate() *   (4) StartAlpha()*   注:*   以上函数参数中 *   isOpenOnlyType = true 只播放当前动画(比如只移动或只旋转 不播放其他动画) *   isOpenOnlyType = false 播放手动开启的动画 和 使用手动设置的值*   *   *   注:*   (0) 每个物体完成动画时 都会回调 Lua 函数 并且返回此物体*   (1) 挂此脚本的控件需 Anchor填充状态,*   (2) 从StartMove 传过来的物体 都在此控件层下(obj.SetParent(transform))*   (3) 此控件是动画控制器 本身不参与动画**/using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;public enum TweenType{None,Normal,}public class TweenController : MonoBehaviour {private static TweenController _Instance = null;public static TweenController Instance{get{return _Instance;}}//存储 物体信息private List<TweenObjAttribute> objAttributeList = new List<TweenObjAttribute>();private Action<GameObject> callBackFunc;public float time = 1;   //动画进行时间public float delayTime = 0; //延迟时间//** 额外参数public bool isUseAdditionalParam = false;public bool playOnStart = false;public GameObject animGameObj;private RectTransform animGameObjRectTrans;private bool isTweening = false;private float updateTime = 0f;//** Position 动画相关public TweenType moveType = TweenType.None;public AnimationCurve xCurve = AnimationCurve.Linear(0, 0, 1, 1);public AnimationCurve yCurve = AnimationCurve.Linear(0, 0, 1, 1);public Vector3 fromPos;public Vector3 toPos;//** 偏移 动画相关public TweenType offsetType = TweenType.None;public AnimationCurve offsetCurve = AnimationCurve.Linear(0, 0, 1, 1);public float offset;//** Scale 动画相关public TweenType scaleType = TweenType.None;public AnimationCurve scaleCurve = AnimationCurve.Linear(0, 0, 1, 1);public Vector3 fromScale = Vector3.one;public Vector3 toScale = Vector3.one;//** Rotate 动画相关public TweenType rotateType = TweenType.None;public AnimationCurve rotateCurve = AnimationCurve.Linear(0, 0, 1, 1);public Vector3 fromRotate = Vector3.zero;public Vector3 toRotate = Vector3.zero;//** Alpha 动画相关public TweenType alphaType = TweenType.None;public AnimationCurve alphaCurve = AnimationCurve.Linear(0, 0, 1, 1);public float fromAlpha;public float toAlpha;private List<TweenType> beginTypeList = new List<TweenType>();private bool isAwake = false;private void Awake(){isAwake = true;_Instance = this;}private void Start(){//初始化用beginTypeList.Add(moveType);beginTypeList.Add(scaleType);beginTypeList.Add(rotateType);beginTypeList.Add(alphaType);if (playOnStart){StartTween();}}//还原成默认 动画类型public void InitTweenType(){moveType = beginTypeList[0];scaleType = beginTypeList[1];rotateType = beginTypeList[2];alphaType = beginTypeList[3];}//选择性 动画类型开启方式 (移动,缩放,旋转,Alpha)public void OpenTweenType(bool isOpenMoveType, bool isOpenScaleType, bool isOpenRotateType, bool isOpenAlphaType){moveType = isOpenMoveType ? TweenType.Normal : TweenType.None;scaleType = isOpenScaleType ? TweenType.Normal : TweenType.None;rotateType = isOpenRotateType ? TweenType.Normal : TweenType.None;alphaType = isOpenAlphaType ? TweenType.Normal : TweenType.None;}//普通 开始动画 (用于 自定义物体)public void StartTween(){StartTween(null);}//开始 带回调的 动画  (用于 自定义物体)public void StartTween(Action<GameObject> callBackFunc){if (!isAwake && callBackFunc != null){Debug.LogError(string.Format("This GameObject({0}) is not activated", this.gameObject.name));}if (!isUseAdditionalParam) return;if (animGameObj == null) return;if (moveType != TweenType.None){animGameObj.transform.GetComponent<RectTransform>().anchoredPosition = fromPos;}if (scaleType != TweenType.None){animGameObj.transform.localScale = fromScale;}if (rotateType != TweenType.None){animGameObj.transform.localRotation = Quaternion.Euler(fromRotate);}if (alphaType != TweenType.None){CanvasGroup g = animGameObj.GetComponent<CanvasGroup>();if(g == null){g = animGameObj.AddComponent<CanvasGroup>();}g.alpha = fromAlpha;}animGameObjRectTrans = animGameObj.GetComponent<RectTransform>();updateTime = 0;isTweening = true;}//-------------------------------------------------------------->>>  移动动画 接口  <<<--------------------------------------------------------------------------//isOpenOnlyType == true 仅开启移动动画 其他动画关闭 //isOpenOnlyType == false 用手动设置的动画开启 和 除Position外 用手动设置的值//参数 (物体,开始Pos,目标Pos,是否仅开启移动动画)public void StartMove(GameObject obj, Vector3 fromPos, Vector3 toPos, bool isOpenOnlyType){StartMove(obj, fromPos, toPos, isOpenOnlyType, null);}//参数 (物体,开始Pos,目标Pos,是否仅开启移动动画,回调函数)public void StartMove(GameObject obj, Vector3 fromPos, Vector3 toPos, bool isOpenOnlyType, Action<GameObject> callBackFunc){StartMove(obj, fromPos, toPos, time, delayTime, isOpenOnlyType, callBackFunc);}//参数 (物体,开始Pos,目标Pos, 持续时间,延迟时间,是否仅开启移动动画,回调函数)public void StartMove(GameObject obj, Vector3 fromPos, Vector3 toPos, float timeLength, float delayTime, bool isOpenOnlyType, Action<GameObject> callBackFunc){StartMove(obj, fromPos, toPos, timeLength, delayTime, isOpenOnlyType, false, false, callBackFunc);}public void StartMove(GameObject obj, Vector3 fromPos, Vector3 toPos, float timeLength, float delayTime, bool isOpenOnlyType, bool isCounterX, bool isCounterY, Action<GameObject> callBackFunc){StartMove(obj, fromPos, toPos, timeLength, delayTime, isOpenOnlyType, false, false, callBackFunc, 0);}//参数 (物体,开始Pos,目标Pos, 持续时间,延迟时间,是否仅开启移动动画,x曲线是否反轨迹运动,y曲线是否反轨迹运动,回调函)public void StartMove(GameObject obj, Vector3 fromPos, Vector3 toPos, float timeLength, float delayTime, bool isOpenOnlyType, bool isCounterX, bool isCounterY, Action<GameObject> callBackFunc, float offset){if (!isAwake){Debug.LogError(string.Format("This GameObject({0}) is not activated", this.gameObject.name));}//obj.transform.SetParent(transform);TweenObjAttribute attribute = isOpenOnlyType ? new TweenObjAttribute(1) : new TweenObjAttribute(moveType, scaleType, rotateType, alphaType, this);attribute.Obj = obj;//attribute.RectTrans = obj.GetComponent<RectTransform>();attribute.FromPos = fromPos;attribute.ToPos = toPos;attribute.UpdateTime = 0;attribute.Time = timeLength;attribute.DelayTime = delayTime;//obj.transform.localPosition = fromPos;attribute.IsCounterX = isCounterX;attribute.IsCounterY = isCounterY;attribute.Offset = offset;attribute.CallBackFunc = callBackFunc;objAttributeList.Add(attribute);attribute.IsTweening = true;}//支持偏移的动画 参数 (物体,开始Pos,目标Pos, 持续时间,延迟时间,是否仅开启移动动画,偏移值,回调函数)public void StartOffsetMove(GameObject obj, Vector3 fromPos, Vector3 toPos, float timeLength, float delayTime, float offset,bool isOpenOnlyType, Action<GameObject> callBackFunc){StartMove(obj, fromPos, toPos, timeLength, delayTime, isOpenOnlyType, false, false, callBackFunc, offset);}//-------------------------------------------------------------->>>  缩放动画 接口  <<<--------------------------------------------------------------------------//isOpenOnlyType == true 仅开启移动动画 其他动画关闭 //isOpenOnlyType == false 用手动设置的动画开启 和 除Scale外 用手动设置的值//参数 (物体,开始Scale,目标Scale,是否仅开启 Scale 动画)public void StartScale(GameObject obj, Vector3 fromScale, Vector3 toScale, bool isOpenOnlyType){StartScale(obj, fromScale, toScale, isOpenOnlyType, null);}//参数 (物体,开始Scale,目标Scale,是否仅开启 Scale 动画, 回调函数)public void StartScale(GameObject obj, Vector3 fromScale, Vector3 toScale, bool isOpenOnlyType, Action<GameObject> callBackFunc){StartScale(obj, fromScale, toScale, time, delayTime, isOpenOnlyType, callBackFunc);}//参数 (物体,开始Scale,目标Scale, 持续时间,延迟时间,是否仅开启 Scale 动画, 回调函数)public void StartScale(GameObject obj, Vector3 fromScale, Vector3 toScale, float timeLength, float delayTime, bool isOpenOnlyType, Action<GameObject> callBackFunc){if (!isAwake){Debug.LogError(string.Format("This GameObject({0}) is not activated", this.gameObject.name));}//obj.transform.SetParent(transform);TweenObjAttribute attribute = isOpenOnlyType ? new TweenObjAttribute(2) : new TweenObjAttribute(moveType, scaleType, rotateType, alphaType, this);attribute.Obj = obj;attribute.FromScale = fromScale;attribute.ToScale = toScale;attribute.UpdateTime = 0;attribute.Time = timeLength;attribute.DelayTime = delayTime;//attribute.Obj.transform.GetComponent<RectTransform>().anchoredPosition = fromPos;attribute.CallBackFunc = callBackFunc;objAttributeList.Add(attribute);attribute.IsTweening = true;}//-------------------------------------------------------------->>> 旋转动画 接口  <<<--------------------------------------------------------------------------//isOpenOnlyType == true 仅开启移动动画 其他动画关闭 //isOpenOnlyType == false 用手动设置的动画开启 和 除Rotate外 用手动设置的值//参数 (物体,开始Rotate,目标Rotate,是否仅开启 Rotate 动画)public void StartRotate(GameObject obj, Vector3 fromRotate, Vector3 toRotate, bool isOpenOnlyType){StartRotate(obj, fromRotate, toRotate, isOpenOnlyType, null);}//参数 (物体,开始Rotate,目标Rotate,是否仅开启 Rotate 动画, 回调函数)public void StartRotate(GameObject obj, Vector3 fromRotate, Vector3 toRotate, bool isOpenOnlyType, Action<GameObject> callBackFunc){StartRotate(obj, fromRotate, toRotate, time, delayTime, isOpenOnlyType, callBackFunc);}//参数 (物体,开始Rotate,目标Rotate, 持续时间,延迟时间,是否仅开启 Rotate 动画, 回调函数)public void StartRotate(GameObject obj, Vector3 fromRotate, Vector3 toRotate, float timeLength, float delayTime, bool isOpenOnlyType, Action<GameObject> callBackFunc){if (!isAwake){Debug.LogError(string.Format("This GameObject({0}) is not activated", this.gameObject.name));}//obj.transform.SetParent(transform);TweenObjAttribute attribute = isOpenOnlyType ? new TweenObjAttribute(3) : new TweenObjAttribute(moveType, scaleType, rotateType, alphaType, this);attribute.Obj = obj;attribute.FromRotate = fromRotate;attribute.ToRotate = toRotate;attribute.UpdateTime = 0;attribute.Time = timeLength;attribute.DelayTime = delayTime;attribute.Obj.transform.GetComponent<RectTransform>().anchoredPosition = fromPos;attribute.CallBackFunc = callBackFunc;objAttributeList.Add(attribute);attribute.IsTweening = true;}//-------------------------------------------------------------->>>  Alpha动画 接口  <<<--------------------------------------------------------------------------//isOpenOnlyType == true 仅开启移动动画 其他动画关闭 //isOpenOnlyType == false 用手动设置的动画开启 和 除Alpha外 用手动设置的值//参数 (物体,开始Alpha,目标alpha,是否仅开启 Alpha 动画)public void StartAlpha(GameObject obj, float fromAlpha, float toAlpha, bool isOpenOnlyType){StartAlpha(obj, fromAlpha, toAlpha, isOpenOnlyType, null);}//参数 (物体,开始Alpha,目标alpha,是否仅开启 Alpha 动画, 回调函数)public void StartAlpha(GameObject obj, float fromAlpha, float toAlpha, bool isOpenOnlyType, Action<GameObject> callBackFunc){StartAlpha(obj, fromAlpha, toAlpha, time, delayTime, isOpenOnlyType, callBackFunc);}//参数 (物体,开始Alpha,目标alpha, 持续时间,延迟时间,是否仅开启 Alpha 动画, 回调函数)public void StartAlpha(GameObject obj, float fromAlpha, float toAlpha, float timeLength, float delayTime, bool isOpenOnlyType, Action<GameObject> callBackFunc){if (!isAwake){Debug.LogError(string.Format("This GameObject({0}) is not activated", this.gameObject.name));}//obj.transform.SetParent(transform);TweenObjAttribute attribute = isOpenOnlyType ? new TweenObjAttribute(4) : new TweenObjAttribute(moveType, scaleType, rotateType, alphaType, this);attribute.Obj = obj;attribute.FromAlpha = fromAlpha;attribute.ToAlpha = toAlpha;attribute.UpdateTime = 0;attribute.Time = timeLength;attribute.DelayTime = delayTime;attribute.Obj.transform.GetComponent<RectTransform>().anchoredPosition = fromPos;attribute.CallBackFunc = callBackFunc;objAttributeList.Add(attribute);attribute.IsTweening = true;}public void ClearTween(){DisposeAll ();objAttributeList.Clear ();}private void Update () {//** 自定义物体 动画if (isTweening && animGameObj){updateTime += Time.deltaTime;//判断 是否动画完成if (updateTime - delayTime > time){StopNormalTween();}else if(updateTime - delayTime >= 0){float t = (updateTime - delayTime) / time;UpdateMove(moveType, animGameObj, fromPos, toPos, t);UpdateScale(scaleType, animGameObj, fromScale, toScale, t);UpdateRotate(rotateType, animGameObj, fromRotate, toRotate, t);UpdateFade(alphaType, animGameObj, fromAlpha, toAlpha, t);}}//** 代码里指定的物体 动画if (objAttributeList.Count <= 0) return;for(int i = 0; i < objAttributeList.Count; i++){TweenObjAttribute objAttribute = objAttributeList[i];if (!objAttribute.IsTweening) continue;objAttribute.UpdateTime += Time.deltaTime;//判断 是否动画完成if (objAttribute.UpdateTime - objAttribute.DelayTime > objAttribute.Time){StopTween(objAttribute);}else if (objAttribute.UpdateTime - objAttribute.DelayTime >= 0){if (!objAttribute.Obj.activeSelf)objAttribute.Obj.SetActive (true);float t = (objAttribute.UpdateTime - objAttribute.DelayTime) / objAttribute.Time;UpdateMove(objAttribute.MoveType, objAttribute.Obj, objAttribute.FromPos, objAttribute.ToPos, t, objAttribute.IsCounterX, objAttribute.IsCounterY, objAttribute.Offset);UpdateScale(objAttribute.ScaleType, objAttribute.Obj, objAttribute.FromScale, objAttribute.ToScale, t);UpdateRotate(objAttribute.RotateType, objAttribute.Obj, objAttribute.FromRotate, objAttribute.ToRotate, t);UpdateFade(objAttribute.AlphaType, objAttribute.Obj, objAttribute.FromAlpha, objAttribute.ToAlpha, t);}}}//移动(Move)动画private void UpdateMove(TweenType type, GameObject obj, Vector3 fromPos,Vector3 toPos, float t, bool isCounterX = false, bool isCounterY = false, float offset = 0){if (type == TweenType.None)return;Vector3 move = toPos - fromPos;float xVar = xCurve.Evaluate(t);float yVar = yCurve.Evaluate(t);float val = t / time;move.x *= !isCounterX ? val - (val - xVar) : val + (val - xVar);move.y *= !isCounterY ? val - (val - yVar) : val + (val - yVar);//偏移值float offsetVal = offsetCurve.Evaluate (t);float oVal = offset * offsetVal;float a = Vector3.Angle (move, Vector3.left) - 90;float offsetY = oVal * Mathf.Sin (a * Mathf.Deg2Rad);float offsetX = oVal * Mathf.Cos (a * Mathf.Deg2Rad);obj.transform.localPosition = fromPos + move + new Vector3(-offsetX, offsetY, 0);}//缩放(Scale)动画private void UpdateScale(TweenType type, GameObject obj, Vector3 fromScale, Vector3 toScale, float t){if (type == TweenType.None)return;float val = scaleCurve.Evaluate(t);Vector3 s = fromScale * (1 - val) + toScale * val;obj.transform.localScale = s;}//旋转(Rotate)动画private void UpdateRotate(TweenType type, GameObject obj, Vector3 fromRotate, Vector3 toRotate, float t){if (type == TweenType.None)return;float val = rotateCurve.Evaluate(t);Vector3 s = fromRotate * (1 - val) + toRotate * val;obj.transform.localRotation = Quaternion.Euler(s);}//透明(Alpha)动画Dictionary<GameObject, AnimatedAlpha> canvasGroups = new Dictionary<GameObject, AnimatedAlpha>(); private void UpdateFade(TweenType type, GameObject obj, float fromAlpha, float toAlpha, float t){if (type == TweenType.None)return;AnimatedAlpha g = null;if (!canvasGroups.ContainsKey(obj)){g = obj.GetComponent<AnimatedAlpha>();canvasGroups[obj] = g;}else{g = canvasGroups[obj];}if (g == null)return;float val = alphaCurve.Evaluate(t);g.alpha = fromAlpha * (1 - val) + toAlpha * val;}private void StopNormalTween(){if (moveType != TweenType.None){animGameObj.transform.localPosition= toPos;}if (scaleType != TweenType.None){//animGameObj.transform.localScale = toScale;}if (rotateType != TweenType.None){animGameObj.transform.localRotation = Quaternion.Euler(toRotate);}if (alphaType != TweenType.None){AnimatedAlpha g = animGameObj.GetComponent<AnimatedAlpha>();if (g != null){g.alpha = toAlpha;}}updateTime = 0;isTweening = false;if (callBackFunc != null){callBackFunc(animGameObj);}}private void StopTween(TweenObjAttribute objManager){if (objManager.Obj == null)return;if (objManager.MoveType != TweenType.None){objManager.Obj.transform.localPosition = objManager.ToPos;}if (objManager.ScaleType != TweenType.None){objManager.Obj.transform.localScale = toScale;}if (objManager.RotateType != TweenType.None){objManager.Obj.transform.localRotation = Quaternion.Euler(toRotate);}if (objManager.AlphaType != TweenType.None){AnimatedAlpha g = objManager.Obj.GetComponent<AnimatedAlpha>();if (g != null){g.alpha = objManager.ToAlpha;}}objManager.IsTweening = false;objManager.UpdateTime = 0;if (objManager.CallBackFunc != null){objManager.CallBackFunc(objManager.Obj);}objAttributeList.Remove(objManager);}private void OnDestroy(){DisposeAll ();}private void Dispose(){for(int i = 0,length = objAttributeList.Count; i < length; i++){objAttributeList[i].Dispose();objAttributeList [i].Obj = null;}objAttributeList.Clear ();}public void DisposeAll(){Dispose();}}

TweenObjAttribute.cs(物体属性脚本)

using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
using System;public class TweenObjAttribute{private GameObject obj;     //物体private RectTransform rectTrans;private Vector3 fromPos;    //初始 Vector3 值 private Vector3 toPos;      //目标 Vector3 值private Vector3 fromScale;    //初始 Vector3 值 private Vector3 toScale;      //目标 Vector3 值private Vector3 fromRotate;    //初始 Vector3 值 private Vector3 toRotate;      //目标 Vector3 值private float fromAlpha = 0; //初始Alpha值private float toAlpha = 0;  //目标Alpha值private float updateTime = 0;  //实时更新的时间private bool isTweening = false;    //是否开启动画private float time = 1;  //时间长度private float delayTime = 0;  //延迟时间private bool isCounterX = false; //是否反曲线运动private bool isCounterY = false; //是否反曲线运动private float offset = 0; //偏移值private TweenType moveType = TweenType.None;private TweenType scaleType = TweenType.None;private TweenType rotateType = TweenType.None;private TweenType alphaType = TweenType.None;public Action<GameObject> CallBackFunc;public TweenObjAttribute(){}public TweenObjAttribute(TweenType moveType, TweenType scaleType, TweenType rotateType, TweenType alphaType, TweenController tweenController){this.moveType = moveType;this.scaleType = scaleType;this.rotateType = rotateType;this.alphaType = alphaType;fromPos = tweenController.fromPos;toPos = tweenController.toPos;fromScale = tweenController.fromScale;toScale = tweenController.toScale;fromRotate = tweenController.fromRotate;toRotate = tweenController.toRotate;fromAlpha = tweenController.fromAlpha;toAlpha = tweenController.toAlpha;}//仅开启 某类型动画 (1 = 移动,2 = 缩放,3 = 旋转,4 = Alpha, 其他 = 默认)public TweenObjAttribute(int type){switch (type){case 1:moveType = TweenType.Normal;scaleType = TweenType.None;rotateType = TweenType.None;alphaType = TweenType.None;break;case 2:moveType = TweenType.None;scaleType = TweenType.Normal;rotateType = TweenType.None;alphaType = TweenType.None;break;case 3:moveType = TweenType.None;scaleType = TweenType.None;rotateType = TweenType.Normal;alphaType = TweenType.None;break;case 4:moveType = TweenType.None;scaleType = TweenType.None;rotateType = TweenType.None;alphaType = TweenType.Normal;break;default:break;}}public GameObject Obj{get{return obj;}set{obj = value;}}public float UpdateTime{get{return updateTime;}set{updateTime = value;}}public bool IsTweening{get{return isTweening;}set{isTweening = value;}}public float Time{get{return time;}set{time = value;}}public float DelayTime{get{return delayTime;}set{delayTime = value;}}public bool IsCounterX{get{return isCounterX;}set{isCounterX = value;}}public bool IsCounterY{get{return isCounterY;}set{isCounterY = value;}}public float FromAlpha{get{return fromAlpha;}set{fromAlpha = value;}}public float ToAlpha{get{return toAlpha;}set{toAlpha = value;}}public TweenType MoveType{get{return moveType;}set{moveType = value;}}public TweenType ScaleType{get{return scaleType;}set{scaleType = value;}}public TweenType RotateType{get{return rotateType;}set{rotateType = value;}}public TweenType AlphaType{get{return alphaType;}set{alphaType = value;}}public Vector3 FromPos{get{return fromPos;}set{fromPos = value;}}public Vector3 ToPos{get{return toPos;}set{toPos = value;}}public float Offset{get{return offset;}set{offset = value;}}public Vector3 FromScale{get{return fromScale;}set{fromScale = value;}}public Vector3 ToScale{get{return toScale;}set{toScale = value;}}public Vector3 FromRotate{get{return fromRotate;}set{fromRotate = value;}}public Vector3 ToRotate{get{return toRotate;}set{toRotate = value;}}public RectTransform RectTrans{get{return rectTrans;}set{rectTrans = value;}}public void Dispose(){}}

TweenControllerEditor.cs(编辑器显示脚本)

/** Author Leon kim*
*/using UnityEngine;
using UnityEditor;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;[CustomEditor(typeof(TweenController), true)]public class TweenControllerEditor : Editor{SerializedProperty delayTime;SerializedProperty time;SerializedProperty isUseAddtionalParam;SerializedProperty playOnStart;SerializedProperty animGameObj;SerializedProperty xCurve;SerializedProperty yCurve;SerializedProperty fromPos;SerializedProperty toPos;SerializedProperty offsetCurve;SerializedProperty offset;SerializedProperty scaleCurve;SerializedProperty fromScale;SerializedProperty toScale;SerializedProperty rotateCurve;SerializedProperty fromRotate;SerializedProperty toRotate;SerializedProperty alphaCurve;SerializedProperty fromAlpha;SerializedProperty toAlpha;protected void OnEnable(){delayTime = serializedObject.FindProperty("delayTime");time = serializedObject.FindProperty("time");xCurve = serializedObject.FindProperty("xCurve");yCurve = serializedObject.FindProperty("yCurve");fromPos = serializedObject.FindProperty("fromPos");toPos = serializedObject.FindProperty("toPos");offsetCurve = serializedObject.FindProperty ("offsetCurve");offset = serializedObject.FindProperty ("offset");scaleCurve = serializedObject.FindProperty("scaleCurve");fromScale = serializedObject.FindProperty("fromScale");toScale = serializedObject.FindProperty("toScale");rotateCurve = serializedObject.FindProperty("rotateCurve");fromRotate = serializedObject.FindProperty("fromRotate");toRotate = serializedObject.FindProperty("toRotate");alphaCurve = serializedObject.FindProperty("alphaCurve");fromAlpha = serializedObject.FindProperty("fromAlpha");toAlpha = serializedObject.FindProperty("toAlpha");playOnStart = serializedObject.FindProperty("playOnStart");animGameObj = serializedObject.FindProperty("animGameObj");}public override void OnInspectorGUI(){TweenController tw = target as TweenController;//serializedObject.Update();EditorGUILayout.PropertyField(delayTime);EditorGUILayout.PropertyField(time);EditorGUI.indentLevel = 0;tw.isUseAdditionalParam = EditorGUILayout.ToggleLeft("自定义物体", tw.isUseAdditionalParam);if (tw.isUseAdditionalParam){EditorGUI.indentLevel = 1;EditorGUILayout.PropertyField(playOnStart);EditorGUILayout.PropertyField(animGameObj);}EditorGUI.indentLevel = 0;tw.moveType = (TweenType)EditorGUILayout.EnumPopup("移动 (Move)", (System.Enum)tw.moveType);if(tw.moveType != TweenType.None){EditorGUI.indentLevel = 1;EditorGUILayout.PropertyField(xCurve);EditorGUILayout.PropertyField(yCurve);EditorGUILayout.BeginHorizontal();EditorGUILayout.PropertyField(fromPos);if (GUILayout.Button("reset")){try{tw.fromPos = tw.animGameObj.transform.GetComponent<RectTransform>().anchoredPosition;}catch{throw new System.Exception("此按钮仅 自定义物体时 可用, 若需自定义请指定物体到 Anim Game Obj");}}EditorGUILayout.EndHorizontal();EditorGUILayout.BeginHorizontal();EditorGUILayout.PropertyField(toPos);if (GUILayout.Button("reset")){try{tw.toPos = tw.animGameObj.transform.GetComponent<RectTransform>().anchoredPosition;}catch{throw new System.Exception("此按钮仅 自定义物体时 可用, 若需自定义请指定物体到 Anim Game Obj");}}EditorGUILayout.EndHorizontal();tw.offsetType = (TweenType)EditorGUILayout.EnumPopup ("偏移 (offset)", (System.Enum)tw.offsetType);if (tw.offsetType != TweenType.None) {EditorGUILayout.PropertyField(offsetCurve);EditorGUILayout.BeginHorizontal();EditorGUILayout.PropertyField(offset);EditorGUILayout.EndHorizontal ();}}EditorGUI.indentLevel = 0;tw.scaleType = (TweenType)EditorGUILayout.EnumPopup("缩放 (Scale)", (System.Enum)tw.scaleType);if(tw.scaleType != TweenType.None){EditorGUI.indentLevel = 1;EditorGUILayout.PropertyField(scaleCurve);EditorGUILayout.PropertyField(fromScale);EditorGUILayout.PropertyField(toScale);}EditorGUI.indentLevel = 0;tw.rotateType = (TweenType)EditorGUILayout.EnumPopup("旋转 (Rotate)", (System.Enum)tw.rotateType);if(tw.rotateType != TweenType.None){EditorGUI.indentLevel= 1;EditorGUILayout.PropertyField(rotateCurve);EditorGUILayout.PropertyField(fromRotate);EditorGUILayout.PropertyField(toRotate);}EditorGUI.indentLevel = 0;tw.alphaType = (TweenType)EditorGUILayout.EnumPopup("透明 (Alpha)", (System.Enum)tw.alphaType);if (tw.alphaType != TweenType.None){EditorGUI.indentLevel = 1;EditorGUILayout.PropertyField(alphaCurve);EditorGUILayout.PropertyField(fromAlpha);EditorGUILayout.PropertyField(toAlpha);}serializedObject.ApplyModifiedProperties();}}

Unity【NGUI】【UGUI】 动画效果实现,AnimationCurve曲线动画控制器,支持动画完成 回调相关推荐

  1. Android把商品添加到购物车的动画效果(贝塞尔曲线)

    当我们写商城类的项目的时候,一般都会有加入购物车的功能,加入购物车的时候会有一些抛物线动画,具体代码如下: 实现效果如图: 思路: 确定动画的起终点 在起终点之间使用二次贝塞尔曲线填充起终点之间的点的 ...

  2. android曲线水波纹录音动画,Android-贝塞尔曲线实现水波纹动画

    Android 系统api提供了quadTo和rQuadTo实现二阶贝塞尔曲线,三阶贝塞尔曲线在这不做阐述,只不过是两个控制点. 效果图 首先看张二阶贝赛尔的曲线 Path path = new Pa ...

  3. 抽奖动画效果html,利用css实现一个抽奖动画效果

    首先我们先来看下最终的运行效果: 从效果图我们可以看到,抽奖会自动进行,并显示中奖信息. 这个效果基本是用CSS实现的,没有用图片,加一丢丢JS.完全没有考虑兼容性. 具体步骤如下: 首先画一个转盘 ...

  4. html5 鼠标滑动页面动画效果,鼠标滑动到当前页面触发动画效果

    近年来,关于鼠标滑动到当前页面从而触发动画效果十分的火热,今天我们就来学习下这一效果. 一.首先,我们先来了解一下这一效果实现的原理 1.一个网页离不开基本的布局,所以首先就是要先用html将所需要的 ...

  5. html怎么把字做成动画效果,8个华丽的HTML5文字动画特效赏析

    文字是网页的灵魂,很早以前有人发明了很多漂亮的计算机字体,这让网页变得样式各异.HTML5和CSS3的出现,我们可以让文字变得更加富有个性,在一些需要的场合,我们甚至可以利用HTML5制作文字动画.本 ...

  6. html将图片动画效果,8款精美的HTML5图片动画分享

    原标题:8款精美的HTML5图片动画分享 HTML5结合jQuery可以让网页图片变得更加绚丽多彩,比如实现一些图片3D切换.CSS3动画绘制以及各种图片效果的渲染.本文将分享8款精美的HTML5图片 ...

  7. html 气泡动画效果,css3实现好看的气泡按钮动画特效

    CSS3在我们网页设计中是最关键的一环,为什么这么说呢?我们在浏览别人的网站时,经常会看到特别好看的动画效果,比如一个按钮啊,一个图片啊,每次看到都能够让人有种赏心悦目的感觉,这就使网站更具有吸引力和 ...

  8. html右移动动画效果,图片的左右移动,js动画效果实现代码

    图片的左右移动,js动画效果实现代码 图片的左右移动,动画效果的实现 =(xk+xp)/2) { if (smer == 1) step--; else step++; } else { if (sm ...

  9. php 动画效果,首页自适应的分类图标的动画渐入效果

    随着HTML5技术的不断更新和革新,动画效果也越来越多的被使用.下面分享一个很炫的,自适应的分类的效果展示. 该展示不需要借助js或者jquery,单纯的html5+css3实现,有两种方式:渐入和震 ...

  10. html中flash的简单动画效果,css实现快速炫酷抖动动画效果

    1.Animate.css简介 Animate.css是一个可在您的Web项目中使用的即用型跨浏览器动画库.非常适合强调,首页,滑块和引导注意的提示.它是一个来自国外的 CSS3 动画库,它预设了抖动 ...

最新文章

  1. ballerina 学习二十九 数据库操作
  2. c++局域网主动ftp_如何在局域网中实现 ARP 攻击
  3. 模式识别新研究:微软OCR两层优化提升自然场景下的文字识别精度
  4. Bit-Z转入GXS、PPS、SPHTX、EOS未到账解决方案
  5. 吸尘车-真空吸尘车:真空吸尘车
  6. day28 java的集合(6)Properties和TreeSet
  7. 机器学习——层次聚类(超详细)
  8. Android日志输出管理
  9. 傻瓜式安装卸载office
  10. ASP.NET大作业/ASP.NET期末项目/大作业
  11. spring data jpa 多表UNION ALL查询按条件排序分页处理:未搜到方法,解决后记录:2018年11月13日15:22:00
  12. python实现情感分析
  13. Graphics2D 使用详解 【转】
  14. Excel 2010 SQL应用117 分组统计之GROUP BY 与First
  15. 【iMessage苹果相册推日历真机推】改成vue的MVVM模式现在前端趋向是去dom化
  16. PostMan测试http请求
  17. 关于银河麒麟系统配置本地yum源配置流程说明
  18. android 中获取所有有效网卡和对应的IP地址
  19. 微信“15。。。。。”背后的故事
  20. C# 监控笔记本/平板的充电/电源状态

热门文章

  1. 仿lex生成器(qt+C++实现)
  2. 开发android蓝牙4.0 BLE低功耗应用的感受
  3. C语言的三套标准:C89、C99和C11
  4. android使用ViewPage实现Grally画廊的卡片式效果
  5. 滴滴终于上市了,38岁程维身家300亿!
  6. 阿里云服务器的镜像如何选择
  7. 51单片机 驱动步进电机 C语言 lcd,基于51单片机的步进电机驱动程序
  8. js数组中的join(),reverse(),sort(),方法
  9. 虚拟机安装win7为什么进入不了安装界面
  10. 京东商品详情 API