//Create playable tree void CreateAndPlayTree() { var clipActions = clips.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(); // GraphVisualizerClient.Show(graph, animator.name); }
public static PlayableHandle PlayAnimatorController(Animator animator, RuntimeAnimatorController controller, out PlayableGraph graph) { graph = PlayableGraph.CreateGraph(); PlayableHandle result = graph.CreateAnimationOutput("AnimatorControllerPlayable", animator).sourcePlayable = graph.CreateAnimatorControllerPlayable(controller); graph.SyncUpdateAndTimeMode(animator); graph.Play(); return result; }
public static PlayableHandle PlayMixer(Animator animator, int inputCount, out PlayableGraph graph) { graph = PlayableGraph.CreateGraph(); PlayableHandle result = graph.CreateAnimationOutput("Mixer", animator).sourcePlayable = graph.CreateAnimationMixerPlayable(inputCount); graph.SyncUpdateAndTimeMode(animator); graph.Play(); return result; }
public static PlayableHandle PlayClip(Animator animator, AnimationClip clip, out PlayableGraph graph) { graph = PlayableGraph.CreateGraph(); PlayableHandle result = graph.CreateAnimationOutput("AnimationClip", animator).sourcePlayable = graph.CreateAnimationClipPlayable(clip); graph.SyncUpdateAndTimeMode(animator); graph.Play(); return result; }
public static void PlayAnimation(Animator animator, AnimationClip clip) { var graph = PlayableGraph.CreateGraph(); var output = graph.CreateAnimationOutput("Animation", animator); var playableClip = graph.CreateAnimationClipPlayable(clip); output.sourcePlayable = playableClip; graph.CreateAnimationClipPlayable(clip); graph.Play(); _playableGraphs.Add(graph); }
//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); }