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

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() { }
    }

    
}

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章