using DG.Tweening;
using UnityEngine;
namespace UGUITweener
{
[ExecuteInEditMode]
public class TweenScale : 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).localScale = startValue;
tween = ((RectTransform)component).DOScale(to, duration);
}
else
{
((Transform)component).eulerAngles = startValue;
tween = ((Transform)component).DOScale(to, 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.GetType() == typeof(RectTransform))
{
from = ((RectTransform)component).localScale;
}
else
{
from = ((Transform)component).localScale;
}
}
[ContextMenu("设置 Transform")]
private void SetTransform()
{
if (component.GetType() == typeof(RectTransform))
{
((RectTransform)component).localScale = from;
}
else
{
((Transform)component).localScale = from;
}
}
#endif
}
}
下载地址:https://download.youkuaiyun.com/download/yuyingwin/10846928