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); }
void ShowGraph() { if (playableGraph.IsValid()) { GraphVisualizerClient.Show(playableGraph); } }
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); }
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(); }
/// <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"); }
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(); }
public void SetVizualizerName(string newName, bool forceShowInVisualizer = false) { if (forceShowInVisualizer) { showInVisualizer = true; } if (showInVisualizer) { GraphVisualizerClient.Hide(graph); GraphVisualizerClient.Show(graph, newName); } }
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(); }
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); }
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(); }
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; }
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); }