コード例 #1
0
    public void Initialize(EntityManager entityManager, Entity owner, Entity character)
    {
        m_Animator = entityManager.GetComponentObject <Animator>(owner);

        m_Animator.fireEvents = fireAnimationEvents;

        GameDebug.Assert(animStateDefinition != null, "No animStateDefinition defined for AnimStateController:" + this.name);

        Profiler.BeginSample("Create graph");
        m_PlayableGraph = PlayableGraph.Create(name);
        Profiler.EndSample();

#if UNITY_EDITOR
        GraphVisualizerClient.Show(m_PlayableGraph);
#endif

        Profiler.BeginSample("Instantiate playables");
        m_animGraph = animStateDefinition.Instatiate(entityManager, owner, m_PlayableGraph, character);
        Profiler.EndSample();

        m_animGraphLogic = m_animGraph as IGraphLogic;

        m_PlayableGraph.Play();

        var outputPlayable = Playable.Null;
        var outputPort     = 0;
        m_animGraph.GetPlayableOutput(0, ref outputPlayable, ref outputPort);

        // Set graph output
        var animationOutput = AnimationPlayableOutput.Create(m_PlayableGraph, "Animator", m_Animator);
        animationOutput.SetSourcePlayable(outputPlayable);
        animationOutput.SetSourceOutputPort(outputPort);
    }
コード例 #2
0
        private void Awake()
        {
            this.SafeGetComponent(ref _animator);

            // for objects in bundles, it'll be pre-scrubbed out
            #if UNITY_EDITOR
            _animator.runtimeAnimatorController = null;
            #endif

            _graph = PlayableGraph.Create();

            _playSelectorOwner = ScriptPlayable <PlaySelectorPlayable> .Create(_graph);

            _playSelector = _playSelectorOwner.GetBehaviour();
            _playSelector.Initialize(_playSelectorOwner, _graph);

            var playableOutput = AnimationPlayableOutput.Create(_graph, "Animation", _animator);
            playableOutput.SetSourcePlayable(_playSelectorOwner);
            playableOutput.SetSourceInputPort(0);

            #if UNITY_EDITOR
            GraphVisualizerClient.Show(_graph, string.Format("{0}.PlayObjectAnimations", gameObject.name));
            #endif

            _graph.Play();
            _playSelectorOwner.Pause();
        }
コード例 #3
0
    PlayableGraph CreatePlayableGraph()
    {
        // Create a Mixer.
        PlayableGraph g = animator.playableGraph;

        //var playableOutput = AnimationPlayableOutput.Create(g, "AnimationOutput", animator);

        mixerPlayable = AnimationMixerPlayable.Create(g, AnimationMapping.Length + 1);

        // Create a 'neutral' playable with low weight
        var neutral = AnimationClipPlayable.Create(g, NeutralAnimation);

        g.Connect(neutral, 0, mixerPlayable, 0);
        // Create a playable for every AffdexPlayable and connect inputs to the Mixer
        for (int i = 0; i < AnimationMapping.Length; i++)
        {
            var playable = AnimationClipPlayable.Create(g, AnimationMapping[i].CubismExpression);
            Debug.Log("Connection: " + i + 1);
            g.Connect(playable, 0, mixerPlayable, i + 1);
        }

        if (AttemptLayerMix)
        {
            AttachMixerToLayerMixer(mixerPlayable, g);
        }
        else
        {
            AttachMixerToAnimationPlayableOutput(mixerPlayable, g);
        }
        g.Play();
        GraphVisualizerClient.Show(g, "Affdex");
        rawWeights = new float[AnimationMapping.Length];
        return(g);
    }
コード例 #4
0
        private PlayableGraph GetSelectedGraphInToolBar(List <PlayableGraph> graphs, PlayableGraph currentGraph)
        {
            EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.Width(position.width));

            List <string> options = new List <string>(graphs.Count);

            foreach (var graph in graphs)
            {
                string name = GraphVisualizerClient.GetName(graph);
                if (name == null)
                {
                    name = graph.GetEditorName();
                }
                options.Add(name.Length != 0 ? name : "[Unnamed]");
            }

            options.Sort();

            int currentSelection = graphs.IndexOf(currentGraph);
            int newSelection     = EditorGUILayout.Popup(currentSelection != -1 ? currentSelection : 0, options.ToArray(), GUILayout.Width(200));

            PlayableGraph selectedGraph = new PlayableGraph();

            if (newSelection != -1)
            {
                selectedGraph = graphs[newSelection];
            }

            GUILayout.FlexibleSpace();
            EditorGUILayout.EndHorizontal();

            return(selectedGraph);
        }
