CreateAnimationJob() method must return a new instance of the desired IAnimationLayerJob-type. When you link a new Animator Profile, the system iterates over all animation features (Layer Settings) and then invokes the CreateAnimationJob() method to create the Layer State.
Example
First, create a new FPSAnimatorLayerSettings-derived class for data, and IAnimationLayerJob-implemented struct:
YourFeatureLayerSettings.cs
publicclassYourFeatureLayerSettings:FPSAnimatorLayerSettings{ //Define your settings here, including the KRigElements.publicKRigElement myRigElement;publicoverrideIAnimationLayerJobCreateAnimationJob() {returnnewYourAnimationLayerJob(); }#if UNITY_EDITORpublicoverridevoidOnRigUpdated() { base.OnRigUpdated(); // (!) Always update KRigElements here. // Called when a rig asset is updated/changed.UpdateRigElement(ref myRigElement); }#endif}
YourAnimationLayerJob.cs
publicstructYourAnimationLayerJob{privateYourFeatureLayerSettings _settings;privateLayerJobData _jobData;privateTransformStreamHandle _yourBoneHandle; // Use this method for custom animation logic.publicvoidProcessAnimation(AnimationStream stream) { } // Use this for modifying root motion.publicvoidProcessRootMotion(AnimationStream stream) { } // This method is called when a new profile is linked.publicvoidInitialize(LayerJobData newJobData,FPSAnimatorLayerSettings settings) { _settings = (AdditiveLayerSettings) settings; _jobData = newJobData;Transform bone =newJobData.rigComponent.GetRigTransform(settings.myRigElement); _yourBoneHandle =newJobData.animator.BindStreamTransform(bone); }publicAnimationScriptPlayableCreatePlayable(PlayableGraph graph) {returnAnimationScriptPlayable.Create(graph,this); } // Make sure to return a reference to the active asset. // It will be used by the FPSBoneController to compute a layer weight.publicFPSAnimatorLayerSettingsGetSettingAsset() {return _settings; } // Use this method to update job data when a layer is linked.publicvoidOnLayerLinked(FPSAnimatorLayerSettings newSettings) { } // Use this method when a new weapon or item is equipped.publicvoidUpdateEntity(FPSAnimatorEntity newEntity) { } // Use this method before the main update to gather input data.publicvoidOnPreGameThreadUpdate() { } // Use this method to update playable data and gather game thread data.publicvoidUpdatePlayableJobData(AnimationScriptPlayable playable,float weight) {_jobData.weight= weight;playable.SetJobData(this); } // Use this method when a finalized pose is required.publicvoidLateUpdate() { } // Use this method to dispose data manually.publicvoidDestroy() { }}
In the next chapter, we will learn how to work with the demo project.