diff --git a/Editor/EditorExample.cs b/Editor/EditorExample.cs deleted file mode 100644 index 772931c..0000000 --- a/Editor/EditorExample.cs +++ /dev/null @@ -1,6 +0,0 @@ -using UnityEngine; -using UnityEditor; - -namespace TAO.VertexAnimation.Editor -{ -} \ No newline at end of file diff --git a/Editor/EditorExample.cs.meta b/Editor/EditorExample.cs.meta deleted file mode 100644 index fbbe16b..0000000 --- a/Editor/EditorExample.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 5a3fe61ae09e60f488649e570a04e071 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Editor/Scripts/Editor/VA_AnimationBookEditor.cs b/Editor/Scripts/Editor/VA_AnimationBookEditor.cs index 816a04c..574d08b 100644 --- a/Editor/Scripts/Editor/VA_AnimationBookEditor.cs +++ b/Editor/Scripts/Editor/VA_AnimationBookEditor.cs @@ -176,6 +176,11 @@ namespace TAO.VertexAnimation.Editor { animationPages.InsertArrayElementAtIndex(animationPages.arraySize); } + + if (GUILayout.Button("auto fill", EditorStyles.miniButton)) + { + animationBook.AutoFill(); + } } } diff --git a/Runtime/RuntimeExample.cs b/Runtime/RuntimeExample.cs deleted file mode 100644 index d28375b..0000000 --- a/Runtime/RuntimeExample.cs +++ /dev/null @@ -1,5 +0,0 @@ -using UnityEngine; - -namespace TAO.VertexAnimation -{ -} \ No newline at end of file diff --git a/Runtime/RuntimeExample.cs.meta b/Runtime/RuntimeExample.cs.meta deleted file mode 100644 index 9029a5c..0000000 --- a/Runtime/RuntimeExample.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 1d191fd2694a80142aaa155c49b1b8ae -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Runtime/Scripts/VA_AnimationBook.cs b/Runtime/Scripts/VA_AnimationBook.cs index e6f3044..6b965ca 100644 --- a/Runtime/Scripts/VA_AnimationBook.cs +++ b/Runtime/Scripts/VA_AnimationBook.cs @@ -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] diff --git a/Runtime/Scripts/VA_AnimationLibrary.cs b/Runtime/Scripts/VA_AnimationLibrary.cs index a0c697a..8b10d4f 100644 --- a/Runtime/Scripts/VA_AnimationLibrary.cs +++ b/Runtime/Scripts/VA_AnimationLibrary.cs @@ -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] diff --git a/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs index 50e9d6c..c83b95d 100644 --- a/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs +++ b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs @@ -38,8 +38,7 @@ namespace TAO.VertexAnimation BlobAssetReference animLibAssetRef = blobBuilder.CreateBlobAssetReference(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."); } diff --git a/Runtime/Scripts/VA_AnimationLibraryData.cs b/Runtime/Scripts/VA_AnimationLibraryData.cs index 0982f54..c61f2f7 100644 --- a/Runtime/Scripts/VA_AnimationLibraryData.cs +++ b/Runtime/Scripts/VA_AnimationLibraryData.cs @@ -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++) diff --git a/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs b/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs index 5755d0a..b06a596 100644 --- a/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs +++ b/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs @@ -26,7 +26,7 @@ namespace TAO.VertexAnimation { protected override void OnUpdate() { - BlobAssetStore.TryGet(new Unity.Entities.Hash128("AnimationLib"), out BlobAssetReference animLib); + BlobAssetStore.TryGet(new Unity.Entities.Hash128(VA_AnimationLibraryUtils.AnimationLibraryAssetStoreName), out BlobAssetReference animLib); Entities.ForEach((VA_AnimatorComponentAuthoring animator) => { diff --git a/Samples~/Example1.meta b/Samples~/Example1.meta new file mode 100644 index 0000000..e7d56c6 --- /dev/null +++ b/Samples~/Example1.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: eb128807d44bec847a9f9d1c4aafb5b1 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Samples~/Example1/Animations.meta b/Samples~/Example1/Animations.meta new file mode 100644 index 0000000..d0bffd9 --- /dev/null +++ b/Samples~/Example1/Animations.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 0014c77daedcce641a0054e802fde87f +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Samples~/Example1/Animations/AnimationLib.asset b/Samples~/Example1/Animations/AnimationLib.asset new file mode 100644 index 0000000..ac27026 --- /dev/null +++ b/Samples~/Example1/Animations/AnimationLib.asset @@ -0,0 +1,23 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 0d1625f26e651894b954faf1934378dc, type: 3} + m_Name: AnimationLib + m_EditorClassIdentifier: + animationBooks: + - {fileID: 11400000, guid: 317f071a0ab99b845bf3b609ca7cbc63, type: 2} + animations: + - frames: 36 + maxFrames: 43 + frameTime: 0.023255814 + duration: 0.8372093 + animationMapIndex: 0 + colorMapIndex: 0 diff --git a/Samples~/Example1/Animations/AnimationLib.asset.meta b/Samples~/Example1/Animations/AnimationLib.asset.meta new file mode 100644 index 0000000..7d9a39a --- /dev/null +++ b/Samples~/Example1/Animations/AnimationLib.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 721fbe09d2910a949925c6b1ed810323 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 0 + userData: + assetBundleName: + assetBundleVariant: