From e07f7f67e63c8d9e37abbf91cf8b06ee44699d93 Mon Sep 17 00:00:00 2001 From: SergeyVolik Date: Sat, 19 Feb 2022 14:29:16 +0200 Subject: [PATCH] fix: multiple animators support --- Runtime/Scripts/VA_AnimationLibrary.cs | 15 +++++++++++++- .../VA_AnimationLibraryComponentAuthoring.cs | 20 +++++++++++++------ Runtime/Scripts/VA_AnimationLibraryData.cs | 5 ++++- .../Scripts/VA_AnimatorComponentAuthoring.cs | 8 +++++--- 4 files changed, 37 insertions(+), 11 deletions(-) diff --git a/Runtime/Scripts/VA_AnimationLibrary.cs b/Runtime/Scripts/VA_AnimationLibrary.cs index e938c09..a7bbbd2 100644 --- a/Runtime/Scripts/VA_AnimationLibrary.cs +++ b/Runtime/Scripts/VA_AnimationLibrary.cs @@ -18,9 +18,22 @@ namespace TAO.VertexAnimation private List loadedAnimationsPreview = null; #endif - public void Init() + public Unity.Entities.Hash128 key; + public string guid; + + private void Awake() + { + + + } + public void Init() { + // generate guid + guid = System.Guid.NewGuid().ToString("N"); + key = new Unity.Entities.Hash128(guid); + animationData = new List(); + foreach (VA_AnimationBook book in animationBooks) { diff --git a/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs index 8d8e355..92dbcff 100644 --- a/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs +++ b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs @@ -1,5 +1,7 @@ using Unity.Entities; using Unity.Collections; +using Unity.Assertions; +using System; namespace TAO.VertexAnimation { @@ -14,7 +16,7 @@ namespace TAO.VertexAnimation public class VA_AnimationLibraryConversionSystem : GameObjectConversionSystem { // Static because of multi scene setup. - public static BlobAssetReference animLibAssetRef; + //public static BlobAssetReference animLibAssetRef; protected override void OnUpdate() { @@ -43,17 +45,23 @@ namespace TAO.VertexAnimation } // Construct blob asset reference. - //BlobAssetReference animLibAssetRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); - // Static because of multi scene setup. - animLibAssetRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); + BlobAssetReference animLibAssetRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); + // Add it to the asset store. - BlobAssetStore.TryAdd(new Hash128(VA_AnimationLibraryUtils.AnimationLibraryAssetStoreName), animLibAssetRef); + var anumLibName = animationLib.animationLibrary.name; + + var hash = animationLib.animationLibrary.key; + var result = BlobAssetStore.TryAdd(hash, animLibAssetRef); if (animationLib.debugMode) { - UnityEngine.Debug.Log("VA_AnimationLibrary has " + animLibAssetRef.Value.animations.Length.ToString() + " animations."); + UnityEngine.Debug.Log($"blob asset {anumLibName} key: {hash.Value.x} {hash.Value.y} {hash.Value.z} {hash.Value.w} "); + UnityEngine.Debug.Log($"VA_AnimationLibrary {anumLibName} has {animLibAssetRef.Value.animations.Length.ToString()} animations."); } + + + Assert.IsTrue(result, $"{anumLibName} hasn't been added to the blob asset store"); } // Remove the entity since we don't need it anymore. diff --git a/Runtime/Scripts/VA_AnimationLibraryData.cs b/Runtime/Scripts/VA_AnimationLibraryData.cs index cdfdf3f..a359706 100644 --- a/Runtime/Scripts/VA_AnimationLibraryData.cs +++ b/Runtime/Scripts/VA_AnimationLibraryData.cs @@ -1,5 +1,7 @@ using Unity.Entities; using Unity.Collections; +using Unity.Assertions; +using UnityEngine; namespace TAO.VertexAnimation { @@ -40,7 +42,6 @@ namespace TAO.VertexAnimation public static class VA_AnimationLibraryUtils { - public const string AnimationLibraryAssetStoreName = "VA_AnimationLibrary"; public static int GetAnimation(ref VA_AnimationLibraryData animationsRef, FixedString64 animationName) { @@ -52,6 +53,8 @@ namespace TAO.VertexAnimation } } + Debug.LogError($"{animationName} animation not found!"); + return -1; } diff --git a/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs b/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs index bfa9b5b..02cb409 100644 --- a/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs +++ b/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs @@ -8,7 +8,7 @@ namespace TAO.VertexAnimation [DisallowMultipleComponent] public class VA_AnimatorComponentAuthoring : MonoBehaviour { - + public VA_AnimationLibrary lib; } //[GenerateAuthoringComponent] @@ -25,12 +25,14 @@ namespace TAO.VertexAnimation { protected override void OnUpdate() { - //BlobAssetStore.TryGet(new Unity.Entities.Hash128(VA_AnimationLibraryUtils.AnimationLibraryAssetStoreName), out BlobAssetReference animLib); // Static because of multi scene setup. - BlobAssetReference animLib = VA_AnimationLibraryConversionSystem.animLibAssetRef; + //BlobAssetReference animLib = VA_AnimationLibraryConversionSystem.animLibAssetRef; Entities.ForEach((VA_AnimatorComponentAuthoring animator) => { + + BlobAssetStore.TryGet(animator.lib.key, out BlobAssetReference animLib); + Entity entity = GetPrimaryEntity(animator); // Add animator to 'parent'.