コード例 #5
0
 void ShowGraph()
 {
     if (playableGraph.IsValid())
     {
         GraphVisualizerClient.Show(playableGraph);
     }
 }
コード例 #6
0
        private void OnDestroy()
        {
            #if UNITY_EDITOR
            GraphVisualizerClient.Hide(_graph);
            #endif

            _graph.Destroy();
        }
コード例 #7
0
        /// <summary>
        /// Use this for initialization
        /// </summary>
        private void Awake()
        {
            // Create playable graph.
            playableGraph = PlayableGraph.Create();

            // Create playable output node.
            var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>());

            // Create animation mixer playerable node.
            int animationClipsLength = animationClips == null ? 0 : animationClips.Length;

            animationMixer = AnimationMixerPlayable.Create(playableGraph, animationClipsLength);

            // Connect the mixer to an output.
            playableOutput.SetSourcePlayable(animationMixer);

            // Create clip playable node for all animations.
            for (int i = 0; i < animationClipsLength; i++)
            {
                // Wrap the clip in a playable.
                var clipPlayable = AnimationClipPlayable.Create(playableGraph, animationClips[i]);

                playableGraph.Connect(clipPlayable, 0, animationMixer, i);
                animationMixer.SetInputWeight(i, 0.0f);
            }

            // Create audio output node.
            var audioOutput = AudioPlayableOutput.Create(playableGraph, "Audio", GetComponent <AudioSource>());

            // Create audio mixer playerable node.
            int audioClipsLength = audioClips == null ? 0 : audioClips.Length;

            audioMixer = AudioMixerPlayable.Create(playableGraph, audioClipsLength);

            // Connect the mixer to an output.
            audioOutput.SetSourcePlayable(audioMixer);

            // Create clip playable node for all audios.
            for (int i = 0; i < audioClipsLength; i++)
            {
                // Wrap the clip in a playable.
                var clipPlayable = AudioClipPlayable.Create(playableGraph, audioClips[i], false);

                playableGraph.Connect(clipPlayable, 0, audioMixer, i);
                audioMixer.SetInputWeight(i, 0.0f);
            }

            // Init the animation component list.
            currentAnimationList = new List <AnimationComponent>();

            // Plays the playable graph.
            playableGraph.Play();

            // Register graph visual client to show debug messages.
            GraphVisualizerClient.Show(playableGraph, "Animation Engine Graph");
        }
コード例 #8
0
 private void AnimatorAwake()
 {
     PlayableGraph = PlayableGraph.Create();
     Anim          = GetParentActor().GetComponentInChildren <Animator>();
     Debug.Assert(Anim != null, "Animator not found.  Player Animation will not work.");
     PlayableOutput = AnimationPlayableOutput.Create(PlayableGraph, "Animation", Anim);
     CreateAllClipPlayables();
     PlayableOutput.SetSourcePlayable(ClipPlayables["sideJump"]);
     PlayableGraph.Play();
     GraphVisualizerClient.Show(PlayableGraph, "MSV_Animator");
 }
    public void CannotShowSameGraphTwice()
    {
        var graph1 = CreatePlayableGraph("test1");

        GraphVisualizerClient.Show(graph1);
        var graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(1));

        graph1.Destroy();
    }
コード例 #10
0
        public void SetVizualizerName(string newName, bool forceShowInVisualizer = false)
        {
            if (forceShowInVisualizer)
            {
                showInVisualizer = true;
            }

            if (showInVisualizer)
            {
                GraphVisualizerClient.Hide(graph);
                GraphVisualizerClient.Show(graph, newName);
            }
        }
