private void Awake()
    {
        Animator animator = GetComponent <Animator>();

        animator.updateMode  = m_AnimatorUpdateMode;
        animator.cullingMode = m_CullingMode;

#if !UNITY_2018_2_OR_NEWER
        Debug.LogError("Only support 2018.2 or newer!");
#else
#if UNITY_2018_2
        m_Graph = animator.playableGraph;
#else
        m_Graph = PlayableGraph.Create(this.name);
        AnimationPlayableOutput.Create(m_Graph, "ani", animator);
        m_Graph.Play();
#endif
#endif
        m_LayerManager = AnimationLayerMixerPlayable.Create(m_Graph, 2);
        m_Graph.GetOutput(0).SetSourcePlayable(m_LayerManager);

        m_Layer = new SAnimationLayer[m_LayerCount];
        for (int i = 0; i < m_LayerCount; i++)
        {
            m_Layer[i] = new SAnimationLayer(animator, m_LayerManager, i);
        }
    }
Esempio n. 2
0
    public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
    {
        if (Application.isPlaying)
        {
            PlayableOutput playableOutput = graph.GetOutput(0);

            if (playableOutput.IsOutputValid())
            {
                ScriptPlayable <TimeNotificationBehaviour> scriptPlayable =
                    (ScriptPlayable <TimeNotificationBehaviour>)playableOutput.GetSourcePlayable().GetInput(0);



                TimeNotificationBehaviour timeNotificationBehaviour = scriptPlayable.GetBehaviour();

                var simpleMarkers = this.GetMarkers().OfType <SimpleMarker>();

                m_Receiver = new ReceiverExample();

                playableOutput.AddNotificationReceiver(m_Receiver);

                foreach (var marker in simpleMarkers)
                {
                    scriptPlayable.GetBehaviour().AddNotification(marker.time, marker);
                }
            }
            else
            {
                playableOutput = ScriptPlayableOutput.Create(graph, "NotificationOutput");

                m_Receiver = new ReceiverExample();

                //why also here and in "outputs"
                playableOutput.AddNotificationReceiver(m_Receiver);

                //Create a TimeNotificationBehaviour
                var timeNotificationPlayable = ScriptPlayable <TimeNotificationBehaviour> .Create(graph);

                playableOutput.SetSourcePlayable(graph.GetRootPlayable(0));
                timeNotificationPlayable.GetBehaviour().timeSource = playableOutput.GetSourcePlayable();
                playableOutput.GetSourcePlayable().SetInputCount(playableOutput.GetSourcePlayable().GetInputCount() + 1);
                graph.Connect(timeNotificationPlayable, 0, playableOutput.GetSourcePlayable(), playableOutput.GetSourcePlayable().GetInputCount() - 1);

                var simpleMarkers = this.GetMarkers().OfType <SimpleMarker>();


                foreach (var marker in simpleMarkers)
                {
                    timeNotificationPlayable.GetBehaviour().AddNotification(marker.time, marker);
                }
            }
        }

        return(base.CreateTrackMixer(graph, go, inputCount));
    }
Esempio n. 3
0
        public void RegisterSignalReceiver(PlayableGraph graph)
        {
            var outputCount = graph.GetOutputCount();

            for (int i = 0; i < outputCount; i++)
            {
                var output = graph.GetOutput(i);

                output.AddNotificationReceiver(signalReceiver);
            }
        }
Esempio n. 4
0
    void AttachMixerToLayerMixer(AnimationMixerPlayable mixer, PlayableGraph g)
    {
        var playableOutput = g.GetOutput(0);
        var animatorMixer  = playableOutput.GetSourcePlayable();

        if (!animatorMixer.IsValid())
        {
            Debug.LogError("AnimatorMixerPlayable not found.");
        }
        var layerMixer = animatorMixer.GetInput(0);

        layerMixer.SetInputCount(1);
        layerMixer.ConnectInput(0, mixer, 0);
        //layerMixer.AddInput(mixer, 0);
    }
    protected override void Populate()
    {
        if (!m_PlayableGraph.IsValid())
        {
            return;
        }

        int outputs = m_PlayableGraph.GetOutputCount();

        for (int i = 0; i < outputs; i++)
        {
            var output = m_PlayableGraph.GetOutput(i);
            if (output.IsOutputValid())
            {
                AddNodeHierarchy(CreateNodeFromPlayableOutput(output));
            }
        }
    }
