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 static AnimationClipPlayable AddClip(this AnimationLayerMixerPlayable layerMixer, PlayableGraph graph, AnimationClip clip, out int index) { var playable = AnimationClipPlayable.Create(graph, clip); index = layerMixer.AddInput(playable, 0); return(playable); }
void Awake() { animator.updateMode = AnimatorUpdateMode.UnscaledTime; playableGraph = PlayableGraph.Create(GetType().ToString()); playableGraph.SetTimeUpdateMode(DirectorUpdateMode.UnscaledGameTime); var animationLayerMixerPlayable = AnimationLayerMixerPlayable.Create(playableGraph, resources.Count); var animationPlayableOutput = AnimationPlayableOutput.Create(playableGraph, GetType().ToString() + "Output", animator); animationPlayableOutput.SetSourcePlayable(animationLayerMixerPlayable); var ui = Instantiate(uiPrerab); var layout = Instantiate(layoutPrerab, ui.transform); resources.ForEach(resource => { var animationClips = Resources.LoadAll <AnimationClip>(resource).ToList(); var mixier = new Mixer(playableGraph, ref animationLayerMixerPlayable, blendingCurve, animationClips); var grid = Instantiate(gridPrerab, layout.transform); var toggleGroup = grid.GetComponent <ToggleGroup>(); animationClips.ForEach(animationClip => { var button = Instantiate(buttonPrerab, grid.transform); button.GetComponentInChildren <Text>().text = animationClip.name; var toggle = button.GetComponent <Toggle>(); toggle.group = toggleGroup; toggle .OnValueChangedAsObservable() .Where(_ => _) .Subscribe(_ => mixier.Play(animationClip.name)); }); mixers.Add(mixier); }); }
/************************************************************************************************************************/ /// <summary>[Internal] Creates a new <see cref="LayerList"/>.</summary> internal LayerList(AnimancerPlayable root, out Playable layerMixer) { Root = root; _Layers = new AnimancerLayer[DefaultCapacity]; layerMixer = LayerMixer = AnimationLayerMixerPlayable.Create(root._Graph, 1); Root._Graph.Connect(layerMixer, 0, Root._RootPlayable, 0); }
private void Play(AnimationClip animClip) { m_Graph = PlayableGraph.Create(name + " Character Anims"); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); // Create the starting animation clip. AnimationClipPlayable animPlayable = AnimationClipPlayable.Create(m_Graph, animClip); // Create the transition mixer for changing animations over time. AnimationMixerPlayable transitionMixer = AnimationMixerPlayable.Create(m_Graph, 2); // Connect the base clip to the transition mixer. m_Graph.Connect(animPlayable, 0, transitionMixer, 1); transitionMixer.SetInputWeight(0, 0); transitionMixer.SetInputWeight(1, 1); // Create the layer output to handle 'heels'/'barefoot' options. AnimationPlayableOutput playableOutput = AnimationPlayableOutput.Create(m_Graph, "LayerMixer", m_Animator); AnimationLayerMixerPlayable layerMixer = AnimationLayerMixerPlayable.Create(m_Graph, 2); // Set the 'heels' layer to additive. layerMixer.SetLayerAdditive(1, true); playableOutput.SetSourcePlayable(layerMixer); layerMixer.ConnectInput(0, transitionMixer, 0, 1); m_Graph.Play(); }
// 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 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); } }
public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Jump settings) { m_EntityManager = entityManager; m_Owner = owner; m_AnimStateOwner = animStateOwner; m_additiveMixer = AnimationLayerMixerPlayable.Create(graph); m_animJump = AnimationClipPlayable.Create(graph, settings.animJump); m_animJump.SetApplyFootIK(true); m_animJump.SetDuration(settings.animJump.length); m_animJump.Pause(); int port = m_additiveMixer.AddInput(m_animJump, 0); m_additiveMixer.SetLayerAdditive((uint)port, false); m_additiveMixer.SetInputWeight(port, 1); // Adjust play speed so vertical velocity in animation is matched with character velocity (so feet doesnt penetrate ground) var animJumpVel = settings.jumpHeight / settings.animJump.length; var characterJumpVel = Game.config != null ? Game.config.jumpAscentHeight / Game.config.jumpAscentDuration : animJumpVel; playSpeed = characterJumpVel / animJumpVel; // Aim //m_aimHandler = new AimVerticalHandler(m_additiveMixer, settings.animAimDownToUp); }
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, AnimGraph_Simple settings) { m_EntityManager = entityManager; m_Owner = owner; m_layerMixer = AnimationLayerMixerPlayable.Create(graph); int port; // Idle m_animIdle = AnimationClipPlayable.Create(graph, settings.animIdle); m_animIdle.SetApplyFootIK(settings.idleFootIKActive); port = m_layerMixer.AddInput(m_animIdle, 0); m_layerMixer.SetInputWeight(port, 1.0f); // Aim if (settings.animAimDownToUp != null) { m_aimHandler = new AimVerticalHandler(m_layerMixer, settings.animAimDownToUp); } // Actions m_actionMixer = AnimationLayerMixerPlayable.Create(graph); port = m_actionMixer.AddInput(m_layerMixer, 0); m_actionMixer.SetInputWeight(port, 1); m_actionAnimationHandler = new ActionAnimationHandler(m_actionMixer, settings.actionAnimations); }
public ActionAnimationHandler(AnimationLayerMixerPlayable mixer, ActionAnimationDefinition[] actionAnimationDefs) { if (actionAnimationDefs == null) { return; } m_mixer = mixer; foreach (var def in actionAnimationDefs) { if (def.animation == null) { continue; } if (m_actionAnimations.ContainsKey(def.action)) { continue; } ActionAnimation actionAnim = new ActionAnimation(); actionAnim.animation = AnimationClipPlayable.Create(mixer.GetGraph(), def.animation); actionAnim.animation.SetApplyFootIK(false); actionAnim.animation.SetDuration(def.animation.length); actionAnim.port = mixer.AddInput(actionAnim.animation, 0); actionAnim.restartTimeOffset = def.restartTimeOffset; mixer.SetLayerAdditive((uint)actionAnim.port, true); m_actionAnimations.Add(def.action, actionAnim); } }
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); }
public Instance(EntityManager entityManager, Entity owner, PlayableGraph graph, Entity animStateOwner, AnimGraph_Move8Dir settings) { m_settings = settings; m_EntityManager = entityManager; m_Owner = owner; m_AnimStateOwner = animStateOwner; m_locomotionMixer = AnimationLayerMixerPlayable.Create(graph, 3); // Movement m_BlendTree = new BlendTree2dSimpleDirectional(graph, settings.blendSpaceNodes); graph.Connect(m_BlendTree.GetRootPlayable(), 0, m_locomotionMixer, 0); m_locomotionMixer.SetInputWeight(0, 1.0f); m_BlendTree.masterSpeed = m_settings.animMovePlaySpeed; // Aim //if (settings.animAim != null) { // m_clipAim = AnimationClipPlayable.Create(graph, settings.animAim); // m_clipAim.SetApplyFootIK(false); // m_clipAim.Pause(); // m_aimTimeFactor = m_clipAim.GetAnimationClip().length / 180.0f; // m_locomotionMixer.SetLayerAdditive(1, true); // graph.Connect(m_clipAim, 0, m_locomotionMixer, 1); // m_locomotionMixer.SetInputWeight(1, 1.0f); //} // Actions m_actionMixer = AnimationLayerMixerPlayable.Create(graph); var port = m_actionMixer.AddInput(m_locomotionMixer, 0); m_actionMixer.SetInputWeight(port, 1); m_actionAnimationHandler = new ActionAnimationHandler(m_actionMixer, settings.actionAnimations); }
public TwoDBlendTree(int layerId, PlayableGraph PlayableGraph, AnimationLayerMixerPlayable parentAnimationLayerMixerPlayable, TwoDAnimationInput TwoDAnimationInput) : base(layerId, parentAnimationLayerMixerPlayable) { this.TwoDAnimationInput = TwoDAnimationInput; this.TwoDBlendTreeAnimationClips = TwoDAnimationInput.TwoDBlendTreeAnimationClipInputs.ConvertAll(i => new TwoDBlendTreeAnimationClip(i.AnimationClip, i.TreePosition, i.Speed)); this.TwoDBlendTreeAnimationClipsPositions = this.TwoDBlendTreeAnimationClips.ConvertAll(c => c.TreePosition).ToArray(); this.Weights = new float[this.TwoDBlendTreeAnimationClipsPositions.Length]; //create a playable mixer this.AnimationMixerPlayable = AnimationMixerPlayable.Create(PlayableGraph); foreach (var TwoDBlendTreeAnimationClip in TwoDBlendTreeAnimationClips) { var animationClipPlayable = AnimationClipPlayable.Create(PlayableGraph, TwoDBlendTreeAnimationClip.AnimationClip); animationClipPlayable.SetApplyFootIK(false); animationClipPlayable.SetApplyPlayableIK(false); animationClipPlayable.SetSpeed(TwoDBlendTreeAnimationClip.Speed); TwoDBlendTreeAnimationClip.InputHandler = PlayableExtensions.AddInput(this.AnimationMixerPlayable, animationClipPlayable, 0); PlayableExtensions.Play(animationClipPlayable); TwoDBlendTreeAnimationClip.AnimationClipPlayable = animationClipPlayable; } this.Inputhandler = PlayableExtensions.AddInput(parentAnimationLayerMixerPlayable, this.AnimationMixerPlayable, 0); if (TwoDAnimationInput.AvatarMask != null) { parentAnimationLayerMixerPlayable.SetLayerMaskFromAvatarMask((uint)this.Inputhandler, TwoDAnimationInput.AvatarMask); } }
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); }
private void Awake() { Animator animator = GetComponent <Animator>(); animator.updateMode = m_AnimatorUpdateMode; animator.cullingMode = m_CullingMode; #if !UNITY_2018_2_OR_NEWER Debug.LogError("Only support 2018.2 or newer!"); #else #if UNITY_2018_2 m_Graph = animator.playableGraph; #else m_Graph = PlayableGraph.Create(this.name); AnimationPlayableOutput.Create(m_Graph, "ani", animator); m_Graph.Play(); #endif #endif m_LayerManager = AnimationLayerMixerPlayable.Create(m_Graph, 2); m_Graph.GetOutput(0).SetSourcePlayable(m_LayerManager); m_Layer = new SAnimationLayer[m_LayerCount]; for (int i = 0; i < m_LayerCount; i++) { m_Layer[i] = new SAnimationLayer(animator, m_LayerManager, i); } }
//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); }
private PlayableGraph graph; //PlayAbleとの接続 private void Awake() { graph = PlayableGraph.Create(); var anim = GetComponent <Animator>(); var defo = new List <AnimationClip>(); //全レイヤーの初期アニメを取得し、デフォルトアニメとしてコンバータにセット foreach (var i in Enumerable.Range(0, anim.layerCount)) { var temp = anim.GetCurrentAnimatorClipInfo(i)[0].clip; converters.Add(new Converter(graph, temp)); defo.Add(temp); Debug.Log("Layer num " + i + ",defoult anim " + temp.name); } //LayerMask情報をコンバータにセット layerMixer = AnimationLayerMixerPlayable.Create(graph, anim.layerCount); foreach (var item in maskBoxs) { layerMixer.SetLayerMaskFromAvatarMask(item.numberToMask, item.layerMask); } var output = AnimationPlayableOutput.Create(graph, "output", anim); //自身のAnimatorを出力先に決定 output.SetSourcePlayable(layerMixer); graph.Play(); }
//============================================================================================ /** * @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; }
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(); }
/// <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 Start() { graph = PlayableGraph.Create(name); layerMixer = AnimationLayerMixerPlayable.Create(graph, 0); AnimationPlayableUtilities.Play(animator, layerMixer, graph); }
// 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(); }
public override void Destroy(AnimationLayerMixerPlayable AnimationLayerMixerPlayable) { base.Destroy(AnimationLayerMixerPlayable); this.AnimationMixerPlayable.Destroy(); if (this.OnSequencedAnimationEnd != null) { this.OnSequencedAnimationEnd.Invoke(); } }
public void Init() { InitializeTweener(); if (handData) { graph = PlayableGraph.Create("Hand Animation Controller graph"); fingers = new Finger[5]; var fingerMixer = AnimationLayerMixerPlayable.Create(graph, fingers.Length); for (uint i = 0; i < fingers.Length; i++) { fingers[i] = new Finger(graph, handData.closed, handData.opened, handData[(int)i], lerper); fingerMixer.SetLayerAdditive(i, false); fingerMixer.SetLayerMaskFromAvatarMask(i, handData[(int)i]); graph.Connect(fingers[i].Mixer, 0, fingerMixer, (int)i); fingerMixer.SetInputWeight((int)i, 1); } handMixer = AnimationMixerPlayable.Create(graph, 2); graph.Connect(fingerMixer, 0, handMixer, 0); handMixer.SetInputWeight(0, 1); if (handData.poses.Count > 0) { poseMixer = AnimationMixerPlayable.Create(graph, handData.poses.Count); poses = new List <Pose>(); for (int i = 0; i < handData.poses.Count; i++) { var poseClip = handData.poses[i]; if (poseClip) { var pose = new Pose(lerper); pose.playable = AnimationClipPlayable.Create(graph, handData.poses[i]); pose.clip = handData.poses[i]; poses.Add(pose); graph.Connect(pose.playable, 0, poseMixer, i); poseMixer.SetInputWeight(i, 0); } poseMixer.SetInputWeight(pose, 1); } if (poses.Count > 0) { graph.Connect(poseMixer, 0, handMixer, 1); handMixer.SetInputWeight(1, 0); } } var playableOutput = AnimationPlayableOutput.Create(graph, "Hand Controller", GetComponentInChildren <Animator>()); playableOutput.SetSourcePlayable(handMixer); initialized = true; graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); graph.Play(); } else { initialized = false; } }
// Creates a layer mixer containing default blends // 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 Playable CreateDefaultBlend(PlayableGraph graph, GameObject go, Playable mixer, bool requireOffset) { #if UNITY_EDITOR if (Application.isPlaying) { return(mixer); } int inputs = 1 + ((m_CachedPropertiesClip != null) ? 1 : 0) + ((m_DefaultPoseClip != null) ? 1 : 0); if (inputs == 1) { return(mixer); } var defaultPoseMixer = AnimationLayerMixerPlayable.Create(graph, inputs); 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, defaultPoseMixer, mixerInput); defaultPoseMixer.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, defaultPoseMixer, mixerInput); defaultPoseMixer.SetInputWeight(mixerInput, 1.0f); mixerInput++; } graph.Connect(mixer, 0, defaultPoseMixer, mixerInput); defaultPoseMixer.SetInputWeight(mixerInput, 1.0f); return(defaultPoseMixer); #else return(mixer); #endif }
public AnimatorPlayableObject(string graphName, Animator animator) { this.Animator = animator; this.GlobalPlayableGraph = PlayableGraph.Create(graphName); this.GlobalPlayableGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); var playableOutput = AnimationPlayableOutput.Create(this.GlobalPlayableGraph, "Animation", animator); this.AnimationLayerMixerPlayable = AnimationLayerMixerPlayable.Create(this.GlobalPlayableGraph); PlayableOutputExtensions.SetSourcePlayable(playableOutput, this.AnimationLayerMixerPlayable); this.GlobalPlayableGraph.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); } }
public APLayer(uint layerIdx, PlayableGraph gragh, AnimationLayerMixerPlayable layerMixer, bool applyFootIK = false, bool isAddtive = false, AvatarMask avatarMask = null) { LayerID = layerIdx; m_applyFootIK = applyFootIK; m_isAdditive = isAddtive; m_avatarMask = avatarMask; m_layerMixer = layerMixer; StateMixer = AnimationMixerPlayable.Create(gragh); }