仿照NGUI封装 DoTween功能系列(四)-TweenFillCount

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/yuyingwin/article/details/80074556

using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

namespace UGUITweener
{
    [ExecuteInEditMode,RequireComponent(typeof(Image))]
    public class TweenFillCount : TweenerSetting
    {
        [Range(0.0f, 1.0f)]
        public float from = 0.0f;

        [Range(0.0f, 1.0f)]
        public float to = 1.0f;

        private Image image;

        public override void TweenPlay(bool value)
        {
            if (image.type == Image.Type.Filled)
            {
                float startValue = value ? from : to;
                float endValue = value ? to : from;
                image.fillAmount = startValue;
                tween = image.DOFillAmount(endValue, duration).OnComplete(unityEvent.Invoke);
                SetTweenData();
            }
        }
        public override void SetEndToCurrentValue()
        {
            base.SetEndToCurrentValue();

            if (!image)
            {
                image = GetComponent<Image>();
                image.type = Image.Type.Filled;
            }
        }
#if UNITY_EDITOR

        [ContextMenu("设置 From")]
        private void SetFrom()
        {
            if (image.type == Image.Type.Filled)
                from = image.fillAmount;
        }

        [ContextMenu("设置 FillCount")]
        private void SetFillCount()
        {
            if (image.type == Image.Type.Filled)
                 image.fillAmount= from;
        }
#endif
    }
}

猜你喜欢

转载自blog.csdn.net/yuyingwin/article/details/80074556