コード例 #1
0
        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
                );

            /// To play an animation clip we first have to create a playable representation of it,
            /// via AnimationClipPlayable.Create. We have to provide the graph it belongs to and the animation clip as arguments.
            ///
            /// The easiest way to add a clip to a mixer is by invoking ConnectInput on the mixer with the clip's
            /// index and the playable clip as arguments. A third argument specifies the output index of the clip, which is always zero.
            /// Do this for all three clips in Configure.
            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);
        }
コード例 #2
0
        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);
            }
        }