public override Playable GeneratePlayable(PlayableGraph graph, Dictionary <string, List <BlendTreeController1D> > varTo1DBlendControllers, Dictionary <string, List <BlendTreeController2D> > varTo2DBlendControllers, List <BlendTreeController2D> all2DControllers) { var treeMixer = AnimationMixerPlayable.Create(graph, blendTree.Count, true); treeMixer.SetPropagateSetTime(true); if (blendTree.Count == 0) { return(treeMixer); } var controller = new BlendTreeController2D(blendVariable, blendVariable2, treeMixer, blendTree.Count); all2DControllers.Add(controller); varTo2DBlendControllers.GetOrAdd(blendVariable).Add(controller); varTo2DBlendControllers.GetOrAdd(blendVariable2).Add(controller); for (int j = 0; j < blendTree.Count; j++) { var blendTreeEntry = blendTree[j]; var clipPlayable = AnimationClipPlayable.Create(graph, GetClipToUseFor(blendTreeEntry.clip)); clipPlayable.SetApplyFootIK(true); clipPlayable.SetSpeed(speed); graph.Connect(clipPlayable, 0, treeMixer, j); controller.AddThresholdsForClip(j, blendTreeEntry.threshold1, blendTreeEntry.threshold2); } controller.OnAllThresholdsAdded(); controller.SetInitialValues(0f, 0f); return(treeMixer); }
public void Configure(Animator animator, EnemyAnimationConfig config) { graph = PlayableGraph.Create(); graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); mixer = AnimationMixerPlayable.Create(graph, 4); var clip = AnimationClipPlayable.Create(graph, config.Move); clip.Pause(); mixer.ConnectInput((int)Clip.Move, clip, 0); clip = AnimationClipPlayable.Create(graph, config.Intro); clip.SetDuration(config.Intro.length); clip.Pause(); mixer.ConnectInput((int)Clip.Intro, clip, 0); clip = AnimationClipPlayable.Create(graph, config.Outro); clip.SetDuration(config.Outro.length); clip.Pause(); mixer.ConnectInput((int)Clip.Outro, clip, 0); clip = AnimationClipPlayable.Create(graph, config.Dying); clip.SetDuration(config.Dying.length); clip.Pause(); mixer.ConnectInput((int)Clip.Dying, clip, 0); var output = AnimationPlayableOutput.Create(graph, "Enemy", animator); output.SetSourcePlayable(mixer); }
Playable CompileTrackPlayable(PlayableGraph graph, TrackAsset track, GameObject go, IntervalTree <RuntimeElement> tree, AppliedOffsetMode mode) { var mixer = AnimationMixerPlayable.Create(graph, track.clips.Length); for (int i = 0; i < track.clips.Length; i++) { var c = track.clips[i]; var asset = c.asset as PlayableAsset; if (asset == null) { continue; } var animationAsset = asset as AnimationPlayableAsset; if (animationAsset != null) { animationAsset.appliedOffsetMode = mode; } var source = asset.CreatePlayable(graph, go); if (source.IsValid()) { var clip = new RuntimeClip(c, source, mixer); tree.Add(clip); graph.Connect(source, 0, mixer, i); mixer.SetInputWeight(i, 0.0f); } } return(ApplyTrackOffset(graph, mixer, go, mode)); }
public void SetBlendTreePlayable(BlendTreeConfig[] configs) { m_BlendTreeConfigs = configs; if (configs != null && configs.Length > 0) { m_ClipLength = configs[0].clip.length; } if (!m_IsBlendTreeRootInit) { // 创建混合树混合节点,与状态playable相连 var graph = m_Playable.GetGraph(); m_BlendTreeMixer = AnimationMixerPlayable.Create(graph, m_BlendTreeConfigs.Length, true); graph.Connect(m_BlendTreeMixer, 0, m_Playable, 0); m_Playable.SetInputWeight(0, 1f); m_IsBlendTreeRootInit = true; } else if (m_BlendTreeMixer.GetInputCount() != m_BlendTreeConfigs.Length) { m_BlendTreeMixer.SetInputCount(m_BlendTreeConfigs.Length); } m_IsBlendTreeDirty = true; }
/// <summary> /// Use animation Playables API to control keyed values, blended between the first frame of 2 animation clips. /// </summary> /// <param name="valueForAdaptationCurve">A value to evaluate into adaptation curve producing a real blend value for 2 clips.</param> /// <param name="animator">The control target for animation playables. The clips used must be able to control the keyed fields traveling down from this animator component.</param> public void Adapt(float valueForAdaptationCurve, Animator animator) { if (!Adaptable) { return; } float blend = adaptationCurve.Evaluate(valueForAdaptationCurve); //Connect up a playable graph, evaluate once, then we're done with them. PlayableGraph pg = PlayableGraph.Create("AdaptationGraph"); pg.SetTimeUpdateMode(DirectorUpdateMode.Manual); var mixer = AnimationMixerPlayable.Create(pg, 2, normalizeWeights: true); //Not sure if the mixer should be "cross fade" like this, or should we do 0~1 weight over 1 weight? //But I think that's for AnimationLayerMixerPlayable ? mixer.SetInputWeight(inputIndex: 0, weight: 1 - blend); mixer.SetInputWeight(inputIndex: 1, weight: blend); var normalStateAcp = AnimationClipPlayable.Create(pg, normalState); var fullyAdaptedStateAcp = AnimationClipPlayable.Create(pg, fullyAdaptedState); pg.Connect(normalStateAcp, sourceOutputPort: 0, mixer, destinationInputPort: 0); pg.Connect(fullyAdaptedStateAcp, sourceOutputPort: 0, mixer, destinationInputPort: 1); var output = AnimationPlayableOutput.Create(pg, "AdaptationGraphOutput", animator); output.SetSourcePlayable(mixer); pg.Evaluate(); pg.Destroy(); }
public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, AnimGraph_DamageReaction settings) { m_settings = settings; m_graph = graph; m_EntityManager = entityManager; m_Owner = owner; m_rootMixer = AnimationLayerMixerPlayable.Create(graph, 2); m_rootMixer.SetInputWeight(0, 1f); // Setup blend mixer m_blendMixer = AnimationMixerPlayable.Create(graph, 4); GameDebug.Assert(m_settings.clips != null && m_settings.clips.Length > 0, "No animation clips added to damagereaction settings:{0}", settings.name); for (var i = 0; i < m_settings.clips.Length; i++) { var clipPlayable = AnimationClipPlayable.Create(graph, m_settings.clips[i]); clipPlayable.SetApplyFootIK(false); clipPlayable.Pause(); graph.Connect(clipPlayable, 0, m_blendMixer, i); if (m_settings.clips[i].length > m_reactionAnimDuration) { m_reactionAnimDuration = m_settings.clips[i].length; } } m_reactionAnimAngleSpan = 360 / m_blendMixer.GetInputCount(); graph.Connect(m_blendMixer, 0, m_rootMixer, m_blendMixerPort); m_rootMixer.SetLayerAdditive(m_blendMixerPort, true); }
// Use this for initialization void Start() { animator = GetComponent <Animator>(); mixer = AnimationMixerPlayable.Create(); mixer.SetInputs(new[] { idle, walk }); animator.Play(mixer); }
//============================================================================================ /** * @brief Constructor for the MxMLayer class which takes a playable instead of an animation clip. * Sets up all initial values and creates the layer's mixer. * * @param [int] a_id - the layer id (lowest layer value is 2 for MxMLayers) * @param [int] a_maxClips - the maximum number of clips that can be blended on this layer * @param [ref PlayableGraph] a_playableGraph - the playable graph that this layer lives on * @param [Playable] a_playable - the playable to use for this layer * @param [AvatarMask] a_mask - the mask to use with this player (Default null) * @param [float] a_weight - the starting weight of this layer (Default 0) * @param [bool] a_additive - whether the layer is additive or not (Default false) * *********************************************************************************************/ public MxMLayer(int a_id, int a_maxClips, ref AnimationLayerMixerPlayable a_layerMixer, Playable a_playable, AvatarMask a_mask = null, float a_weight = 0f, bool a_additive = false) { if(!a_playable.IsValid()) Debug.LogError("Error: Attempting to create an MxMLayer with an invalid playable"); if (!a_layerMixer.IsValid()) Debug.LogError("Error: Attempting to create an MxMLayer with an invalid layerMixer."); m_layerMixer = a_layerMixer; m_playableGraph = m_layerMixer.GetGraph(); Id = a_id; MaxClips = a_maxClips; PrimaryInputId = 0; Mixer = AnimationMixerPlayable.Create(m_playableGraph, a_maxClips, true); m_layerMixer.ConnectInput(Id, Mixer, 0); Mixer.ConnectInput(0, a_playable, 0); Mixer.SetInputWeight(0, 1f); Mask = a_mask; m_layerMixer.SetLayerAdditive((uint)Id, a_additive); m_layerMixer.SetInputWeight(Id, Mathf.Clamp01(a_weight)); SubLayerWeights = new float[a_maxClips]; SubLayerWeights[0] = 1f; }
public override Playable GeneratePlayable(PlayableGraph graph, Dictionary <string, List <BlendTreeController1D> > varTo1DBlendControllers, Dictionary <string, List <BlendTreeController2D> > varTo2DBlendControllers, Dictionary <string, float> blendVars) { var treeMixer = AnimationMixerPlayable.Create(graph, blendTree.Count, true); if (blendTree.Count == 0) { return(treeMixer); } float[] thresholds = new float[blendTree.Count]; for (int j = 0; j < blendTree.Count; j++) { var blendTreeEntry = blendTree[j]; var clipPlayable = AnimationClipPlayable.Create(graph, blendTreeEntry.clip); clipPlayable.SetSpeed(speed); graph.Connect(clipPlayable, 0, treeMixer, j); thresholds[j] = blendTreeEntry.threshold; } treeMixer.SetInputWeight(0, 1f); var blendController = new BlendTreeController1D(treeMixer, thresholds, val => blendVars[blendVariable] = val); varTo1DBlendControllers.GetOrAdd(blendVariable).Add(blendController); blendVars[blendVariable] = 0; return(treeMixer); }
private IEnumerator PlayStartAnimation() { // Trigger an "animationStart" event Camera.main.gameObject.GetComponent <PlayableDirector>().enabled = true; Camera.main.gameObject.GetComponent <PlayableDirector>().Play(); allow_input = false; animationStartEvent(); // Trying to change aniumation speed, not working AnimationMixerPlayable mixer = AnimationMixerPlayable.Create(Camera.main.gameObject.GetComponent <PlayableDirector> ().playableGraph, 1); mixer.SetSpeed(startAnimationSpeed); // When animation is over, trigger an "animationEnd" event while (true) { if (Camera.main.gameObject.GetComponent <PlayableDirector>().state != PlayState.Playing) { allow_input = true; animationEndEvent(); Debug.Log("Animation is Done."); yield break; } yield return(1); } }
void Start() { var animator = this.GetComponent <Animator>(); this.PlayableGraph = PlayableGraph.Create("Test"); this.AnimationLayerMixerPlayable = AnimationLayerMixerPlayable.Create(this.PlayableGraph, 0); this.AnimationLayerMixerPlayable.SetInputCount(0); var playableOutput = AnimationPlayableOutput.Create(this.PlayableGraph, "Animation", animator); playableOutput.SetSourcePlayable(this.AnimationLayerMixerPlayable); this.Layers.Add(AnimationMixerPlayable.Create(this.PlayableGraph)); ((AnimationMixerPlayable)this.Layers[0]).AddInput(AnimationClipPlayable.Create(this.PlayableGraph, this.FakeClip), 0); ((AnimationMixerPlayable)this.Layers[0]).AddInput(AnimationClipPlayable.Create(this.PlayableGraph, this.FakeClip), 0); this.Layers.Add(AnimationClipPlayable.Create(this.PlayableGraph, this.FakeClip)); this.Layers.Add(AnimationMixerPlayable.Create(this.PlayableGraph)); ((AnimationMixerPlayable)this.Layers[2]).AddInput(AnimationClipPlayable.Create(this.PlayableGraph, this.FakeClip), 0); this.AnimationLayerMixerPlayable.AddInput((Playable)this.Layers[0], 0); this.AnimationLayerMixerPlayable.AddInput((Playable)this.Layers[1], 0); this.AnimationLayerMixerPlayable.AddInput((Playable)this.Layers[2], 0); this.PlayableGraph.Play(); }
public Handler CreateMixer(int inputCount) { var index = m_SequenceHandlers.Count; if (index >= m_MaxMixingCount) { throw new System.InvalidOperationException(string.Format("More than the specified count of AnimationMixerPlayable have been added. (max: {0})", m_MaxMixingCount)); } var Weight = 0f; var mixer = AnimationMixerPlayable.Create(m_Graph, inputCount, false); m_SequenceMixer.ConnectInput(index, mixer, 0, Weight); var handler = new Handler(Type.Sequence, index, Weight, OnChangeWeight, OnRemove); handler.SetMixer(mixer); m_SequenceHandlers.Add(handler); var target = m_PlayableOutput.GetTarget(); if (target != null) { target.Rebind(); } return(handler); }
// Use this for initialization void Start() { animator = Entity.GetComponent <Animator>(); playableGraph = PlayableGraph.Create(); playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", Entity.GetComponent <Animator>()); previousAnimator = AnimatorControllerPlayable.Create(playableGraph, null); currentAnimatorPlayable = AnimatorControllerPlayable.Create(playableGraph, null); movementController = AnimatorControllerPlayable.Create(playableGraph, DefaultMovement); mixPlayable = AnimationMixerPlayable.Create(playableGraph, 2); playableGraph.Connect(previousAnimator, 0, mixPlayable, 0); playableGraph.Connect(currentAnimatorPlayable, 0, mixPlayable, 1); //playableGraph.Connect(movementController, 0, mixPlayable, 2); mixPlayable.SetInputWeight(0, 0); mixPlayable.SetInputWeight(1, 0); //mixPlayable.SetInputWeight(2, 1); layerMixer = AnimationLayerMixerPlayable.Create(playableGraph, 2); playableGraph.Connect(mixPlayable, 0, layerMixer, 0); playableGraph.Connect(movementController, 0, layerMixer, 1); layerMixer.SetInputWeight(0, 1); layerMixer.SetInputWeight(1, 1); //layerMixer.SetLayerAdditive(0, true); playableOutput.SetSourcePlayable(layerMixer); playableGraph.Play(); currentAnimatorController = null; init = true; }
public static AnimationController Create(GameObject go) { var animator = go.GetComponent <Animator>(); if (animator == null) { animator = go.AddComponent <Animator>(); animator.cullingMode = AnimatorCullingMode.AlwaysAnimate; } var graph = PlayableGraph.Create("Action"); var playable = ScriptPlayable <AnimationController> .Create(graph); var animOut = AnimationPlayableOutput.Create(graph, "Animation", animator); animOut.SetSourcePlayable(playable, 0); var mixer = AnimationMixerPlayable.Create(graph); playable.AddInput(mixer, 0, 1); var behaviour = playable.GetBehaviour(); behaviour.mGraph = graph; behaviour.mMixer = mixer; return(behaviour); }
//============================================================================================ /** * @brief Starts pose debugging in editor and creates the playable graph. * *********************************************************************************************/ public void StartPoseDebug(int a_animDataId) { if (m_animData.Length > 0 && a_animDataId < m_animData.Length) { CurrentAnimData = m_animData[a_animDataId]; } if (CurrentAnimData != null) { p_animator = GetComponent <Animator>(); m_animationStates = new MxMPlayableState[1]; if (p_animator) { MxMPlayableGraph = PlayableGraph.Create(); MxMPlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.Manual); var playableOutput = AnimationPlayableOutput.Create(MxMPlayableGraph, "Animation", p_animator); m_animationMixer = AnimationMixerPlayable.Create(MxMPlayableGraph, 1, true); playableOutput.SetSourcePlayable(m_animationMixer); m_animationMixer.SetInputWeight(0, 1f); basePosition = transform.position; baseRotation = transform.rotation; m_debugPosesActive = true; } else { m_debugPoses = false; m_debugPosesActive = false; } } }
// Use this for initialization void Start() { for (int i = 0; i < clipBindings.Length; i++) { int indx = i; clipBindings[indx].binding.Init(); clipBindings[indx].binding.Bind(() => StartClip(indx), (f) => UpdateClip(indx, f), () => EndClip(indx)); } animator = GetComponent <Animator>(); playableGraph = PlayableGraph.Create(); var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Anim", animator); mixer = AnimationMixerPlayable.Create(playableGraph, clipBindings.Length); playableOutput.SetSourcePlayable(mixer); playableClips = new AnimationClipPlayable[clipBindings.Length]; for (int i = 0; i < playableClips.Length; i++) { playableClips[i] = AnimationClipPlayable.Create(playableGraph, clipBindings[i].clip); playableGraph.Connect(playableClips[i], 0, mixer, i); } }
private void BuildOutput() { PlayableDirector.Evaluate(); if (PlayableDirector.playableGraph.IsValid()) { _outputTrackIndex = 0; _trackAsset = (PlayableDirector.playableAsset as TimelineAsset)?.GetOutputTrack(_outputTrackIndex); _originalOutput = (AnimationPlayableOutput)PlayableDirector.playableGraph.GetOutputByType <AnimationPlayableOutput>(_outputTrackIndex); _originalSourcePlayable = _originalOutput.GetSourcePlayable(); _clone = PlayableDirector.playableAsset.CreatePlayable(PlayableDirector.playableGraph, PlayableDirector.gameObject); _mixer = AnimationMixerPlayable.Create(PlayableDirector.playableGraph, 2); _cloneIndex = _mixer.AddInput(_clone, 0); _originalIndex = _mixer.AddInput(_originalSourcePlayable, 0, 1f); if (_originalOutput.IsOutputValid() && _originalOutput.GetTarget() != null) { _output = AnimationPlayableOutput.Create(PlayableDirector.playableGraph, "OverridedDirectorOutput" + GetInstanceID(), _originalOutput.GetTarget()); _output.SetSourcePlayable(_mixer); _output.SetSourceOutputPort(_originalOutput.GetSourceOutputPort()); _output.SetWeight(1f); _originalOutput.SetTarget(null); } else { Debug.Log("Original Director Output is invalid"); } } }
void Start() { playableGraph = PlayableGraph.Create("测试"); playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>()); // Wrap the clip in a playable m_Mixer = AnimationMixerPlayable.Create(playableGraph, 2); AnimationClipPlayable clipPlayable0 = AnimationClipPlayable.Create(playableGraph, clip0); AnimationClipPlayable clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1); playableGraph.Connect(clipPlayable0, 0, m_Mixer, 0); playableGraph.Connect(clipPlayable1, 0, m_Mixer, 1); m_Mixer.SetInputWeight(0, 1); m_Mixer.SetInputWeight(1, 0); // Connect the Playable to an output playableOutput.SetSourcePlayable(m_Mixer); playableOutput.SetSortingOrder(0); // Plays the Graph. leftTime = tranTime; playableGraph.Play(); }
public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_InAir settings) { m_settings = settings; m_EntityManager = entityManager; m_Owner = owner; m_AnimStateOwner = animStateOwner; GameDebug.Assert(entityManager.HasComponent <Character>(m_AnimStateOwner), "Owner has no Character component"); m_character = entityManager.GetComponentObject <Character>(m_AnimStateOwner); m_mainMixer = AnimationMixerPlayable.Create(graph); m_animInAir = AnimationClipPlayable.Create(graph, settings.animInAir); m_animInAir.Play(); m_animInAir.SetApplyFootIK(false); inAirPort = m_mainMixer.AddInput(m_animInAir, 0); m_animLandAntic = AnimationClipPlayable.Create(graph, settings.animLandAntic); m_animInAir.Play(); m_animLandAntic.SetApplyFootIK(false); landAnticPort = m_mainMixer.AddInput(m_animLandAntic, 0); m_layerMixer = AnimationLayerMixerPlayable.Create(graph); var port = m_layerMixer.AddInput(m_mainMixer, 0); m_layerMixer.SetInputWeight(port, 1); // Aim //if (settings.animAimDownToUp != null) // m_aimHandler = new AimVerticalHandler(m_layerMixer, settings.animAimDownToUp); // Actions m_actionAnimationHandler = new ActionAnimationHandler(m_layerMixer, settings.actionAnimations); }
public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Emote settings) { m_EntityManager = entityManager; m_Owner = owner; m_AnimStateOwner = animStateOwner; m_settings = settings; m_mixer = AnimationMixerPlayable.Create(graph, settings.emoteData.Length + 1); var ports = new int[m_settings.emoteData.Length + 1]; for (var i = 0; i < ports.Length; i++) { ports[i] = i; } m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_mixer, ports); for (int i = 0; i < settings.emoteData.Length; i++) { var clip = settings.emoteData[i].clip; var clipPlayable = AnimationClipPlayable.Create(graph, clip); clipPlayable.SetDuration(clip.length); clipPlayable.Pause(); var port = i + 1; m_mixer.ConnectInput(port, clipPlayable, 0); m_mixer.SetInputWeight(port, 0.0f); } }
Playable CreateInfiniteTrackPlayable(PlayableGraph graph, GameObject go, IntervalTree <RuntimeElement> tree, AppliedOffsetMode mode) { if (m_InfiniteClip == null) { return(Playable.Null); } var mixer = AnimationMixerPlayable.Create(graph, 1); // In infinite mode, we always force the loop mode of the clip off because the clip keys are offset in infinite mode // which causes loop to behave different. // The inline curve editor never shows loops in infinite mode. var playable = AnimationPlayableAsset.CreatePlayable(graph, m_InfiniteClip, m_InfiniteClipOffsetPosition, m_InfiniteClipOffsetEulerAngles, false, mode, infiniteClipApplyFootIK, AnimationPlayableAsset.LoopMode.Off); if (playable.IsValid()) { tree.Add(new InfiniteRuntimeClip(playable)); graph.Connect(playable, 0, mixer, 0); mixer.SetInputWeight(0, 1.0f); } if (!AnimatesRootTransform()) { return(mixer); } var rootTrack = isSubTrack ? (AnimationTrack)parent : this; return(rootTrack.ApplyTrackOffset(graph, mixer, go, mode)); }
public override Playable GeneratePlayable(PlayableGraph graph, Dictionary <string, List <BlendTreeController1D> > varTo1DBlendControllers, Dictionary <string, List <BlendTreeController2D> > varTo2DBlendControllers, Dictionary <string, float> blendVars) { var treeMixer = AnimationMixerPlayable.Create(graph, blendTree.Count, true); if (blendTree.Count == 0) { return(treeMixer); } Action <float> setVar1 = val => blendVars[blendVariable] = val; Action <float> setVar2 = val => blendVars[blendVariable2] = val; var controller = new BlendTreeController2D(blendVariable, blendVariable2, treeMixer, blendTree.Count, setVar1, setVar2); varTo2DBlendControllers.GetOrAdd(blendVariable).Add(controller); varTo2DBlendControllers.GetOrAdd(blendVariable2).Add(controller); blendVars[blendVariable] = 0; blendVars[blendVariable2] = 0; for (int j = 0; j < blendTree.Count; j++) { var blendTreeEntry = blendTree[j]; var clipPlayable = AnimationClipPlayable.Create(graph, blendTreeEntry.clip); clipPlayable.SetSpeed(speed); graph.Connect(clipPlayable, 0, treeMixer, j); controller.Add(j, blendTreeEntry.threshold1, blendTreeEntry.threshold2); } treeMixer.SetInputWeight(0, 1f); return(treeMixer); }
public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphStand settings) { m_Settings = settings; m_AnimState = controller.GetComponent <AnimStateData>(); m_PredictedState = controller.GetComponent <LogicStateData>(); m_Mask = 1 << LayerMask.NameToLayer("Default") | 1 << LayerMask.NameToLayer("Platform"); m_LocomotionMixer = AnimationMixerPlayable.Create(graph, (int)LocoMixerPort.Count); m_AnimIdle = AnimationClipPlayable.Create(graph, settings.animIdle); graph.Connect(m_AnimIdle, 0, m_LocomotionMixer, (int)LocoMixerPort.Idle); m_LocomotionMixer.SetInputWeight((int)LocoMixerPort.Idle, 1.0f); m_AnimTurnL = CreateTurnPlayable(graph, settings.animTurnL, m_LocomotionMixer, LocoMixerPort.TurnL); m_AnimTurnR = CreateTurnPlayable(graph, settings.animTurnR, m_LocomotionMixer, LocoMixerPort.TurnR); var ports = new int[] { (int)LocoMixerPort.Idle, (int)LocoMixerPort.TurnL, (int)LocoMixerPort.TurnR }; m_Transition = new SimpleTranstion <AnimationMixerPlayable>(m_LocomotionMixer, ports); if (settings.animTurnL.events.Length != 0) { m_LeftTurnFootFalls = ExtractFootFalls(settings.animTurnL); m_RightTurnFootFalls = ExtractFootFalls(settings.animTurnR); } var animator = controller.GetComponent <Animator>(); var skeleton = controller.GetComponent <Skeleton>(); var leftToes = skeleton.bones[skeleton.GetBoneIndex(settings.leftToeBone.GetHashCode())]; var rightToes = skeleton.bones[skeleton.GetBoneIndex(settings.rightToeBone.GetHashCode())]; var ikJob = new FootIkJob { settings = settings.footIK, leftToe = animator.BindStreamTransform(leftToes), rightToe = animator.BindStreamTransform(rightToes) }; m_FootIk = AnimationScriptPlayable.Create(graph, ikJob, 1); graph.Connect(m_LocomotionMixer, 0, m_FootIk, 0); m_FootIk.SetInputWeight(0, 1f); m_AimMixer = AnimationMixerPlayable.Create(graph, (int)AimMixerPort.Count, true); m_AnimAimLeft = CreateAimPlayable(graph, settings.animAimLeft, m_AimMixer, AimMixerPort.AimLeft); m_AnimAimMid = CreateAimPlayable(graph, settings.animAimMid, m_AimMixer, AimMixerPort.AimMid); m_AnimAimRight = CreateAimPlayable(graph, settings.animAimRight, m_AimMixer, AimMixerPort.AimRight); m_AdditiveMixer = AnimationLayerMixerPlayable.Create(graph); var locoMixerPort = m_AdditiveMixer.AddInput(m_FootIk, 0); m_AdditiveMixer.SetInputWeight(locoMixerPort, 1); var aimMixerPort = m_AdditiveMixer.AddInput(m_AimMixer, 0); m_AdditiveMixer.SetInputWeight(aimMixerPort, 1); m_AdditiveMixer.SetLayerAdditive((uint)aimMixerPort, true); }
public AnimMixer(PlayableGraph graph, int layer) : base(graph) { Layer = layer; _mixer = AnimationMixerPlayable.Create(graph); _playable = _mixer; }
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); }
public BlendTree2dSimpleDirectional(PlayableGraph graph, List <BlendSpaceNode> nodes) { m_Nodes = nodes; var count = m_Nodes.Count; m_Positions = new Vector2[count]; m_Clips = new AnimationClipPlayable[count]; m_Weights = new float[count]; m_Mixer = AnimationMixerPlayable.Create(graph, count); m_Mixer.SetPropagateSetTime(true); for (var i = 0; i < count; i++) { var node = m_Nodes[i]; var clip = AnimationClipPlayable.Create(graph, node.clip); node.clipLength = node.clip.length; clip.Play(); m_Mixer.ConnectInput(i, clip, 0); m_Clips[i] = clip; m_Nodes[i] = node; } masterSpeed = 1f; SetBlendPosition(new Vector2(0f, 0f)); }
//次のアニメーションのプレイアブル作成 private void SetNextAnimationPlayable() { if (setPlayAnimation != null && playableGraph.IsValid()) { if (mixer.IsValid()) { playableGraph.Disconnect(mixer, 0); playableGraph.Disconnect(mixer, 1); } else { mixer = AnimationMixerPlayable.Create(playableGraph, 2, true); var output = AnimationPlayableOutput.Create(playableGraph, "output", GetComponent <Animator>()); output.SetSourcePlayable(mixer); } if (_beforePlayAnimation.IsValid()) { _beforePlayAnimation.Destroy(); } if (_nowPlayAnimation.IsValid()) { _beforePlayAnimation = _nowPlayAnimation; } //今のアニメーションに設定 nowPlayAnimation = setPlayAnimation; _beforeNowPlayClip = nowPlayAnimation; setPlayAnimation = null; //アニメーションプレイアブル作成 _nowPlayAnimation = AnimationClipPlayable.Create(playableGraph, nowPlayAnimation); mixer.ConnectInput(0, _nowPlayAnimation, 0); mixer.ConnectInput(1, _beforePlayAnimation, 0); } }
public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_SprintBlend settings) { // TODO: Remove the members that are not needed m_Settings = settings; m_EntityManager = entityManager; m_Owner = owner; m_AnimStateOwner = animStateOwner; m_RunController = new AnimationControllerEntry(); m_RunController.controller = settings.runTemplate.Instatiate(entityManager, owner, graph, animStateOwner); m_RunController.animStateUpdater = m_RunController.controller as IGraphState; m_RunController.port = 0; m_SprintController = new AnimationControllerEntry(); m_SprintController.controller = settings.sprintTemplate.Instatiate(entityManager, owner, graph, animStateOwner); m_SprintController.animStateUpdater = m_SprintController.controller as IGraphState; m_SprintController.port = 1; m_RootMixer = AnimationMixerPlayable.Create(graph, 2); // TODO: Put into function? var outputPlayable = Playable.Null; var outputPort = 0; m_RunController.controller.GetPlayableOutput(m_RunController.port, ref outputPlayable, ref outputPort); graph.Connect(outputPlayable, outputPort, m_RootMixer, 0); m_SprintController.controller.GetPlayableOutput(m_SprintController.port, ref outputPlayable, ref outputPort); graph.Connect(outputPlayable, outputPort, m_RootMixer, 1); m_RootMixer.SetInputWeight(0, 1f); }
void Start() { // Creates the graph, the mixer and binds them to the Animator. playableGraph = PlayableGraph.Create(); var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>()); mixerPlayable = AnimationMixerPlayable.Create(playableGraph, 2); playableOutput.SetSourcePlayable(mixerPlayable); // Creates AnimationClipPlayable and connects them to the mixer. var clipPlayable0 = AnimationClipPlayable.Create(playableGraph, clip0); var clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1); playableGraph.Connect(clipPlayable0, 0, mixerPlayable, 0); playableGraph.Connect(clipPlayable1, 0, mixerPlayable, 1); // Plays the Graph. playableGraph.Play(); }
AnimationMixerPlayable Setup2() { animator = GetComponent <Animator>(); //animator.playableGraph.Destroy(); playableGraph = PlayableGraph.Create(nameof(PlayableComponent)); var playableOutput = AnimationPlayableOutput.Create(playableGraph, $"Animation Output", animator); // Animator controller var controllerPlayable = AnimatorControllerPlayable.Create(playableGraph, animator.runtimeAnimatorController); // Clip var clipPlayable = AnimationClipPlayable.Create(playableGraph, animationClips[0]); clipPlayable.Play(); // Mixer var mixer = AnimationMixerPlayable.Create(playableGraph, 2, true); playableGraph.Connect(controllerPlayable, 0, mixer, 0); mixer.SetInputWeight(0, 1); playableGraph.Connect(clipPlayable, 0, mixer, 1); mixer.SetInputWeight(1, 0); // Setup output playableOutput.SetSourcePlayable(mixer); playableGraph.Play(); return(mixer); }