先修复一下,错误的场景 删除不必要的钓场资产 修复into场景 update:更新meta文件,修复报错 update:修复资源 修复第一章节建造 修复建造第三章 update:删除多余内容 update:更新README.md update:还原图标 update:更新README update:更新配置
110 lines
2.9 KiB
C#
110 lines
2.9 KiB
C#
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
|
|
namespace FT.Timeline
|
|
{
|
|
public class DOTweenBehaviour : PlayableBehaviour
|
|
{
|
|
public DOTweenClipType tweenType;
|
|
public int variantId;
|
|
public float tweenDuration;
|
|
public Vector2 shakeStrength;
|
|
public int shakeVibrato;
|
|
public float shakeRandomness;
|
|
public bool shakeSnapping;
|
|
public bool shakeFadeOut;
|
|
public ShakeRandomnessMode shakeRandomnessMode;
|
|
|
|
private Tween _activeTween;
|
|
private RectTransform _target;
|
|
|
|
public override void OnBehaviourPlay(Playable playable, FrameData info)
|
|
{
|
|
}
|
|
|
|
public override void OnBehaviourPause(Playable playable, FrameData info)
|
|
{
|
|
KillTween();
|
|
}
|
|
|
|
public override void OnPlayableDestroy(Playable playable)
|
|
{
|
|
KillTween();
|
|
}
|
|
|
|
public override void ProcessFrame(Playable playable, FrameData info, object playerData)
|
|
{
|
|
var target = playerData as RectTransform;
|
|
if (target == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (!IsVariantMatched(target))
|
|
{
|
|
KillTween();
|
|
return;
|
|
}
|
|
|
|
if (_activeTween == null || _target != target)
|
|
{
|
|
KillTween();
|
|
_target = target;
|
|
_activeTween = CreateTween(target);
|
|
}
|
|
|
|
if (_activeTween == null || !_activeTween.IsActive())
|
|
{
|
|
return;
|
|
}
|
|
|
|
var duration = Mathf.Max(tweenDuration, 0f);
|
|
var localTime = duration > 0f ? Mathf.Clamp((float)playable.GetTime(), 0f, duration) : 0f;
|
|
_activeTween.Goto(localTime, false);
|
|
}
|
|
|
|
private bool IsVariantMatched(RectTransform target)
|
|
{
|
|
var selector = target.GetComponent<DOTweenRuntimeSelector>();
|
|
if (selector == null)
|
|
{
|
|
return true;
|
|
}
|
|
return selector.CurrentVariantId == variantId;
|
|
}
|
|
|
|
private Tween CreateTween(RectTransform target)
|
|
{
|
|
Tween tween;
|
|
switch (tweenType)
|
|
{
|
|
case DOTweenClipType.ShakeAnchorPos:
|
|
tween = target.DOShakeAnchorPos(tweenDuration, shakeStrength, shakeVibrato, shakeRandomness,
|
|
shakeSnapping, shakeFadeOut, shakeRandomnessMode);
|
|
break;
|
|
default:
|
|
return null;
|
|
}
|
|
|
|
return tween.SetAutoKill(false).Pause();
|
|
}
|
|
|
|
private void KillTween()
|
|
{
|
|
if (_activeTween == null)
|
|
{
|
|
return;
|
|
}
|
|
|
|
if (_activeTween.IsActive())
|
|
{
|
|
_activeTween.Kill();
|
|
}
|
|
|
|
_activeTween = null;
|
|
_target = null;
|
|
}
|
|
}
|
|
}
|