// 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; }
// Update is called once per frame void Update() { if (!CurrentAnimatorPlayable.IsNull() && CurrentAnimatorPlayable.GetCurrentAnimatorStateInfo(0).IsTag(AnimTagLock)) { movementLayerWeight -= 0.2f / Time.deltaTime; movementLayerWeight = movementLayerWeight < 0 ? 0 : movementLayerWeight; layerMixer.SetInputWeight(1, 0); } else { movementLayerWeight += 0.2f / Time.deltaTime; movementLayerWeight = movementLayerWeight > 1 ? 1 : movementLayerWeight; layerMixer.SetInputWeight(1, 1); } /*layerMixer.SetInputWeight(1, movementLayerWeight); * layerMixer.SetInputWeight(0, 1 - movementLayerWeight);*/ if (transTotalTime <= 0) { weight = 1; } else { weight = Mathf.Clamp01(transTime / transTotalTime); } transTime += Time.deltaTime; mixPlayable.SetInputWeight((currentConnectedIdx + 1) % 2, 1 - weight); mixPlayable.SetInputWeight(currentConnectedIdx, weight); //weight = transTotalTime }
public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphJump settings) { m_AnimState = controller.GetComponent <AnimStateData>(); m_Mixer = AnimationLayerMixerPlayable.Create(graph, 2); m_AnimJump = AnimationClipPlayable.Create(graph, settings.animJump); m_AnimJump.SetApplyFootIK(true); m_AnimJump.SetDuration(settings.animJump.length); m_AnimJump.Pause(); graph.Connect(m_AnimJump, 0, m_Mixer, 0); m_Mixer.SetInputWeight(0, 1); var gameJumpHeight = 1.0f; var gameJumpDuration = 0.3f; var animJumpVel = settings.jumpHeight / settings.animJump.length; var characterJumpVel = gameJumpHeight / gameJumpDuration; m_PlaySpeed = characterJumpVel / animJumpVel; m_AnimAim = AnimationClipPlayable.Create(graph, settings.animAim); m_AnimAim.SetApplyFootIK(false); m_AnimAim.Pause(); graph.Connect(m_AnimAim, 0, m_Mixer, 1); m_Mixer.SetInputWeight(1, 1); m_Mixer.SetLayerAdditive(1, true); m_AimTimeFactor = settings.animAim.length / 180.0f; }
public override void OnUpdate(TimelineGraphModificationManager manager, AnimationLayerMixerPlayable mixer) { if (!playable.IsValid()) { return; } if (!Clip) { return; } if (proceedTimeInEditMode && !Application.isPlaying) { var newTime = playable.GetTime() + Time.deltaTime; playable.SetTime(newTime); } if (Loop && playable.GetTime() > Clip.length) { playable.SetTime(0); } mixer.SetInputWeight(index, Weight01); if (Additive) { mixer.SetInputWeight(0, 1); } else { mixer.SetInputWeight(0, 1 - Weight01); } }
//Create and play the playable graph void CreateAndPlayTree() { graph = PlayableGraph.Create(); animationOutput = AnimationPlayableOutput.Create(graph, "Animation", animator); masterMixer = AnimationLayerMixerPlayable.Create(graph, siblingTracks.Count + 2); for (var i = 0; i < siblingTracks.Count; i++) { var animatorTrack = siblingTracks[i]; var mix = animatorTrack.CreateClipsMixer(graph); graph.Connect(mix, 0, masterMixer, i); masterMixer.SetInputWeight(i, 1f); if (animatorTrack.mask != null) { masterMixer.SetLayerMaskFromAvatarMask((uint)i, animatorTrack.mask); } masterMixer.SetLayerAdditive((uint)i, animatorTrack.blendMode == AnimationBlendMode.Additive); } animatorPlayable = AnimatorControllerPlayable.Create(graph, animator.runtimeAnimatorController); graph.Connect(animatorPlayable, 0, masterMixer, siblingTracks.Count + 1); masterMixer.SetInputWeight(siblingTracks.Count + 1, 0f); animationOutput.SetSourcePlayable(masterMixer); // graph.Play(); // masterMixer.Pause(); // GraphVisualizerClient.Show(graph, this.name); }
//... protected override void OnUpdate(float time, float previousTime) { if (isMasterTrack) { if (animator == null || !animator.gameObject.activeInHierarchy || !graph.IsValid()) { return; } var totalSiblingWeight = 0f; for (var i = 0; i < siblingTracks.Count; i++) { var siblingWeight = siblingTracks[i].compoundTrackWeight; masterMixer.SetInputWeight(i, siblingWeight); totalSiblingWeight += siblingWeight; } var animatorWeight = totalSiblingWeight < 1 ? 1 - totalSiblingWeight : 0; masterMixer.SetInputWeight(siblingTracks.Count + 1, animatorWeight); graph.Evaluate(time - previousTime); if (useRootMotion && useBakedRootMotion) { ApplyBakedRootMotion(time); } } }
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 void Update() { if (this.gesturePlaying) { if (this.gesturePlayable.IsDone()) { this.StopGesture(); return; } else { float time = (float)this.gesturePlayable.GetTime(); if (time + this.gestureTransitionOut >= this.gestureDuration) { float t = (this.gestureDuration - time) / this.gestureTransitionOut; t = Mathf.Clamp01(t); mixer.SetInputWeight(1, t); } else if (time <= this.gestureTransitionIn) { float t = time / this.gestureTransitionIn; t = Mathf.Clamp01(t); mixer.SetInputWeight(1, t); } else { mixer.SetInputWeight(1, 1.0f); } } } }
// Use this for initialization void Start() { animator = GetComponent <Animator>(); playableGraph = PlayableGraph.Create("ClairePlayableGraph"); playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", animator); // Create Top Level Layer Mixer AnimationLayerMixerPlayable mixerLayerPlayable = AnimationLayerMixerPlayable.Create(playableGraph, 2); playableOutput.SetSourcePlayable(mixerLayerPlayable); // Create an Emotion Mixer mixerEmotionPlayable = AnimationMixerPlayable.Create(playableGraph, 4); // Wrap AnimController runtimeAnimController = animator.runtimeAnimatorController; var runtimeAnimControllerPlayable = AnimatorControllerPlayable.Create(playableGraph, runtimeAnimController); // Connect to Top Level Layer Mixer playableGraph.Connect(runtimeAnimControllerPlayable, 0, mixerLayerPlayable, 0); playableGraph.Connect(mixerEmotionPlayable, 0, mixerLayerPlayable, 1); mixerLayerPlayable.SetInputWeight(0, 1.0f); mixerLayerPlayable.SetInputWeight(1, 1.0f); mixerLayerPlayable.SetLayerMaskFromAvatarMask(1, headMask); // Wrap the clips in a playable pHappy = AnimationClipPlayable.Create(playableGraph, happy); pHappyTransitionIn = AnimationClipPlayable.Create(playableGraph, happyTransitionIn); pAngry = AnimationClipPlayable.Create(playableGraph, angry); pAngryTransitionIn = AnimationClipPlayable.Create(playableGraph, angryTransitionIn); pTPose = AnimationClipPlayable.Create(playableGraph, tPose); // Setup Durations for IsDone Checks pHappyTransitionIn.SetDuration(happyTransitionIn.length); pAngryTransitionIn.SetDuration(angryTransitionIn.length); // Connect to Emotion Mixer mixerEmotionPlayable.SetInputCount(5); // InputCount needs to be == to the number of connected clips (for normalization purposes) playableGraph.Connect(pHappy, 0, mixerEmotionPlayable, 0); playableGraph.Connect(pHappyTransitionIn, 0, mixerEmotionPlayable, 1); playableGraph.Connect(pAngry, 0, mixerEmotionPlayable, 2); playableGraph.Connect(pAngryTransitionIn, 0, mixerEmotionPlayable, 3); playableGraph.Connect(pTPose, 0, mixerEmotionPlayable, 4); Debug.Log("INputLength: " + mixerEmotionPlayable.GetInputCount()); // Activate T Pose mixerEmotionPlayable.SetInputWeight(4, 1.0f); Debug.Log("Happy Transition Time: " + pHappyTransitionIn.GetDuration()); // Plays the Graph playableGraph.Play(); }
// Start is called before the first frame update void Start() { animator = GetComponent <Animator>(); //smr = childwithSkinnedMeshRenderer.GetComponent<SkinnedMeshRenderer>(); //blendShapeCount = smr.sharedMesh.blendShapeCount; playableGraph = PlayableGraph.Create("ClairePlayableGraph"); playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", animator); // Create Top Level Layer Mixer AnimationLayerMixerPlayable mixerLayerPlayable = AnimationLayerMixerPlayable.Create(playableGraph, 2); playableOutput.SetSourcePlayable(mixerLayerPlayable); // Wrap AnimController runtimeAnimController = animator.runtimeAnimatorController; var runtimeAnimControllerPlayable = AnimatorControllerPlayable.Create(playableGraph, runtimeAnimController); // Create an Emotion Mixer mixerEmotionPlayable = AnimationMixerPlayable.Create(playableGraph, 10, true); //playableOutput.SetSourcePlayable(mixerEmotionPlayable); // Connect to Top Level Layer Mixer playableGraph.Connect(runtimeAnimControllerPlayable, 0, mixerLayerPlayable, 0); playableGraph.Connect(mixerEmotionPlayable, 0, mixerLayerPlayable, 1); mixerLayerPlayable.SetInputWeight(0, 1.0f); mixerLayerPlayable.SetInputWeight(1, 1.0f); mixerLayerPlayable.SetLayerMaskFromAvatarMask(1, headMask); // Wrap the clips in a playable pInterested = AnimationClipPlayable.Create(playableGraph, interested); pInterested2 = AnimationClipPlayable.Create(playableGraph, interested2); pEntertained = AnimationClipPlayable.Create(playableGraph, entertained); pUncomfortable = AnimationClipPlayable.Create(playableGraph, uncomfortable); pConfused = AnimationClipPlayable.Create(playableGraph, confused); pBored = AnimationClipPlayable.Create(playableGraph, bored); pNeutral = AnimationClipPlayable.Create(playableGraph, neutral); // Connect to Emotion Mixer //mixerEmotionPlayable.SetInputCount(5); // InputCount needs to be == to the number of connected clips (for normalization purposes) playableGraph.Connect(pInterested, 0, mixerEmotionPlayable, 0); playableGraph.Connect(pInterested2, 0, mixerEmotionPlayable, 1); playableGraph.Connect(pEntertained, 0, mixerEmotionPlayable, 2); playableGraph.Connect(pUncomfortable, 0, mixerEmotionPlayable, 3); playableGraph.Connect(pConfused, 0, mixerEmotionPlayable, 4); playableGraph.Connect(pBored, 0, mixerEmotionPlayable, 5); playableGraph.Connect(pNeutral, 0, mixerEmotionPlayable, 6); // Plays the Graph playableGraph.Play(); }
// INITIALIZERS: ------------------------------------------------------------------------------ public Playable Setup(PlayableGraph graph, Playable input) { this.graph = graph; this.mixer = AnimationLayerMixerPlayable.Create(this.graph, 2); this.mixer.ConnectInput(0, input, 0); this.mixer.ConnectInput(1, Playable.Null, 0); mixer.SetInputWeight(0, 1.0f); mixer.SetInputWeight(1, 0.0f); return(this.mixer); }
//private AnimatorController animController; void Start() { playableGraph = PlayableGraph.Create("ClairePlayableGraph"); playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", GetComponent <Animator>()); // Create a Mixer AnimationLayerMixerPlayable mixerLayerPlayable = AnimationLayerMixerPlayable.Create(playableGraph, 2); playableOutput.SetSourcePlayable(mixerLayerPlayable); // Wrap the clip in a playable var clipPlayable = AnimationClipPlayable.Create(playableGraph, clip); //var clipPlayable1 = AnimationClipPlayable.Create(playableGraph, clip1); // Wrap AnimController runtimeAnimController = GetComponent <Animator>().runtimeAnimatorController; //animController = (AnimatorController)animator.runtimeAnimatorController; var runtimeAnimControllerPlayable = AnimatorControllerPlayable.Create(playableGraph, runtimeAnimController); // Connect to Mixer playableGraph.Connect(runtimeAnimControllerPlayable, 0, mixerLayerPlayable, 1); playableGraph.Connect(clipPlayable, 0, mixerLayerPlayable, 0); mixerLayerPlayable.SetInputWeight(0, 1.0f); mixerLayerPlayable.SetInputWeight(1, 1.0f); //mixerLayerPlayable.SetLayerAdditive(0, true); mixerLayerPlayable.SetLayerAdditive(1, true); Debug.Log("Is layer 0 additive: " + mixerLayerPlayable.IsLayerAdditive(0)); Debug.Log("Is layer 1 additive: " + mixerLayerPlayable.IsLayerAdditive(1)); //mixerLayerPlayable.SetLayerMaskFromAvatarMask(1, headMask); // Connect the Playable to an output //playableOutput.SetSourcePlayable(clipPlayable); // Plays the Graph. playableGraph.Play(); }
// private IEnumerator crossFadeLayerWeight(int layer, float duration, bool enable) { Debug.Log(enable + " " + layerMixer.GetInputWeight(layer)); //既に有効/無効になっている場合は処理しない if (enable && layerMixer.GetInputWeight(layer) >= 1f) { yield break; } else if (enable == false && layerMixer.GetInputWeight(layer) <= 0f) { yield break; } // 指定時間でアニメーションをブレンド float waitTime = Time.time + duration; yield return(new WaitWhile(() => { float diff = waitTime - Time.time; float rate = Mathf.Clamp01(diff / duration); float weight = (enable) ? 1 - rate : rate; layerMixer.SetInputWeight(layer, weight); if (diff <= 0) { return false; } else { return true; } })); }
//============================================================================================ /** * @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, 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; PrimaryInputId = 0; MaxClips = 1; m_layerMixer.ConnectInput(Id, a_playable, 0); Mask = a_mask; m_layerMixer.SetLayerAdditive((uint)Id, a_additive); m_layerMixer.SetInputWeight(Id, Mathf.Clamp01(a_weight)); SubLayerWeights = new float[1]; SubLayerWeights[0] = 1f; }
//============================================================================================ /** * @brief Constructor for the MxMLayer class. 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 [AnimationClip] a_clip - the starting animation clip 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, AnimationClip a_clip, AvatarMask a_mask = null, float a_weight = 0f, bool a_additive = false) { Assert.IsNotNull(a_clip, "Error: Attempting to create an MxMLayer with null AnimationClip"); if (!a_layerMixer.IsValid()) Debug.LogError("Error: Attempting to create an MxMLayer with an invalid layerMixer."); m_playableGraph = a_layerMixer.GetGraph(); m_layerMixer = a_layerMixer; PrimaryClip = a_clip; Id = a_id; MaxClips = a_maxClips; PrimaryInputId = 0; Mixer = AnimationMixerPlayable.Create(m_playableGraph, a_maxClips, true); var clipPlayable = AnimationClipPlayable.Create(m_playableGraph, PrimaryClip); m_layerMixer.ConnectInput(Id, Mixer, 0); Mixer.ConnectInput(0, clipPlayable, 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[MaxClips]; SubLayerWeights[0] = 1f; }
public void ClickStopB() { // ...这里暂无判空等检测 mixer.SetInputWeight(1, 0f); //graph.Disconnect(mixer, 1); }
/// <summary> /// Called by Unity. /// </summary> private void OnEnable() { _cubismFadeMotionList = GetComponent <CubismFadeController>().CubismFadeMotionList; // Fail silently... if (_cubismFadeMotionList == null) { Debug.LogError("CubismMotionController : CubismFadeMotionList doesn't set in CubismFadeController."); return; } // Get Animator. var animator = GetComponent <Animator>(); if (animator.runtimeAnimatorController != null) { Debug.LogWarning("Animator Controller was set in Animator component."); return; } _isActive = true; // Disabble animator's playablegrap. var graph = animator.playableGraph; if (graph.IsValid()) { graph.GetOutput(0).SetWeight(0); } // Create Playable Graph. _playableGrap = PlayableGraph.Create("Playable Graph : " + this.FindCubismModel().name); _playableGrap.SetTimeUpdateMode(DirectorUpdateMode.GameTime); // Create Playable Output. _playableOutput = AnimationPlayableOutput.Create(_playableGrap, "Animation", animator); _playableOutput.SetWeight(1); // Create animation layer mixer. _layerMixer = AnimationLayerMixerPlayable.Create(_playableGrap, LayerCount); // Create cubism motion layers. if (_motionLayers == null) { LayerCount = (LayerCount < 1) ? 1 : LayerCount; _motionLayers = new CubismMotionLayer[LayerCount]; } for (var i = 0; i < LayerCount; ++i) { _motionLayers[i] = CubismMotionLayer.CreateCubismMotionLayer(_playableGrap, _cubismFadeMotionList); _motionLayers[i].AnimationEndHandler += OnAnimationEnd; _layerMixer.ConnectInput(i, _motionLayers[i].PlayableOutput, 0); _layerMixer.SetInputWeight(i, 1.0f); } // Set Playable Output. _playableOutput.SetSourcePlayable(_layerMixer); }
public void Update() { foreach (SAnimationLayer l in m_Layer) { l.Update(); } if (m_Layer[1].Weight == 1) { m_LayerManager.SetInputWeight(0, 0); } else { m_LayerManager.SetInputWeight(0, m_Layer[0].Weight); } m_LayerManager.SetInputWeight(1, m_Layer[1].Weight); }
void Start() { graph = PlayableGraph.Create("PauseSubGraphAnimation"); AnimationPlayableOutput output = AnimationPlayableOutput.Create(graph, "Animation", GetComponent <Animator>()); mixer = AnimationLayerMixerPlayable.Create(graph, 2); output.SetSourcePlayable(mixer); clipPlay0 = AnimationClipPlayable.Create(graph, clip0); clipPlay1 = AnimationClipPlayable.Create(graph, clip1); graph.Connect(clipPlay0, 0, mixer, 0); graph.Connect(clipPlay1, 0, mixer, 1); mixer.SetInputWeight(0, 1f); mixer.SetInputWeight(1, 1f); graph.Play(); }
public void Evaluate() { m_Output.SetWeight(1); for (int i = 0; i < m_Mixers.Count; i++) { var mixInfo = m_Mixers[i]; float weight = mixInfo.modulate ? mixInfo.parentMixer.GetInputWeight(mixInfo.port) : 1.0f; mixInfo.parentMixer.SetInputWeight(mixInfo.port, weight * WeightUtility.NormalizeMixer(mixInfo.mixer)); } float normalizedWeight = WeightUtility.NormalizeMixer(m_LayerMixer); var animator = m_Output.GetTarget(); if (animator == null) { return; } #if UNITY_EDITOR // AnimationMotionXToDeltaPlayable must blend with default values when previewing tracks with absolute root motion. bool blendMotionX = !Application.isPlaying && m_MotionXPlayable.IsValid() && m_MotionXPlayable.IsAbsoluteMotion(); if (blendMotionX) { if (!m_PoseMixer.Equals(AnimationLayerMixerPlayable.Null)) { m_PoseMixer.SetInputWeight(0, 1.0f); m_PoseMixer.SetInputWeight(1, normalizedWeight); } } else { if (!m_PoseMixer.Equals(AnimationLayerMixerPlayable.Null)) { m_PoseMixer.SetInputWeight(0, 1.0f); m_PoseMixer.SetInputWeight(1, 1.0f); } m_Output.SetWeight(normalizedWeight); } #else m_Output.SetWeight(normalizedWeight); #endif }
void Start() { graph = PlayableGraph.Create("RotateMoveCube"); output = AnimationPlayableOutput.Create(graph, "Animation", GetComponent <Animator>()); // inputCount 可以接几个playable mixer = AnimationLayerMixerPlayable.Create(graph, 3); output.SetSourcePlayable(mixer); AnimationClipPlayable clipPlayA = AnimationClipPlayable.Create(graph, animClipA); AnimationClipPlayable clipPlayB = AnimationClipPlayable.Create(graph, animClipB); // sourceOutputPort 默认为0 graph.Connect(clipPlayA, 0, mixer, 0); graph.Connect(clipPlayB, 0, mixer, 1); // weight填0.5f只会有一半效果,和我理解的a + b + c = 1不同 mixer.SetInputWeight(0, 1f); mixer.SetInputWeight(1, 1f); graph.Play(); }
// Use this for initialization void Start() { animator = GetComponent <Animator>(); smr = childwithSkinnedMeshRenderer.GetComponent <SkinnedMeshRenderer>(); blendShapeCount = smr.sharedMesh.blendShapeCount; playableGraph = PlayableGraph.Create("ClairePlayableGraph"); playableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); var playableOutput = AnimationPlayableOutput.Create(playableGraph, "Animation", animator); // Create Top Level Layer Mixer AnimationLayerMixerPlayable mixerLayerPlayable = AnimationLayerMixerPlayable.Create(playableGraph, 2); playableOutput.SetSourcePlayable(mixerLayerPlayable); // Wrap AnimController runtimeAnimController = animator.runtimeAnimatorController; var runtimeAnimControllerPlayable = AnimatorControllerPlayable.Create(playableGraph, runtimeAnimController); // Create an Emotion Mixer mixerEmotionPlayable = AnimationMixerPlayable.Create(playableGraph, 4); //playableOutput.SetSourcePlayable(mixerEmotionPlayable); // Connect to Top Level Layer Mixer playableGraph.Connect(runtimeAnimControllerPlayable, 0, mixerLayerPlayable, 0); playableGraph.Connect(mixerEmotionPlayable, 0, mixerLayerPlayable, 1); mixerLayerPlayable.SetInputWeight(0, 1.0f); mixerLayerPlayable.SetInputWeight(1, 1.0f); mixerLayerPlayable.SetLayerMaskFromAvatarMask(1, headMask); // Wrap the clips in a playable pHappy = AnimationClipPlayable.Create(playableGraph, happy); pAngry = AnimationClipPlayable.Create(playableGraph, angry); // Connect to Emotion Mixer //mixerEmotionPlayable.SetInputCount(5); // InputCount needs to be == to the number of connected clips (for normalization purposes) playableGraph.Connect(pHappy, 0, mixerEmotionPlayable, 0); playableGraph.Connect(pAngry, 0, mixerEmotionPlayable, 1); // Plays the Graph playableGraph.Play(); }
public void InitializeLayerBlending(PlayableGraph graph, int layerIndex, AnimationLayerMixerPlayable layerMixer) { graph.Connect(stateMixer, 0, layerMixer, layerIndex); layerMixer.SetInputWeight(layerIndex, startWeight); layerMixer.SetLayerAdditive((uint)layerIndex, type == AnimationLayerType.Additive); if (mask != null) { layerMixer.SetLayerMaskFromAvatarMask((uint)layerIndex, mask); } }
/// <summary> /// Set layer weight. /// </summary> /// <param name="layerIndex">layer index.</param> /// <param name="weight">Layer weight.</param> public void SetLayerWeight(int layerIndex, float weight) { // Fail silently... if (layerIndex <= 0 || layerIndex >= LayerCount) { return; } _motionLayers[layerIndex].SetLayerWeight(weight); _layerMixer.SetInputWeight(layerIndex, weight); }
public Finger(PlayableGraph graph, AnimationClip closed, AnimationClip opened, AvatarMask mask, VariableTweener lerper) { mixer = AnimationLayerMixerPlayable.Create(graph, 2); var openPlayable = AnimationClipPlayable.Create(graph, opened); graph.Connect(openPlayable, 0, mixer, 0); var closedPlayable = AnimationClipPlayable.Create(graph, closed); graph.Connect(closedPlayable, 0, mixer, 1); mixer.SetLayerAdditive(0, false); mixer.SetLayerMaskFromAvatarMask(0, mask); mixer.SetInputWeight(0, 1); mixer.SetInputWeight(1, 0); crossFadingWeight = new TweenableFloat(lerper); crossFadingWeight.onChange += (value) => { mixer.SetInputWeight(0, 1 - value); mixer.SetInputWeight(1, value); }; }
public void UpdatePhase2() { float highestWeight = 0f; for (int i = 0; i < m_eventLayers.Count; ++i) { EventLayerData eventLayer = m_eventLayers[i]; float curTime = (float)eventLayer.ClipPlayable.GetTime(); float age = curTime - eventLayer.StartTime; float deathAge = eventLayer.EndTime - curTime; float weight = Mathf.Min(Mathf.Clamp01(age / eventLayer.BlendRate), Mathf.Clamp01(deathAge / eventLayer.BlendRate)); if (weight > highestWeight) { highestWeight = weight; } if (curTime >= eventLayer.EndTime) { m_layerMixer.SetInputWeight(eventLayer.SlotId, 0f); m_layerMixer.DisconnectInput(eventLayer.SlotId); eventLayer.ClipPlayable.Destroy(); m_eventLayers.RemoveAt(i); --i; } else if (Mathf.Abs(weight - eventLayer.Weight) > Mathf.Epsilon) { eventLayer.Weight = weight; m_eventLayers[i] = eventLayer; m_layerMixer.SetInputWeight(eventLayer.SlotId, weight); } } if (m_eventLayers.Count > 0) { m_mxmAnimator.SetLayerWeight(m_layerId, highestWeight); } }
public AimVerticalHandler(AnimationLayerMixerPlayable mixer, AnimationClip animAimDownToUp) { // Aim m_animAim = AnimationClipPlayable.Create(mixer.GetGraph(), animAimDownToUp); m_animAim.SetApplyFootIK(false); m_animAim.Pause(); m_aimTimeFactor = animAimDownToUp.length / 180.0f; m_port = mixer.AddInput(m_animAim, 0); mixer.SetLayerAdditive((uint)m_port, true); mixer.SetInputWeight(m_port, 1.0f); }
public Instance(AnimStateController controller, PlayableGraph graph, AnimGraphInAir settings) { m_AnimState = controller.GetComponent <AnimStateData>(); m_Mixer = AnimationLayerMixerPlayable.Create(graph, 2); m_AnimInAir = AnimationClipPlayable.Create(graph, settings.animInAir); m_AnimInAir.Play(); m_AnimInAir.SetApplyFootIK(false); graph.Connect(m_AnimInAir, 0, m_Mixer, 0); m_Mixer.SetInputWeight(0, 1); m_AnimAim = AnimationClipPlayable.Create(graph, settings.animAim); m_AnimAim.SetApplyFootIK(false); m_AnimAim.Pause(); graph.Connect(m_AnimAim, 0, m_Mixer, 1); m_Mixer.SetInputWeight(1, 1); m_Mixer.SetLayerAdditive(1, true); m_AimTimeFactor = settings.animAim.length / 180.0f; }
private AnimationMixerPlayable AddMixerWhenNotExist(int layer) { AnimationMixerPlayable mixer; if (layer < mixers.Count) { if (layer < 0) { return(AnimationMixerPlayable.Null); } mixer = GetMixer(layer); if (!mixer.Equals(AnimationMixerPlayable.Null)) { return(mixer); } mixer = AnimationMixerPlayable.Create(graph, 1); mixers[layer] = mixer; graph.Connect(mixer, 0, layerMixer, layer); layerMixer.SetInputWeight(layer, 1.0f); return(mixer); } AnimationMixerPlayable rst = AnimationMixerPlayable.Null; int diff = layer + 1 - mixers.Count; for (int i = 0; i < diff; ++i) { mixers.Add(AnimationMixerPlayable.Null); } mixer = AnimationMixerPlayable.Create(graph, 1); mixers[layer] = mixer; rst = mixer; graph.Connect(mixer, 0, layerMixer, layer); layerMixer.SetInputWeight(layer, 1.0f); return(rst); }
// Attaches the default blends to the layer mixer // the base layer is a default clip of all driven properties // the next layer is optionally the desired default pose (in the case of humanoid, the TPose) private void AttachDefaultBlend(PlayableGraph graph, AnimationLayerMixerPlayable mixer, bool requireOffset) { #if UNITY_EDITOR if (Application.isPlaying) { return; } int mixerInput = 0; if (m_CachedPropertiesClip) { var cachedPropertiesClip = AnimationClipPlayable.Create(graph, m_CachedPropertiesClip); cachedPropertiesClip.SetApplyFootIK(false); var defaults = (Playable)cachedPropertiesClip; if (requireOffset) { defaults = AttachOffsetPlayable(graph, defaults, m_SceneOffsetPosition, Quaternion.Euler(m_SceneOffsetRotation)); } graph.Connect(defaults, 0, mixer, mixerInput); mixer.SetInputWeight(mixerInput, 1.0f); mixerInput++; } if (m_DefaultPoseClip) { var defaultPose = AnimationClipPlayable.Create(graph, m_DefaultPoseClip); defaultPose.SetApplyFootIK(false); var blendDefault = (Playable)defaultPose; if (requireOffset) { blendDefault = AttachOffsetPlayable(graph, blendDefault, m_SceneOffsetPosition, Quaternion.Euler(m_SceneOffsetRotation)); } graph.Connect(blendDefault, 0, mixer, mixerInput); mixer.SetInputWeight(mixerInput, 1.0f); } #endif }