仿照NGUI封装 DoTween功能系列(七)-TweenRotation

using DG.Tweening;
using UnityEngine;

namespace UGUITweener
{
    [ExecuteInEditMode]
    public class TweenRotation : TweenerSetting
    {
        private Component component;
        public Vector3 from = Vector3.zero;
        public Vector3 to = Vector3.zero;

        public override void TweenPlay(bool value)
        {
            if (component)
            {
                Vector3 startValue = value ? from : to;
                Vector3 endvalue = value ? to : from;

                if (component.GetType() == typeof(RectTransform))
                {
                    ((RectTransform)component).eulerAngles = startValue;
                    tween = ((RectTransform)component).DOLocalRotate(endvalue, duration).OnComplete(unityEvent.Invoke);
                }
                else
                {
                    ((Transform)component).eulerAngles = startValue;
                    tween = ((Transform)component).DOLocalRotate(endvalue, duration).OnComplete(unityEvent.Invoke);
                }

                SetTweenData();
            }
        }

        public override void SetStartToCurrentValue()
        {
            base.SetStartToCurrentValue();

            if (!component)
            {
                component = (Component)GetComponent<RectTransform>() ? (Component)GetComponent<RectTransform>() : (Component)GetComponent<Transform>();
            }
        }

#if UNITY_EDITOR

        [ContextMenu("设置 From")]
        private void SetFrom()
        {
            if (component)
            {
                if (component.GetType() == typeof(RectTransform))
                {
                    from = ((RectTransform)component).eulerAngles;
                }
                else
                {
                    from = ((Transform)component).eulerAngles;
                }
            }
        }

        [ContextMenu("设置 Transform")]
        private void SetTransform()
        {
            if (component)
            {
                if (component.GetType() == typeof(RectTransform))
                {
                    ((RectTransform)component).eulerAngles = from;
                }
                else
                {
                    ((Transform)component).eulerAngles = from;
                }
            }
        }

#endif
    }
}

下载地址:https://download.csdn.net/download/yuyingwin/10846928

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值