コード例 #11
0
        private void Awake()
        {
            EnsureVersionUpgraded();
            hasAwoken = true;

            if (layers.Length == 0)
            {
                return;
            }

            //The playable graph is a directed graph of Playables.
            graph = PlayableGraph.Create();

            // The AnimationPlayableOutput links the graph with an animator that plays the graph.
            // I think we can ditch the animator, but the documentation is kinda sparse!
            outputAnimator = gameObject.EnsureComponent <Animator>();
            AnimationPlayableOutput animOutput = AnimationPlayableOutput.Create(graph, $"{name}_animation_player", outputAnimator);

            for (var i = 0; i < layers.Length; i++)
            {
                layers[i].InitializeSelf(graph);
            }

            if (layers.Length <= 1)
            {
                rootPlayable = layers[0].stateMixer;
            }
            else
            {
                var layerMixer = AnimationLayerMixerPlayable.Create(graph, layers.Length);

                for (var i = 0; i < layers.Length; i++)
                {
                    layers[i].InitializeLayerBlending(graph, i, layerMixer);
                }

                rootPlayable = layerMixer;
            }

            animOutput.SetSourcePlayable(rootPlayable);

            //fun fact: default is DSPClock!
            graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
            graph.Play();

            visualizerClientName = name + " AnimationPlayer";
            GraphVisualizerClient.Show(graph, visualizerClientName);
        }
    public void CanClearGraphs()
    {
        var graph1 = CreatePlayableGraph("test1");
        var graph2 = CreatePlayableGraph("test2");

        GraphVisualizerClient.Show(graph1);
        GraphVisualizerClient.Show(graph2);
        var graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(2));

        GraphVisualizerClient.ClearGraphs();
        graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(0));

        graph1.Destroy();
        graph2.Destroy();
    }
コード例 #13
0
        private List <PlayableGraph> GetGraphList()
        {
            var selectedGraphs = new List <PlayableGraph>();

            foreach (var clientGraph in GraphVisualizerClient.GetGraphs())
            {
                if (clientGraph.IsValid())
                {
                    selectedGraphs.Add(clientGraph);
                }
            }

            if (selectedGraphs.Count == 0)
            {
                selectedGraphs = m_Graphs.ToList();
            }

            return(selectedGraphs);
        }
    public void CanShowGraph()
    {
        var graph1 = CreatePlayableGraph("test1");
        var graph2 = CreatePlayableGraph("test2");

        GraphVisualizerClient.Show(graph1);
        var graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(1));
        Assert.That(graphs[0].GetEditorName(), Is.EqualTo(graph1.GetEditorName()));

        GraphVisualizerClient.Show(graph2);
        graphs = GraphVisualizerClient.GetGraphs().ToArray();

        Assert.That(graphs.Length, Is.EqualTo(2));
        Assert.That(graphs[0].GetEditorName(), Is.EqualTo(graph1.GetEditorName()));
        Assert.That(graphs[1].GetEditorName(), Is.EqualTo(graph2.GetEditorName()));

        graph1.Destroy();
        graph2.Destroy();
    }
コード例 #15
0
        void CreatePlayableGraph()
        {
            playableGraph = PlayableGraph.Create();
            var playableOutput = AnimationPlayableOutput.Create(playableGraph, "PlayableGraphSample", GetComponent <Animator>());

            mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2);
            playableOutput.SetSourcePlayable(mixerPlayable);
            var clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1);
            var clipPlayable2 = AnimationClipPlayable.Create(playableGraph, clip2);

            //playableGraph.Connect(clipPlayable1,0,mixerPlayable,0);
            //playableGraph.Connect(clipPlayable2, 0, mixerPlayable, 1);
            //上面的两行与下面的两行代码是等价的
            mixerPlayable.ConnectInput(0, clipPlayable1, 0);
            mixerPlayable.ConnectInput(1, clipPlayable2, 0);
            weight = Mathf.Clamp01(weight);
            mixerPlayable.SetInputWeight(0, 1.0f - weight);//分别设置两个数据端口的权重
            mixerPlayable.SetInputWeight(1, weight);
            playableGraph.Play();
            GraphVisualizerClient.Show(playableGraph, this.GetType().Name);
        }
コード例 #16
0
    void Start()
    {
        m_Graph = PlayableGraph.Create("TestGraph");
        GraphVisualizerClient.Show(m_Graph);
        m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
        m_Output = AnimationPlayableOutput.Create(m_Graph, "Animation", GetComponent <Animator>());

        m_Mixer = AnimationMixerPlayable.Create(m_Graph, 2);
        m_Output.SetSourcePlayable(m_Mixer);

        AnimationClipPlayable clipPlayable0 = AnimationClipPlayable.Create(m_Graph, clip0);
        AnimationClipPlayable clipPlayable1 = AnimationClipPlayable.Create(m_Graph, clip1);

        m_Graph.Connect(clipPlayable0, 0, m_Mixer, 0);
        m_Graph.Connect(clipPlayable1, 0, m_Mixer, 1);

        m_Mixer.SetInputWeight(0, 1);
        m_Mixer.SetInputWeight(1, 0);

        m_Graph.Play();

        leftTime = tranTime;
    }
