Auto fill, const asset store name

Auto fill, const asset store name.
This commit is contained in:
max
2020-12-16 11:59:22 +01:00
parent ea1d2412b1
commit b285831ef7
14 changed files with 92 additions and 38 deletions

View File

@ -4,7 +4,7 @@ using UnityEngine;
namespace TAO.VertexAnimation
{
[CreateAssetMenu(fileName = "new AnimationBook", menuName = "AnimationBook", order = 0)]
[CreateAssetMenu(fileName = "new AnimationBook", menuName = "VA_Animation/AnimationBook", order = 400)]
public class VA_AnimationBook : ScriptableObject
{
public int maxFrames;
@ -149,6 +149,40 @@ namespace TAO.VertexAnimation
return -1;
}
// Auto fill names and frames.
public void AutoFill()
{
if (animationPages != null)
{
for (int i = 0; i < animationPages.Count; i++)
{
VA_AnimationPage ap = animationPages[i];
if (ap.textures != null && ap.textures.Count > 0)
{
string textureName = ap.textures[0].texture2D.name;
string[] parts = textureName.Split('_');
foreach (var p in parts)
{
if (p.StartsWith("N-"))
{
ap.name = p.Remove(0, 2);
}
else if (p.StartsWith("F-"))
{
if(int.TryParse(p.Remove(0, 2), out int frames))
{
ap.frames = frames;
}
}
}
}
animationPages[i] = ap;
}
}
}
}
[System.Serializable]

View File

@ -3,7 +3,7 @@ using UnityEngine;
namespace TAO.VertexAnimation
{
[CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "AnimationLibrary", order = 0)]
[CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "VA_Animation/AnimationLibrary", order = 400)]
public class VA_AnimationLibrary : ScriptableObject
{
[SerializeField]

View File

@ -38,8 +38,7 @@ namespace TAO.VertexAnimation
BlobAssetReference<VA_AnimationLibraryData> animLibAssetRef = blobBuilder.CreateBlobAssetReference<VA_AnimationLibraryData>(Allocator.Persistent);
// Add it to the asset store.
// TODO: Generate Hash based on Guid.
BlobAssetStore.TryAdd(new Hash128("AnimationLib"), animLibAssetRef);
BlobAssetStore.TryAdd(new Hash128(VA_AnimationLibraryUtils.AnimationLibraryAssetStoreName), animLibAssetRef);
UnityEngine.Debug.Log("VA_AnimationLibrary has " + animLibAssetRef.Value.animations.Length.ToString() + " animations.");
}

View File

@ -29,6 +29,8 @@ namespace TAO.VertexAnimation
public static class VA_AnimationLibraryUtils
{
public const string AnimationLibraryAssetStoreName = "VA_AnimationLibrary";
public static int GetAnimation(ref VA_AnimationLibraryData animationsRef, FixedString32 animationName)
{
for (int i = 0; i < animationsRef.animations.Length; i++)

View File

@ -26,7 +26,7 @@ namespace TAO.VertexAnimation
{
protected override void OnUpdate()
{
BlobAssetStore.TryGet(new Unity.Entities.Hash128("AnimationLib"), out BlobAssetReference<VA_AnimationLibraryData> animLib);
BlobAssetStore.TryGet(new Unity.Entities.Hash128(VA_AnimationLibraryUtils.AnimationLibraryAssetStoreName), out BlobAssetReference<VA_AnimationLibraryData> animLib);
Entities.ForEach((VA_AnimatorComponentAuthoring animator) =>
{