protected override AnimationScriptPlayable InitializePlayable() { BonesLastFrame = sharedData.GetBonesLastFrameCopy(); // Create job var job = new MixerJob() { blendMode = BlendMode, handles = boneHandles, boneWeights = boneWeights, bonesLastFrame = BonesLastFrame, bonesLastState = BonesLastFrame, weight = 0f, }; // Debug.Log($"Initialize mixer playable {job}"); var scriptPlayable = AnimationScriptPlayable.Create(sharedData.PlayableGraph, job, 2); scriptPlayable.SetProcessInputs(false); // sequenceList.ForEach(clip => // { // scriptPlayable.AddInput(AnimationClipPlayable.Create(sharedData.PlayableGraph, clip.pose), 0, 0f); // }); return(scriptPlayable); }
void OnEnable() { // Load animation clips. var idleClip = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Generic", "Idle"); var romClip = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Generic", "ROM"); if (idleClip == null || romClip == null) { return; } var animator = GetComponent <Animator>(); // Get all the transforms in the hierarchy. var transforms = animator.transform.GetComponentsInChildren <Transform>(); var numTransforms = transforms.Length - 1; // Fill native arrays (all the bones have a weight of 1.0). m_Handles = new NativeArray <TransformStreamHandle>(numTransforms, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); m_BoneWeights = new NativeArray <float>(numTransforms, Allocator.Persistent, NativeArrayOptions.ClearMemory); for (var i = 0; i < numTransforms; ++i) { m_Handles[i] = animator.BindStreamTransform(transforms[i + 1]); m_BoneWeights[i] = 1.0f; } // Create job. var job = new MixerJob() { handles = m_Handles, boneWeights = m_BoneWeights, weight = 0.0f }; // Create graph with custom mixer. m_Graph = PlayableGraph.Create("SimpleMixer"); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); m_CustomMixerPlayable = AnimationScriptPlayable.Create(m_Graph, job); m_CustomMixerPlayable.SetProcessInputs(false); AnimationClipPlayable idlePlayable = CreateAnimationPlayableClip(m_Graph, idleClip); AnimationClipPlayable romPlayable = CreateAnimationPlayableClip(m_Graph, romClip); m_CustomMixerPlayable.AddInput(idlePlayable, 0, 1.0f); m_CustomMixerPlayable.AddInput(romPlayable, 0, 1.0f); var output = AnimationPlayableOutput.Create(m_Graph, "output", animator); output.SetSourcePlayable(m_CustomMixerPlayable); m_Graph.Play(); emptyGraph = PlayableGraph.Create("EmptyGraph"); emptyGraph.SetTimeUpdateMode(DirectorUpdateMode.GameTime); }
void OnEnable() { // Load animation clips. var idleClip = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Generic", "Idle"); var romClip = SampleUtility.LoadAnimationClipFromFbx("DefaultMale/Models/DefaultMale_Generic", "ROM"); if (idleClip == null || romClip == null) { return; } var animator = GetComponent <Animator>(); // Get all the transforms in the hierarchy. var allTransforms = animator.transform.GetComponentsInChildren <Transform>(); var numTransforms = allTransforms.Length - 1; // Fill native arrays (all the bones have a weight of 0.0). m_Handles = new NativeArray <TransformStreamHandle>(numTransforms, Allocator.Persistent, NativeArrayOptions.UninitializedMemory); m_BoneWeights = new NativeArray <float>(numTransforms, Allocator.Persistent, NativeArrayOptions.ClearMemory); for (var i = 0; i < numTransforms; ++i) { m_Handles[i] = animator.BindStreamTransform(allTransforms[i + 1]); } // Set bone weights for selected transforms and their hierarchy. m_BoneChildrenIndices = new List <List <int> >(boneTransformWeights.Length); foreach (var boneTransform in boneTransformWeights) { var childrenTransforms = boneTransform.transform.GetComponentsInChildren <Transform>(); var childrenIndices = new List <int>(childrenTransforms.Length); foreach (var childTransform in childrenTransforms) { var boneIndex = Array.IndexOf(allTransforms, childTransform); Debug.Assert(boneIndex > 0, "Index can't be less or equal to 0"); childrenIndices.Add(boneIndex - 1); } m_BoneChildrenIndices.Add(childrenIndices); } // Create job. var job = new MixerJob() { handles = m_Handles, boneWeights = m_BoneWeights, weight = 1.0f }; // Create graph with custom mixer. m_Graph = PlayableGraph.Create("CustomMixer"); m_CustomMixerPlayable = AnimationScriptPlayable.Create(m_Graph, job); m_CustomMixerPlayable.SetProcessInputs(false); m_CustomMixerPlayable.AddInput(AnimationClipPlayable.Create(m_Graph, idleClip), 0, 1.0f); m_CustomMixerPlayable.AddInput(AnimationClipPlayable.Create(m_Graph, romClip), 0, 1.0f); var output = AnimationPlayableOutput.Create(m_Graph, "output", animator); output.SetSourcePlayable(m_CustomMixerPlayable); m_Graph.Play(); }