コード例 #17
0
        void Start()
        {
            m_AnimState      = GetComponent <AnimStateData>();
            m_PredictedState = GetComponent <LogicStateData>();

            m_PlayableGraph  = PlayableGraph.Create(name);
            m_AnimGraph      = animStateDefinition.Instatiate(this, m_PlayableGraph);
            m_AnimGraphLogic = m_AnimGraph as IGraphLogic;
            m_AnimGraphState = m_AnimGraph as IGraphState;

            m_PlayableGraph.Play();
#if UNITY_EDITOR
            GraphVisualizerClient.Show(m_PlayableGraph);
#endif

            var outputPlayable = Playable.Null;
            var outputPort     = 0;
            m_AnimGraph.GetPlayableOutput(0, ref outputPlayable, ref outputPort);

            var animator = GetComponentInChildren <Animator>();
            animator.fireEvents = enableAnimatorEvent;
            var animationOutput = AnimationPlayableOutput.Create(m_PlayableGraph, "Animator", animator);
            animationOutput.SetSourcePlayable(outputPlayable, outputPort);
        }
 public void TearDown()
 {
     // Clear graphs between tests, otherwise graphs are still referenced across tests.
     GraphVisualizerClient.ClearGraphs();
 }
コード例 #19
0
    void OnGUI()
    {
        // Create a list of all the playable graphs extracted.
        IList <PlayableGraphInfo> graphInfos = new List <PlayableGraphInfo>();

        PlayableGraphInfo info;

        // If we requested, we extract automatically the PlayableGraphs from all the components
        // that are in the current scene.
        if (m_AutoScanScene)
        {
            // This code could be generalized, maybe if we added a IHasPlayableGraph Interface.
            IList <PlayableDirector> directors = FindObjectsOfType <PlayableDirector>();
            if (directors != null)
            {
                foreach (var director in directors)
                {
                    if (director.playableGraph.IsValid())
                    {
                        info.name  = director.name;
                        info.graph = director.playableGraph;
                        graphInfos.Add(info);
                    }
                }
            }

            IList <Animator> animators = FindObjectsOfType <Animator>();
            if (animators != null)
            {
                foreach (var animator in animators)
                {
                    if (animator.playableGraph.IsValid())
                    {
                        info.name  = animator.name;
                        info.graph = animator.playableGraph;
                        graphInfos.Add(info);
                    }
                }
            }
        }

        if (GraphVisualizerClient.GetGraphs() != null)
        {
            foreach (var clientGraph in GraphVisualizerClient.GetGraphs())
            {
                if (clientGraph.Key.IsValid())
                {
                    info.name  = clientGraph.Value;
                    info.graph = clientGraph.Key;
                    graphInfos.Add(info);
                }
            }
        }

        // Early out if there is no graphs.
        if (graphInfos.Count == 0)
        {
            ShowMessage("No PlayableGraph in the scene");
            return;
        }

        GUILayout.BeginVertical();
        m_CurrentGraphInfo = GetSelectedGraphInToolBar(graphInfos, m_CurrentGraphInfo);
        GUILayout.EndVertical();

        if (!m_CurrentGraphInfo.graph.IsValid())
        {
            ShowMessage("Selected PlayableGraph is invalid");
            return;
        }

        var graph = new PlayableGraphVisualizer(m_CurrentGraphInfo.graph);

        graph.Refresh();

        if (graph.IsEmpty())
        {
            ShowMessage("Selected PlayableGraph is empty");
            return;
        }

        if (m_Layout == null)
        {
            m_Layout = new ReingoldTilford();
        }

        m_Layout.CalculateLayout(graph);

        var graphRect = new Rect(0, s_ToolbarHeight, position.width, position.height - s_ToolbarHeight);

        if (m_Renderer == null)
        {
            m_Renderer = new DefaultGraphRenderer();
        }

        m_Renderer.Draw(m_Layout, graphRect, m_GraphSettings);
    }