public void Configure(Animator animator, EnemyAnimationConfig config) { hasAppearClip = config.Appear; hasDisappearClip = config.Disappear; graph = PlayableGraph.Create(); graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); mixer = AnimationMixerPlayable.Create( graph, hasAppearClip || hasDisappearClip ? 6 : 4 ); var clip = AnimationClipPlayable.Create(graph, config.Move); clip.Pause(); mixer.ConnectInput((int)Clip.Move, clip, 0); clip = AnimationClipPlayable.Create(graph, config.Intro); clip.SetDuration(config.Intro.length); mixer.ConnectInput((int)Clip.Intro, clip, 0); clip = AnimationClipPlayable.Create(graph, config.Outro); clip.SetDuration(config.Outro.length); clip.Pause(); mixer.ConnectInput((int)Clip.Outro, clip, 0); clip = AnimationClipPlayable.Create(graph, config.Dying); clip.SetDuration(config.Dying.length); clip.Pause(); mixer.ConnectInput((int)Clip.Dying, clip, 0); if (hasAppearClip) { clip = AnimationClipPlayable.Create(graph, config.Appear); clip.SetDuration(config.Appear.length); clip.Pause(); mixer.ConnectInput((int)Clip.Appear, clip, 0); } if (hasDisappearClip) { clip = AnimationClipPlayable.Create(graph, config.Disappear); clip.SetDuration(config.Disappear.length); clip.Pause(); mixer.ConnectInput((int)Clip.Disappear, clip, 0); } var output = AnimationPlayableOutput.Create(graph, "Enemy", animator); output.SetSourcePlayable(mixer); #if UNITY_EDITOR clipTime = GetPlayable(CurrentClip).GetTime(); #endif }
public void RestoreAfterHotReload( Animator animator, EnemyAnimationConfig config, float speed ) { Configure(animator, config); GetPlayable(Clip.Move).SetSpeed(speed); var clip = GetPlayable(CurrentClip); clip.SetTime(clipTime); clip.Play(); SetWeight(CurrentClip, 1f); graph.Play(); if (CurrentClip == Clip.Intro && hasAppearClip) { clip = GetPlayable(Clip.Appear); clip.SetTime(clipTime); clip.Play(); SetWeight(Clip.Appear, 1f); } else if (CurrentClip >= Clip.Outro && hasDisappearClip) { clip = GetPlayable(Clip.Disappear); clip.Play(); double delay = GetPlayable(CurrentClip).GetDuration() - clip.GetDuration() - clipTime; if (delay >= 0f) { clip.SetDelay(delay); } else { clip.SetTime(-delay); } SetWeight(Clip.Disappear, 1f); } }