仿照NGUI封装 DoTween功能系列 (十一)-TweenerSetting

本文介绍了一个Unity中的动画插件UGUITweener,该插件提供了一个名为TweenerSetting的MonoBehaviour类,用于控制和设置游戏对象的动画效果。包括动画曲线、时间缩放、延迟、持续时间等参数的设置,以及动画循环类型和事件的绑定。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using DG.Tweening;
using UnityEngine;
using UnityEngine.Events;

namespace UGUITweener
{
    public class TweenerSetting : MonoBehaviour
    {
        static public TweenerSetting current;
        public Tweener tweener;
        [HideInInspector,Header("是否开启Start")]
        bool mStarted = false;
        [HideInInspector]
        public bool autoPlay;

        [HideInInspector]
        public AnimationCurve animationCurve = new AnimationCurve(new Keyframe(0f, 0f, 0f, 1f), new Keyframe(1f, 1f, 1f, 0f));

        [HideInInspector]
        public bool ignoreTimeScale = true;

        [HideInInspector]
        public float delay = 0f;

        [HideInInspector]
        public float duration = 1f;

        [HideInInspector]
        public int tweenGroup = 0;

        [HideInInspector]
        public LoopType loopType = LoopType.Restart;

        [HideInInspector]
        public int loop;

        [HideInInspector]
        public UnityEvent unityEvent;

        [HideInInspector]
        public Tween tween;
        void Reset()
        {
            if (!mStarted)
            {
                SetStartToCurrentValue();
                SetEndToCurrentValue();
            }
        }

        void OnEnable()
        {
            SetStartToCurrentValue();
        }
        private void Start()
        {
            AutoPlay();
        }

        public virtual void AutoPlay()
        {
            if (autoPlay)
                TweenPlay(autoPlay);
        }

        public virtual void PlayForward()
        {
            TweenPlay(true);
        }

        public virtual void PlayReverse()
        {
            TweenPlay(false);
        }

        public virtual void TweenPlay(bool value)
        {
        }

        public void SetTweenData()
        {
            try
            {
                if (tween == null)
                {
                    return;
                }
                tween.Duration(true);
                tween.SetDelay(delay);
                tween.SetLoops(loop, loopType);

                tween.SetEase(animationCurve);

                if (!string.IsNullOrEmpty(tweenGroup.ToString()))
                {
                    tween.SetId(tweenGroup);
                }
                tween.SetUpdate(ignoreTimeScale);
                tween.SetAutoKill(true);
            }
            catch (System.Exception e)
            {
                Debug.LogError(e.Message);
            }
        }

        public virtual void SetStartToCurrentValue() { }

        public virtual void SetEndToCurrentValue() { }
    }

    
}

下载地址:https://download.youkuaiyun.com/download/yuyingwin/10846928

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值