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
}
}