Esempio n. 6
0
    void AttachMixerToAnimationPlayableOutput(AnimationMixerPlayable mixer, PlayableGraph g)
    {
        var playableOutput = g.GetOutput(0);

        playableOutput.SetSourcePlayable(mixerPlayable);
    }
Esempio n. 7
0
        private void ResampleAnimation(ResampleFlags flags)
        {
            if (state.disabled)
            {
                return;
            }

            if (previewing == false)
            {
                return;
            }
            if (canPreview == false)
            {
                return;
            }

            s_ResampleAnimationMarker.Begin();
            if (state.activeAnimationClip != null)
            {
                var  animationPlayer  = state.activeAnimationPlayer;
                bool usePlayableGraph = animationPlayer is Animator;

                if (usePlayableGraph)
                {
                    var isValidGraph = m_Graph.IsValid();
                    if (isValidGraph)
                    {
                        var playableOutput = (AnimationPlayableOutput)m_Graph.GetOutput(0);
                        isValidGraph = playableOutput.GetTarget() == (Animator)animationPlayer;
                    }

                    if (HasFlag(flags, ResampleFlags.RebuildGraph) || !isValidGraph)
                    {
                        RebuildGraph((Animator)animationPlayer);
                    }
                }

                AnimationMode.BeginSampling();

                if (HasFlag(flags, ResampleFlags.FlushUndos))
                {
                    Undo.FlushUndoRecordObjects();
                }

                if (usePlayableGraph)
                {
                    if (m_UsesPostProcessComponents)
                    {
                        IAnimationWindowPreview[] previewComponents = FetchPostProcessComponents();
                        if (previewComponents != null)
                        {
                            foreach (var component in previewComponents)
                            {
                                component.UpdatePreviewGraph(m_Graph);
                            }
                        }
                    }

                    if (!m_CandidateClip.empty)
                    {
                        AnimationMode.AddCandidates(state.activeRootGameObject, m_CandidateClip);
                    }

                    m_ClipPlayable.SetSampleRate(playing ? -1 : state.activeAnimationClip.frameRate);

                    AnimationMode.SamplePlayableGraph(m_Graph, 0, time.time);

                    // This will cover euler/quaternion matching in basic playable graphs only (animation clip + candidate clip).
                    AnimationUtility.SampleEulerHint(state.activeRootGameObject, state.activeAnimationClip, time.time, WrapMode.Clamp);
                    if (!m_CandidateClip.empty)
                    {
                        AnimationUtility.SampleEulerHint(state.activeRootGameObject, m_CandidateClip, time.time, WrapMode.Clamp);
                    }
                }
                else
                {
                    AnimationMode.SampleAnimationClip(state.activeRootGameObject, state.activeAnimationClip, time.time);
                    if (!m_CandidateClip.empty)
                    {
                        AnimationMode.SampleCandidateClip(state.activeRootGameObject, m_CandidateClip, 0f);
                    }
                }

                AnimationMode.EndSampling();

                if (HasFlag(flags, ResampleFlags.RefreshViews))
                {
                    SceneView.RepaintAll();
                    InspectorWindow.RepaintAllInspectors();

                    // Particle editor needs to be manually repainted to refresh the animated properties
                    var particleSystemWindow = ParticleSystemWindow.GetInstance();
                    if (particleSystemWindow)
                    {
                        particleSystemWindow.Repaint();
                    }
                }
            }
            s_ResampleAnimationMarker.End();
        }
Esempio n. 8
0
    public void Play(float speed)
    {
        graph.GetOutput(0).GetSourcePlayable().SetSpeed(speed);

        graph.Play();
    }