using Unity.Entities; using Unity.Collections; namespace TAO.VertexAnimation { [UnityEngine.RequireComponent(typeof(ConvertToEntity))] [UnityEngine.DisallowMultipleComponent] public class VA_AnimationLibraryComponentAuthoring : UnityEngine.MonoBehaviour { public VA_AnimationLibrary animationLibrary; public bool debugMode = false; } public class VA_AnimationLibraryConversionSystem : GameObjectConversionSystem { // Static because of multi scene setup. public static BlobAssetReference animLibAssetRef; protected override void OnUpdate() { Entities.ForEach((VA_AnimationLibraryComponentAuthoring animationLib) => { animationLib.animationLibrary.Init(); // Blob builder to build. using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp)) { // Construct the root. ref VA_AnimationLibraryData animationDataBlobAsset = ref blobBuilder.ConstructRoot(); // Set all the data. BlobBuilderArray animationDataArray = blobBuilder.Allocate(ref animationDataBlobAsset.animations, animationLib.animationLibrary.animationData.Count); for (int i = 0; i < animationDataArray.Length; i++) { // Copy data. animationDataArray[i] = animationLib.animationLibrary.animationData[i]; if (animationLib.debugMode) { UnityEngine.Debug.Log("VA_AnimationLibrary added " + animationDataArray[i].name.ToString()); } } // Construct blob asset reference. //BlobAssetReference animLibAssetRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); // Static because of multi scene setup. animLibAssetRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); // Add it to the asset store. BlobAssetStore.TryAdd(new Hash128(VA_AnimationLibraryUtils.AnimationLibraryAssetStoreName), animLibAssetRef); if (animationLib.debugMode) { UnityEngine.Debug.Log("VA_AnimationLibrary has " + animLibAssetRef.Value.animations.Length.ToString() + " animations."); } } // Remove the entity since we don't need it anymore. DstEntityManager.DestroyEntity(GetPrimaryEntity(animationLib)); }); } } }