2020-12-09 18:36:32 +01:00
|
|
|
|
using Unity.Entities;
|
|
|
|
|
using Unity.Collections;
|
|
|
|
|
|
|
|
|
|
namespace TAO.VertexAnimation
|
|
|
|
|
{
|
|
|
|
|
[UnityEngine.RequireComponent(typeof(ConvertToEntity))]
|
|
|
|
|
[UnityEngine.DisallowMultipleComponent]
|
|
|
|
|
public class VA_AnimationLibraryComponentAuthoring : UnityEngine.MonoBehaviour
|
|
|
|
|
{
|
2020-12-10 19:51:02 +01:00
|
|
|
|
public VA_AnimationLibrary animationLibrary;
|
2020-12-09 18:36:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public class VA_AnimationLibraryConversionSystem : GameObjectConversionSystem
|
|
|
|
|
{
|
2021-01-13 10:16:22 +01:00
|
|
|
|
// Static because of multi scene setup.
|
|
|
|
|
public static BlobAssetReference<VA_AnimationLibraryData> animLibAssetRef;
|
|
|
|
|
|
2020-12-09 18:36:32 +01:00
|
|
|
|
protected override void OnUpdate()
|
|
|
|
|
{
|
|
|
|
|
Entities.ForEach((VA_AnimationLibraryComponentAuthoring animationLib) =>
|
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
animationLib.animationLibrary.Init();
|
2020-12-10 19:51:02 +01:00
|
|
|
|
|
2020-12-09 18:36:32 +01:00
|
|
|
|
// Blob builder to build.
|
|
|
|
|
using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp))
|
|
|
|
|
{
|
|
|
|
|
// Construct the root.
|
2020-12-10 19:51:02 +01:00
|
|
|
|
ref VA_AnimationLibraryData animationDataBlobAsset = ref blobBuilder.ConstructRoot<VA_AnimationLibraryData>();
|
2020-12-09 18:36:32 +01:00
|
|
|
|
|
|
|
|
|
// Set all the data.
|
2021-01-19 01:18:25 +01:00
|
|
|
|
BlobBuilderArray<VA_AnimationData> animationDataArray = blobBuilder.Allocate(ref animationDataBlobAsset.animations, animationLib.animationLibrary.animationData.Count);
|
2020-12-09 18:36:32 +01:00
|
|
|
|
|
2021-01-14 00:45:25 +01:00
|
|
|
|
for (int i = 0; i < animationDataArray.Length; i++)
|
2020-12-09 18:36:32 +01:00
|
|
|
|
{
|
|
|
|
|
// Copy data.
|
2021-01-19 01:18:25 +01:00
|
|
|
|
animationDataArray[i] = animationLib.animationLibrary.animationData[i];
|
2021-01-19 15:23:52 +01:00
|
|
|
|
UnityEngine.Debug.Log("VA_AnimationLibrary added " + animationDataArray[i].name.ToString());
|
2020-12-09 18:36:32 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Construct blob asset reference.
|
2021-01-13 10:16:22 +01:00
|
|
|
|
//BlobAssetReference<VA_AnimationLibraryData> animLibAssetRef = blobBuilder.CreateBlobAssetReference<VA_AnimationLibraryData>(Allocator.Persistent);
|
|
|
|
|
// Static because of multi scene setup.
|
|
|
|
|
animLibAssetRef = blobBuilder.CreateBlobAssetReference<VA_AnimationLibraryData>(Allocator.Persistent);
|
2020-12-09 18:36:32 +01:00
|
|
|
|
|
|
|
|
|
// Add it to the asset store.
|
2020-12-16 11:59:22 +01:00
|
|
|
|
BlobAssetStore.TryAdd(new Hash128(VA_AnimationLibraryUtils.AnimationLibraryAssetStoreName), animLibAssetRef);
|
2020-12-09 18:36:32 +01:00
|
|
|
|
|
|
|
|
|
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));
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|