using UnityEngine; using UnityEngine.Timeline; namespace Game { public class ClipAnimation : TimelineClipBase { private const string OverrideClip = "timeline"; private const string OverrideClipAnother = "timeline_another"; private AnimationPlayableAsset _mRealAsset; private AnimationComponent _animation; private Animator _animator; public override void OnEnter() { _mRealAsset = Asset as AnimationPlayableAsset; _animation = Owner.animation; _animator = _animation.Animator; _animation.IsTimelineAnother = !_animation.IsTimelineAnother; var clipName = _animation.IsTimelineAnother ? OverrideClipAnother : OverrideClip; _animation.AnimatorOverrideController[clipName] = _mRealAsset.clip; _animator.speed = (float)Speed; } public override void OnStay() { } public override void OnLeave() { _animator.speed = 1; } public override void OnPause(bool isPause) { _animator.speed = isPause ? 0 : (float)Speed; } } }