public static int GetAnimation(ref VA_AnimationLibraryData animationsRef, FixedString64 animationName) { for (int i = 0; i < animationsRef.animations.Length; i++) { if (animationsRef.animations[i].name == animationName) { return(i); } } return(-1); }
protected override void OnUpdate() { var animationData = GetComponentDataFromEntity<VA_AnimationDataComponent>(false); Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer<Child> children) => { for (int i = 0; i < children.Length; i++) { // Get child. Entity child = children[i].Value; // Get the animation lib data. ref VA_AnimationLibraryData animationsRef = ref ac.animationLibrary.Value; // Lerp animations. // Set animation for lerp. int animationIndexNext = ac.animationIndexNext; if (ac.animationIndexNext < 0) { animationIndexNext = ac.animationIndex; } // Calculate next frame time for lerp. float animationTimeNext = ac.animationTime + (1.0f / animationsRef.animations[animationIndexNext].maxFrames); if (animationTimeNext > animationsRef.animations[animationIndexNext].duration) { // Set time. Using the difference to smooth out animations when looping. animationTimeNext -= ac.animationTime; } // Set material data. animationData[child] = new VA_AnimationDataComponent { Value = new float4 { x = ac.animationTime, y = VA_AnimationLibraryUtils.GetAnimationMapIndex(ref animationsRef, ac.animationIndex), z = animationTimeNext, w = VA_AnimationLibraryUtils.GetAnimationMapIndex(ref animationsRef, animationIndexNext) } }; } })
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 <VA_AnimationLibraryData>(); // Set all the data. BlobBuilderArray <VA_AnimationData> 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<VA_AnimationLibraryData> animLibAssetRef = blobBuilder.CreateBlobAssetReference<VA_AnimationLibraryData>(Allocator.Persistent); // Static because of multi scene setup. animLibAssetRef = blobBuilder.CreateBlobAssetReference <VA_AnimationLibraryData>(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)); });
public static int GetColorMapIndex(ref VA_AnimationLibraryData animationsRef, int animation) { return(animationsRef.animations[animation].colorMapIndex); }