Ejemplo n.º 1
0
        private void PlayAnimation(AnimationClip clip)
        {
            var count = mMixer.GetInputCount();

            if (count > 0)
            {
                var animPlayable = (AnimationClipPlayable)mMixer.GetInput(count - 1);
                if (animPlayable.GetAnimationClip() == clip)
                {
                    if (!clip.isLooping)
                    {
                        animPlayable.SetTime(0);
                        mActionTime = clip.length;
                    }
                    if (!mGraph.IsPlaying())
                    {
                        mGraph.Play();
                    }
                    return;
                }
            }
            var playable = AnimationClipPlayable.Create(mGraph, clip);

            if (!clip.isLooping)
            {
                mActionTime = clip.length;
            }
            if (count == 0)
            {
                mMixer.AddInput(playable, 0, 1);
            }
            else
            {
                mTransitionTime = mTransitionDuration;
                mMixer.AddInput(playable, 0, 0);
            }
            if (!mGraph.IsPlaying())
            {
                mGraph.Play();
            }
        }
Ejemplo n.º 2
0
        public void Initialize(BaseAnimationSystem system, PlayableGraph graph, Playable self, int index, AnimationMixerPlayable rootMixer, TInit init)
        {
            SystemType = system.GetType();

            Self  = self;
            Root  = rootMixer;
            Graph = graph;

            Mixer = AnimationMixerPlayable.Create(graph, 0, true);
            Mixer.SetPropagateSetTime(true);
            OnInitialize(init);
            rootMixer.AddInput(self, 0);
            self.AddInput(Mixer, 0, 1);
        }
Ejemplo n.º 3
0
        public void SetOutput(BaseNode node)
        {
            OutputNode = node;

            if (node.Playable.GetOutputCount() == 0)
            {
                node.Playable.SetOutputCount(1);
            }

            if (Playable.GetInputCount() > 0)
            {
                if (!Playable.GetInput(0).IsNull())
                {
                    Playable.DisconnectInput(0);
                }

                Playable.ConnectInput(0, node.Playable, 0, 1f);
            }
            else
            {
                Playable.AddInput(node.Playable, 0, 1f);
            }
        }
Ejemplo n.º 4
0
        //Create playable tree
        void CreateAndPlayTree()
        {
#if UNITY_2017_1_OR_NEWER
            var clipActions = actions.OfType <PlayAnimatorClip>().ToList();
            var inputCount  = 1 + clipActions.Count;
            ports         = new Dictionary <PlayAnimatorClip, int>();
            graph         = PlayableGraph.Create();
            mixerPlayable = AnimationMixerPlayable.Create(graph, inputCount, true);
            mixerPlayable.SetInputWeight(0, 1f);
            baseClipPlayable = AnimationClipPlayable.Create(graph, baseAnimationClip);
            baseClipPlayable.SetPlayState(PlayState.Paused);
            graph.Connect(baseClipPlayable, 0, mixerPlayable, 0);

            var index = 1;             //0 is baseclip
            foreach (var playAnimClip in clipActions)
            {
                var clipPlayable = AnimationClipPlayable.Create(graph, playAnimClip.animationClip);
                graph.Connect(clipPlayable, 0, mixerPlayable, index);
                mixerPlayable.SetInputWeight(index, 0f);
                ports[playAnimClip] = index;
                clipPlayable.SetPlayState(PlayState.Paused);
                index++;
            }

            animationOutput = AnimationPlayableOutput.Create(graph, "Animation", animator);
            animationOutput.SetSourcePlayable(mixerPlayable);
            mixerPlayable.SetPlayState(PlayState.Paused);
            graph.Play();
#elif UNITY_5_6_OR_NEWER
            var clipActions = actions.OfType <PlayAnimatorClip>().ToList();
            var inputCount  = 1 + clipActions.Count;
            ports = new Dictionary <PlayAnimatorClip, int>();
            graph = PlayableGraph.CreateGraph();
            mixerPlayableHandle = graph.CreateAnimationMixerPlayable(inputCount, true);
            mixerPlayableHandle.SetInputWeight(0, 1f);
            baseClipPlayableHandle           = graph.CreateAnimationClipPlayable(baseAnimationClip);
            baseClipPlayableHandle.playState = PlayState.Paused;
            graph.Connect(baseClipPlayableHandle, 0, mixerPlayableHandle, 0);

            var index = 1;             //0 is baseclip
            foreach (var playAnimClip in clipActions)
            {
                var clipPlayableHandle = graph.CreateAnimationClipPlayable(playAnimClip.animationClip);
                graph.Connect(clipPlayableHandle, 0, mixerPlayableHandle, index);
                mixerPlayableHandle.SetInputWeight(index, 0f);
                ports[playAnimClip]          = index;
                clipPlayableHandle.playState = PlayState.Paused;
                index++;
            }

            animationOutput = graph.CreateAnimationOutput("Animation", animator);
            animationOutput.sourcePlayable = mixerPlayableHandle;
            mixerPlayableHandle.playState  = PlayState.Paused;
            graph.Play();
#else
            ports         = new Dictionary <PlayAnimatorClip, int>();
            mixerPlayable = AnimationMixerPlayable.Create();

            var basePlayableClip = AnimationClipPlayable.Create(baseAnimationClip);
            basePlayableClip.state = PlayState.Paused;
            mixerPlayable.AddInput(basePlayableClip);

            foreach (var playAnimClip in actions.OfType <PlayAnimatorClip>())
            {
                var playableClip = AnimationClipPlayable.Create(playAnimClip.animationClip);
                playableClip.state = PlayState.Paused;
                var index = mixerPlayable.AddInput(playableClip);
                mixerPlayable.SetInputWeight(index, 0f);
                ports[playAnimClip] = index;
            }

            animator.SetTimeUpdateMode(DirectorUpdateMode.Manual);
            animator.Play(mixerPlayable);
            mixerPlayable.state = PlayState.Paused;
#endif

            // GraphVisualizerClient.Show(graph, animator.name);
        }
 public void Initialize(Playable owner, PlayableGraph graph)
 {
     Mixer = AnimationMixerPlayable.Create(graph);
     owner.AddInput(Mixer, 0, 1.0f);
 }