功能介绍:
1.整合Append与Insert接口,支持串行与并行动画
2.支持随物体/界面等销毁而自动关闭动画
3.易读性高,action的写法很直观看出具体操作内容
PS:该文章部分源码依据于此在lua里实现类似unity生命周期的监听事件_Le_Sam的博客-优快云博客
源码:
c#
namespace Game.Scripts.Common
{
[XLua.LuaCallCSharp]
public class DoTweenEx
{
private Tweener tweener;
private Sequence sequence;
private Tween current;
public static DoTweenEx Sequence()
{
return new DoTweenEx(DOTween.Sequence());
}
private DoTweenEx(Sequence sequence)
{
this.sequence = sequence;
current = sequence;
this.Ease(1); //默认EaseType为DoTweenAction.Linear
}
private DoTweenEx(Transform target, Tweener tweener)
{
this.tweener = tweener;
current = tweener;
this.Ease(1); //默认EaseType为DoTweenAction.Linear
}
public DoTweenEx Append(DoTweenEx tweener)
{
sequence.Append(tweener.current);
return this;
}
public DoTweenEx Insert(DoTweenEx tweener)
{
sequence.Insert(0, tweener.current);
return this;
}
public DoTweenEx Play()
{
current.Play();
return this;
}
public DoTweenEx Pause()
{
current.Pause();
return this;
}
public DoTweenEx Kill(bool complete)
{
current.Kill(complete);
return this;
}
public DoTweenEx Ease(uint ease)
{
current.SetEase((Ease)ease);
return this;
}
public DoTweenEx Loop(int loops, uint type)
{
loops = loops == -1 ? 99999 : loops; // Temp:循环为-1时,并没有生效,强制改为固定值
if (sequence != null)
sequence.SetLoops(loops);
if (tweener != null)
tweener.SetLoops(loops, (LoopType)type);
return this;
}
public DoTweenEx Delay(float delay)
{
current.SetDelay(delay);
return this;
}
public DoTweenEx Restart()
{
current.Restart();
return this;
}
public DoTweenEx OnComplete(LuaFunction func)
{
current.OnComplete(delegate() { func.Call(this); });
return this;
}
public DoTweenEx SetUpdate(uint type, bool isAlone)
{
current.SetUpdate((UpdateType)type, isAlone);
return this;
}
public DoTweenEx SetPlaySpeed(float speed)
{
current.timeScale = speed;
return this;
}
public static DoTweenEx NoneTo(Transform target, float duration)
{
return new DoTweenEx(target, DOTween.To(() => 0, v => v = 0, 0, duration + 0.001f));
}
public static DoTweenEx LocalMoveTo(Transform target, Vector3 pos, float duration)
{
return new DoTweenEx(target, target.DOLocalMove(pos, duration + 0.001f));
}
public static DoTweenEx LocalMoveBy(Transform target, Vector3 pos, float duration)
{
return new DoTweenEx(target, target.DOBlendableLocalMoveBy(pos, duration + 0.001f));
}
public static DoTweenEx MoveTo(Transform target, Vector3 pos, float duration)
{
return new DoTweenEx(target, t