#define FUNCELL_MODIFIED using Thousandto.Core.Base; using UnityEngine; namespace Thousandto.Plugins.Common { //alpha动画 public class UIAlphaAnimation : UIAnimationBase { #region//私有变量 //开始值 private float _startValue = 0f; //结束值 private float _endValue = 0f; //操作的对象 private Transform _handleTrans = null; private UIPanel _handlePanel = null; private UIWidget _handleWidget = null; private UIButton _handleButton = null; //操作的UI private UINormalForm _handleForm = null; #endregion #region//属性 public float StartValue { get { return _startValue; } set { _startValue = value; if(_startValue < 0.002f) { _startValue = 0.002f; } } } public float EndValue { get { return _endValue; } set { _endValue = value; if (_endValue < 0.002f) { _endValue = 0.002f; } } } public override Transform HandleTrans { get { return _handleTrans; } set { _handleTrans = value; _handlePanel = null; _handleWidget = null; _handleButton = null; _handleForm = null; if (_handleTrans != null) { _handlePanel = _handleTrans.GetComponent(); if (_handlePanel == null) { _handleWidget = _handleTrans.GetComponent(); } _handleButton = _handleTrans.GetComponent(); _handleForm = _handleTrans.GetComponent(); } } } public static float GolbalAlpha { get; set; } #endregion #region//构造函数 public UIAlphaAnimation() : base(UIAnimationType.Alpha) { } #endregion #region//继承基类 public override void Evaluate(float value) { var curValue = Mathf.Lerp(_startValue, _endValue, value) * GolbalAlpha; if(curValue < 0.002f) { curValue = 0.002f; } if (_handlePanel != null) { _handlePanel.alpha = curValue; } else if (_handleWidget != null) { _handleWidget.alpha = curValue; } if (_handleForm != null) { //如果是UI,同步alpha到其子UI for (int i = 0; i < _handleForm.ChildList.Count; ++i) { var form = _handleForm.ChildList[i] as UINormalForm; if(form != null) { form.MainPanel.alpha = curValue; for (int j = 0; j < form.ChildList.Count; ++j) { form.ChildList[j].MainPanel.alpha = curValue; } } } } } protected override void OnStart() { if (_handlePanel != null) { _handlePanel.alpha = _startValue; } if (_handleWidget != null) { if (_handleButton != null) { _handleWidget.alpha = 1f; if (_handleButton.normalSprite != null) { //访问这个变量,调用UIButton的OnInit函数 } } _handleWidget.alpha = _startValue; } _waitFrame = 2; } protected override void OnStop() { _handleTrans = null; _handlePanel = null; _handleWidget = null; _handleForm = null; } #endregion } //缩放动画 public class UIScaleAnimation : UIAnimationBase { #region//私有变量 //开始值 private Vector3 _startValue = Vector3.zero; //结束值 private Vector3 _endValue = Vector3.zero; //操作的对象 private Transform _handleTrans = null; //操作的UI private UINormalForm _handleForm = null; #endregion #region//属性 //开始值 public Vector3 StartValue { get { return _startValue; } set { _startValue = value; } } //结束值 public Vector3 EndValue { get { return _endValue; } set { _endValue = value; } } //操作的对象 public override Transform HandleTrans { get { return _handleTrans; } set { _handleForm = null; _handleTrans = value; if (_handleTrans != null) { _handleForm = _handleTrans.GetComponent(); } } } #endregion #region//构造函数 public UIScaleAnimation() : base(UIAnimationType.Scale) { } #endregion #region//继承基类 public override void Evaluate(float value) { var curScale = Vector3.Lerp(_startValue, _endValue, value); if (_handleTrans != null) { _handleTrans.localScale = curScale; if (_handleForm != null) { //如果是UI,同步缩放到其子UI for (int i = 0; i < _handleForm.ChildList.Count; ++i) { var form = _handleForm.ChildList[i] as UINormalForm; if (form != null && form.MainPanel.mStarted) { form.TransformInst.localScale = curScale; for (int j = 0; j < form.ChildList.Count; ++j) { if(form.ChildList[j].MainPanel.mStarted) { form.ChildList[j].TransformInst.localScale = curScale; } } } } } } } protected override void OnStart() { _waitFrame = 2; if (_handleTrans != null) { if(_endValue.x >= 1) { _handleTrans.localScale = _endValue; } } } protected override void OnStop() { _handleTrans = null; _handleForm = null; } #endregion } //位移动画 public class UIPositionAnimation : UIAnimationBase { #region//私有变量 //开始位置 private Vector3 _startValue = Vector3.zero; //结束位置 private Vector3 _endValue = Vector3.zero; //偏移位置 private Vector3 _offsetPos = Vector3.zero; //操作的对象 private Transform _handleTrans = null; //操作的UI private UINormalForm _handleForm = null; #endregion #region//属性 //开始位置 public Vector3 StartValue { get { return _startValue; } set { _startValue = value; } } //结束位置 public Vector3 EndValue { get { return _endValue; } set { _endValue = value; } } //偏移位置 public Vector3 OffsetPos { get { return _offsetPos; } set { _offsetPos = value; } } //操作的对象 public override Transform HandleTrans { get { return _handleTrans; } set { _handleForm = null; _handleTrans = value; if(_handleTrans != null) { _handleForm = _handleTrans.GetComponent(); } } } #endregion #region//构造函数 public UIPositionAnimation() : base(UIAnimationType.Position) { } #endregion #region//继承基类 public override void Evaluate(float value) { var curPos = Vector3.Lerp(_startValue, _endValue, value); if (_handleTrans != null) { //动画播放不改变z值 curPos.z = _handleTrans.localPosition.z; _handleTrans.localPosition = curPos; if(_handleForm != null) { //如果是UI,同步位置到其子UI for (int i = 0; i < _handleForm.ChildList.Count; ++i) { var form = _handleForm.ChildList[i] as UINormalForm; if (form != null && form.MainPanel.mStarted) { curPos.z = form.TransformInst.localPosition.z; form.TransformInst.localPosition = curPos; for (int j = 0; j < form.ChildList.Count; ++j) { if(form.ChildList[j].MainPanel.mStarted) { curPos.z = form.ChildList[j].TransformInst.localPosition.z; form.ChildList[j].TransformInst.localPosition = curPos; } } } } } } } protected override void OnStart() { _waitFrame = 2; } protected override void OnStop() { _handleTrans = null; _handleForm = null; } #endregion } //空动画,占位用,持续一段时间什么也不做 public class UIEmptyAnimation : UIAnimationBase { #region//私有变量 //操作的对象 private Transform _handleTrans = null; #endregion #region//属性 #endregion #region//构造函数 public UIEmptyAnimation() : base(UIAnimationType.Empty) { } #endregion #region//继承基类 public override Transform HandleTrans { get { return _handleTrans; } set { _handleTrans = value; } } public override void Evaluate(float value) { } protected override void OnStart() { } protected override void OnStop() { } #endregion } //旋转动画 public class UIRotationAnimation : UIAnimationBase { #region//私有变量 //开始值 private float _startValue = 0f; //结束值 private float _endValue = 0f; //操作的对象 private Transform _handleTrans = null; //操作的UI private UINormalForm _handleForm = null; #endregion #region//属性 public float StartValue { get { return _startValue; } set { _startValue = value; } } public float EndValue { get { return _endValue; } set { _endValue = value; } } public override Transform HandleTrans { get { return _handleTrans; } set { _handleForm = null; _handleTrans = value; if(_handleTrans != null) { _handleForm = _handleTrans.GetComponent(); } } } #endregion #region//构造函数 public UIRotationAnimation() : base(UIAnimationType.Rotation) { } #endregion #region//继承基类 public override void Evaluate(float value) { var curValue = Mathf.Lerp(_startValue, _endValue, value); if (_handleTrans != null) { var euler = _handleTrans.localEulerAngles; euler.z = curValue; _handleTrans.localEulerAngles = euler; if (_handleForm != null) { //如果是UI,同步旋转到其子UI for (int i = 0; i < _handleForm.ChildList.Count; ++i) { euler = _handleForm.ChildList[i].TransformInst.localEulerAngles; euler.z = curValue; _handleForm.ChildList[i].TransformInst.localEulerAngles = euler; } } } } protected override void OnStart() { } protected override void OnStop() { _handleTrans = null; _handleForm = null; } #endregion } }