Unity2018.2.12f1時点ではまだExperimentalな機能であるTransformSceneHandle
について調査しました。
リファレンスはコチラ
Position, rotation and scale of an object in the scene. A TransformSceneHandle is a safe handle on a TransformAccess. The Animator used to create this handle manages the validity of this handle.
とリファレンス上では説明されています。
調査すると、結論TransformSceneHandleはAnimationJobを使用する際のTransformへのアクセス方法であるという認識になりました。
※IJobParallelForTransformにおけるTransformへのアクセスは、TransformAccess
を使用していました
簡単な図にするとこうなります。
- TransformSceneHandleは、AnimatorとTransformを元に生成
- TransformSceneHandleをAnimationJobへ渡す
- AnimationJob内でTransformSceneHandleへ位置回転データを渡す
- AnimationJobはAnimationScriptPlayableを通して再生される
というような流れになります。
AnimationJobはIAnimationJobインターフェース
を実装する必要があり、以下のような実装になっています。
AnimationJob内の処理ProcessAnimation
、ProcessRootMotion
の引数でAnimationStreamが渡ってきます。
このAnimationStreamインスタンスを通して、TransformSceneHandleの値を更新していくようです。
※そもそもAnimationStreamとはなんぞや??という疑問が出てきますが、こちらは未調査なので割愛します。
準備として、AnimatorのコンテキストメニューからBuild Generic Avatar
を実行。
このようにAvatarがセットされている必要があります。
リファレンスのほぼ丸コピソースですが、コチラが今回の検証サンプルです。
実行すると上のキャプチャのように並列処理されていました。
1点残念だったのは先日「アセンブリやるぜ!!」っていう記事を書きました。
AnimationJobをBurstCompileしてみてアセンブリがどうなっているか確認しようとしてのですが、AnimationJobがExperimentalのせいか、BurstInspectorに表示されずアセンブリを確認できず。
ただし、コンソールを見ると以下のようにAnimationJobのBurstCompile自体は走っているようです。
While compiling job: System.Void UnityEngine.Experimental.Animations.ProcessAnimationJobStruct`1
::ExecuteProcessRootMotion(T&,System.IntPtr,System.IntPtr,Unity.Jobs.LowLevel.Unsafe.JobRanges&,System.Int32)
Jobs > Show Burst Timings
にチェックを入れると、ランタイム時にコンソールにBurstCompileのタイミングでログが表示されるようになります。
まとめ
TransformSceneHandleはAnimationJobで使用されます。
※どちらもExperimental
参考
環境
- Unity2018.2.12f1