58 lines
2.1 KiB
C#
58 lines
2.1 KiB
C#
using System;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.Playables;
|
|
using UnityEngine.Timeline;
|
|
|
|
namespace FT.Timeline
|
|
{
|
|
public enum DOTweenClipType
|
|
{
|
|
ShakeAnchorPos = 0,
|
|
}
|
|
|
|
[Serializable]
|
|
#if UNITY_EDITOR
|
|
[System.ComponentModel.DisplayName("DOTween Clip")]
|
|
#endif
|
|
public class DOTweenPlayableAsset : PlayableAsset, ITimelineClipAsset
|
|
{
|
|
[Header("Tween")]
|
|
[SerializeField] public DOTweenClipType tweenType = DOTweenClipType.ShakeAnchorPos;
|
|
|
|
[Header("Condition")]
|
|
[Tooltip("仅当绑定对象上的 DOTweenRuntimeSelector.CurrentVariantId 等于此值时本 Clip 生效;未挂 Selector 时始终生效")]
|
|
[SerializeField] public int variantId = 0;
|
|
|
|
[Header("Shake Anchor Pos")]
|
|
[SerializeField] [Min(0f)] public float tweenDuration = 0.2f;
|
|
[SerializeField] public Vector2 shakeStrength = Vector2.one * 5f;
|
|
[SerializeField] [Min(0)] public int shakeVibrato = 10;
|
|
[SerializeField] [Range(0f, 180f)] public float shakeRandomness = 90f;
|
|
[SerializeField] public bool shakeSnapping = false;
|
|
[SerializeField] public bool shakeFadeOut = true;
|
|
[SerializeField] public ShakeRandomnessMode shakeRandomnessMode = ShakeRandomnessMode.Harmonic;
|
|
|
|
public ClipCaps clipCaps => ClipCaps.None;
|
|
public override double duration => tweenDuration;
|
|
|
|
public override Playable CreatePlayable(PlayableGraph graph, GameObject go)
|
|
{
|
|
var playable = ScriptPlayable<DOTweenBehaviour>.Create(graph);
|
|
var behaviour = playable.GetBehaviour();
|
|
|
|
behaviour.tweenType = tweenType;
|
|
behaviour.variantId = variantId;
|
|
behaviour.tweenDuration = tweenDuration;
|
|
behaviour.shakeStrength = shakeStrength;
|
|
behaviour.shakeVibrato = shakeVibrato;
|
|
behaviour.shakeRandomness = shakeRandomness;
|
|
behaviour.shakeSnapping = shakeSnapping;
|
|
behaviour.shakeFadeOut = shakeFadeOut;
|
|
behaviour.shakeRandomnessMode = shakeRandomnessMode;
|
|
|
|
return playable;
|
|
}
|
|
}
|
|
}
|