From e4ca15301b5c9304b606f92af6689d109772368d Mon Sep 17 00:00:00 2001 From: max Date: Thu, 10 Dec 2020 19:51:02 +0100 Subject: [PATCH] AnimationLibrary Editor AnimationLibraryBook editor setup. AnimationLibrary texture2DArray generation and material setup. --- Editor/Scripts.meta | 8 + Editor/Scripts/Editor.meta | 8 + .../Scripts/Editor/VA_AnimationBookEditor.cs | 222 ++++++++++++++++++ .../Editor/VA_AnimationBookEditor.cs.meta | 2 +- Editor/TAO.VertexAnimation.Editor.asmdef | 2 +- Runtime/Scripts/VA_AnimationBook.cs | 86 +++++++ ...ookSO.cs.meta => VA_AnimationBook.cs.meta} | 0 Runtime/Scripts/VA_AnimationBookSO.cs | 30 --- Runtime/Scripts/VA_AnimationLibrary.cs | 76 +++--- Runtime/Scripts/VA_AnimationLibrary.cs.meta | 2 +- .../VA_AnimationLibraryComponentAuthoring.cs | 9 +- Runtime/Scripts/VA_AnimationLibraryData.cs | 38 +++ .../Scripts/VA_AnimationLibraryData.cs.meta | 11 + Runtime/Scripts/VA_AnimationLibrarySO.cs | 46 ---- .../Scripts/VA_AnimatorComponentAuthoring.cs | 4 +- Runtime/Scripts/VA_AnimatorSystem.cs | 4 +- Runtime/Scripts/VA_Texture2DArrayUtils.cs | 64 +++++ .../Scripts/VA_Texture2DArrayUtils.cs.meta | 11 + 18 files changed, 508 insertions(+), 115 deletions(-) create mode 100644 Editor/Scripts.meta create mode 100644 Editor/Scripts/Editor.meta create mode 100644 Editor/Scripts/Editor/VA_AnimationBookEditor.cs rename Runtime/Scripts/VA_AnimationLibrarySO.cs.meta => Editor/Scripts/Editor/VA_AnimationBookEditor.cs.meta (83%) create mode 100644 Runtime/Scripts/VA_AnimationBook.cs rename Runtime/Scripts/{VA_AnimationBookSO.cs.meta => VA_AnimationBook.cs.meta} (100%) delete mode 100644 Runtime/Scripts/VA_AnimationBookSO.cs create mode 100644 Runtime/Scripts/VA_AnimationLibraryData.cs create mode 100644 Runtime/Scripts/VA_AnimationLibraryData.cs.meta delete mode 100644 Runtime/Scripts/VA_AnimationLibrarySO.cs create mode 100644 Runtime/Scripts/VA_Texture2DArrayUtils.cs create mode 100644 Runtime/Scripts/VA_Texture2DArrayUtils.cs.meta diff --git a/Editor/Scripts.meta b/Editor/Scripts.meta new file mode 100644 index 0000000..35e993b --- /dev/null +++ b/Editor/Scripts.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: a1800e0b8df6c3b4f8c7a3b063a355a7 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Editor.meta b/Editor/Scripts/Editor.meta new file mode 100644 index 0000000..b034e7b --- /dev/null +++ b/Editor/Scripts/Editor.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 736114389a5e3ad4f8a02fdb548d5431 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/Scripts/Editor/VA_AnimationBookEditor.cs b/Editor/Scripts/Editor/VA_AnimationBookEditor.cs new file mode 100644 index 0000000..862cf01 --- /dev/null +++ b/Editor/Scripts/Editor/VA_AnimationBookEditor.cs @@ -0,0 +1,222 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; +using System.Runtime.CompilerServices; +using UnityEngine.Rendering.VirtualTexturing; +using System; + +namespace TAO.VertexAnimation.Editor +{ + [CustomEditor(typeof(VA_AnimationBook))] + public class VA_AnimationBookEditor : UnityEditor.Editor + { + private VA_AnimationBook animationBook = null; + private Vector2 textireGroupScollPos; + private Vector2 animationPagesScollPos; + + private UnityEditor.Editor previewEditor = null; + private int previewIndex = 0; + + void OnEnable() + { + animationBook = target as VA_AnimationBook; + } + + public override void OnInspectorGUI() + { + serializedObject.Update(); + + // Texture Groups. + GeneralGUI(); + TextureGroupsGUI(); + SyncListSize(); + AnimationPagesGUI(); + MaterialGUI(); + Texture2DGUI(); + + serializedObject.ApplyModifiedProperties(); + } + + private void SyncListSize() + { + foreach (var page in animationBook.animationPages) + { + if(page.textures.Count < animationBook.textureGroups.Count) + { + int diff = animationBook.textureGroups.Count - page.textures.Count; + + for (int i = 0; i < diff; i++) + { + page.textures.Add(null); + } + } + else if(page.textures.Count > animationBook.textureGroups.Count) + { + int diff = page.textures.Count - animationBook.textureGroups.Count; + + for (int i = 0; i < diff; i++) + { + page.textures.RemoveRange(page.textures.Count - diff, diff); + } + } + } + } + + private void GeneralGUI() + { + using (new EditorGUILayout.VerticalScope()) + { + EditorGUILayout.LabelField("General", EditorStyles.centeredGreyMiniLabel); + EditorGUILayout.PropertyField(serializedObject.FindProperty("maxFrames")); + } + } + + private void TextureGroupsGUI() + { + SerializedProperty textureGroups = serializedObject.FindProperty("textureGroups"); + int removeWidth = 16; + int nameWidth = 152; + int linearWidth = 50; + + using (new EditorGUILayout.VerticalScope()) + { + EditorGUILayout.LabelField("TextureGroups", EditorStyles.centeredGreyMiniLabel); + + textireGroupScollPos = EditorGUILayout.BeginScrollView(textireGroupScollPos, false, false); + using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) + { + EditorGUILayout.LabelField("", GUILayout.Width(removeWidth)); + EditorGUILayout.LabelField("material parameter name", GUILayout.Width(nameWidth)); + EditorGUILayout.LabelField("is linear", GUILayout.MinWidth(linearWidth)); + } + EditorGUILayout.EndScrollView(); + + for (int i = 0; i < textureGroups.arraySize; i++) + { + using (new EditorGUILayout.HorizontalScope()) + { + if (GUILayout.Button("-", GUILayout.Width(removeWidth))) + { + textureGroups.DeleteArrayElementAtIndex(i); + continue; + } + + EditorGUILayout.PropertyField(textureGroups.GetArrayElementAtIndex(i).FindPropertyRelative("shaderParamName"), GUIContent.none, GUILayout.Width(nameWidth)); + EditorGUILayout.PropertyField(textureGroups.GetArrayElementAtIndex(i).FindPropertyRelative("isLinear"), GUIContent.none, GUILayout.MinWidth(linearWidth)); + } + } + + if (GUILayout.Button("+", EditorStyles.miniButton)) + { + animationBook.textureGroups.Add(new TextureGroup + { + shaderParamName = "_ShaderPropertyName", + isLinear = false + }); + } + } + } + + private void AnimationPagesGUI() + { + SerializedProperty animationPages = serializedObject.FindProperty("animationPages"); + int removeWidth = 16; + int nameWidth = 100; + int frameWidth = 50; + int textureWidth = 150; + + using (new EditorGUILayout.VerticalScope()) + { + EditorGUILayout.LabelField("AnimationPages", EditorStyles.centeredGreyMiniLabel); + + animationPagesScollPos = EditorGUILayout.BeginScrollView(animationPagesScollPos, false, false); + using (new EditorGUILayout.HorizontalScope(EditorStyles.toolbar)) + { + EditorGUILayout.LabelField("", GUILayout.Width(removeWidth)); + EditorGUILayout.LabelField("name", GUILayout.Width(nameWidth)); + EditorGUILayout.LabelField("frames", GUILayout.Width(frameWidth)); + foreach (var t in animationBook.textureGroups) + { + EditorGUILayout.LabelField(t.shaderParamName, GUILayout.MinWidth(textureWidth)); + } + } + EditorGUILayout.EndScrollView(); + + animationPagesScollPos = EditorGUILayout.BeginScrollView(animationPagesScollPos, false, false); + for (int i = 0; i < animationPages.arraySize; i++) + { + using (new EditorGUILayout.HorizontalScope()) + { + if (GUILayout.Button("-", GUILayout.Width(removeWidth))) + { + animationPages.DeleteArrayElementAtIndex(i); + continue; + } + + EditorGUILayout.PropertyField(animationPages.GetArrayElementAtIndex(i).FindPropertyRelative("name"), GUIContent.none, GUILayout.Width(nameWidth)); + + EditorGUILayout.PropertyField(animationPages.GetArrayElementAtIndex(i).FindPropertyRelative("frames"), GUIContent.none, GUILayout.Width(frameWidth)); + + SerializedProperty textures = animationPages.GetArrayElementAtIndex(i).FindPropertyRelative("textures"); + for (int t = 0; t < textures.arraySize; t++) + { + EditorGUILayout.PropertyField(textures.GetArrayElementAtIndex(t), GUIContent.none, GUILayout.MinWidth(textureWidth)); + } + } + } + EditorGUILayout.EndScrollView(); + + if (GUILayout.Button("+", EditorStyles.miniButton)) + { + animationPages.InsertArrayElementAtIndex(animationPages.arraySize); + } + } + } + + private void MaterialGUI() + { + using (new EditorGUILayout.VerticalScope()) + { + EditorGUILayout.LabelField("Materials", EditorStyles.centeredGreyMiniLabel); + EditorGUILayout.PropertyField(serializedObject.FindProperty("materials")); + } + } + + private void Texture2DGUI() + { + if (HasPreviewGUI()) + { + using (new EditorGUILayout.VerticalScope()) + { + SerializedProperty texture2DArray = serializedObject.FindProperty("texture2DArray"); + + EditorGUILayout.LabelField("Texture2DArray", EditorStyles.centeredGreyMiniLabel); + previewIndex = EditorGUILayout.IntSlider(previewIndex, 0, texture2DArray.arraySize - 1); + } + } + } + + public override bool HasPreviewGUI() + { + bool hasPreview = false; + + if(animationBook.texture2DArray != null && animationBook.texture2DArray.Count > 0 && animationBook.texture2DArray[previewIndex] != null) + { + hasPreview = true; + } + + return hasPreview; + } + + public override void OnPreviewGUI(Rect r, GUIStyle background) + { + if (previewEditor == null) + { + previewEditor = UnityEditor.Editor.CreateEditor(animationBook.texture2DArray[previewIndex]); + } + + previewEditor.OnInteractivePreviewGUI(r, background); + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationLibrarySO.cs.meta b/Editor/Scripts/Editor/VA_AnimationBookEditor.cs.meta similarity index 83% rename from Runtime/Scripts/VA_AnimationLibrarySO.cs.meta rename to Editor/Scripts/Editor/VA_AnimationBookEditor.cs.meta index 8e82ab2..8f97f06 100644 --- a/Runtime/Scripts/VA_AnimationLibrarySO.cs.meta +++ b/Editor/Scripts/Editor/VA_AnimationBookEditor.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 0d1625f26e651894b954faf1934378dc +guid: 970e86c282fea004fb3b39c887587a36 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Editor/TAO.VertexAnimation.Editor.asmdef b/Editor/TAO.VertexAnimation.Editor.asmdef index 243b73b..6960a1d 100644 --- a/Editor/TAO.VertexAnimation.Editor.asmdef +++ b/Editor/TAO.VertexAnimation.Editor.asmdef @@ -1,7 +1,7 @@ { "name": "TAO.VertexAnimation.Editor", "references": [ - "tech_art_outsource.vertex_animation" + "TAO.VertexAnimation" ], "includePlatforms": [ "Editor" diff --git a/Runtime/Scripts/VA_AnimationBook.cs b/Runtime/Scripts/VA_AnimationBook.cs new file mode 100644 index 0000000..cabb3d7 --- /dev/null +++ b/Runtime/Scripts/VA_AnimationBook.cs @@ -0,0 +1,86 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace TAO.VertexAnimation +{ + [CreateAssetMenu(fileName = "new AnimationBook", menuName = "AnimationBook", order = 0)] + public class VA_AnimationBook : ScriptableObject + { + public int maxFrames; + public List textureGroups = new List() { new TextureGroup { shaderParamName = "_PositionMap", isLinear = false } }; + public List animationPages = new List(); + + public Material[] materials; + public List texture2DArray = null; + + public void Create() + { + // Create textures. + texture2DArray.Clear(); + foreach (var item in GetTextures()) + { + if(VA_Texture2DArrayUtils.IsValidForTextureArray(item.Value.ToArray())) + { + texture2DArray.Add(VA_Texture2DArrayUtils.CreateTextureArray(item.Value.ToArray(), false, textureGroups[item.Key].isLinear, TextureWrapMode.Repeat, FilterMode.Point, 1, name + "-" + item.Key.ToString())); + } + } + + // Assign material parameters. + if(materials != null) + { + foreach (Material mat in materials) + { + if(mat != null) + { + for (int i = 0; i < texture2DArray.Count; i++) + { + mat.SetTexture(textureGroups[i].shaderParamName, texture2DArray[i]); + } + } + } + } + } + + private void OnValidate() + { + foreach (var item in GetTextures()) + { + VA_Texture2DArrayUtils.IsValidForTextureArray(item.Value.ToArray()); + } + } + + private Dictionary> GetTextures() + { + Dictionary> dict = new Dictionary>(); + + // Group and collect the textures. + for (int i = 0; i < textureGroups.Count; i++) + { + dict.Add(i, new List()); + + for (int j = 0; j < animationPages.Count; j++) + { + dict[i].Add(animationPages[j].textures[i]); + } + } + + return dict; + } + } + + [System.Serializable] + public struct VA_AnimationPage + { + public string name; + public int frames; + public List textures; + } + + [System.Serializable] + public struct TextureGroup + { + public string shaderParamName; + public bool isLinear; + } +} \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationBookSO.cs.meta b/Runtime/Scripts/VA_AnimationBook.cs.meta similarity index 100% rename from Runtime/Scripts/VA_AnimationBookSO.cs.meta rename to Runtime/Scripts/VA_AnimationBook.cs.meta diff --git a/Runtime/Scripts/VA_AnimationBookSO.cs b/Runtime/Scripts/VA_AnimationBookSO.cs deleted file mode 100644 index 0ab1f89..0000000 --- a/Runtime/Scripts/VA_AnimationBookSO.cs +++ /dev/null @@ -1,30 +0,0 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; - -namespace TAO.VertexAnimation -{ - [CreateAssetMenu(fileName = "new AnimationBook", menuName = "AnimationBook", order = 0)] - public class VA_AnimationBookSO : ScriptableObject - { - public int maxFrames; - public Material[] materials; - public VA_AnimationPage[] animationPages; - - private void Setup() - { - // TODO: ... - // GenerateTextures. - // SetupMaterials. - } - } - - [System.Serializable] - public struct VA_AnimationPage - { - public string name; - public int frames; - public Texture2D texture2D; - } - -} \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationLibrary.cs b/Runtime/Scripts/VA_AnimationLibrary.cs index 800d3d2..fb1bd05 100644 --- a/Runtime/Scripts/VA_AnimationLibrary.cs +++ b/Runtime/Scripts/VA_AnimationLibrary.cs @@ -1,38 +1,56 @@ -using Unity.Entities; -using Unity.Collections; +using System.Collections.Generic; +using UnityEngine; namespace TAO.VertexAnimation { - [System.Serializable] - public struct VA_AnimationData + [CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "AnimationLibrary", order = 0)] + public class VA_AnimationLibrary : ScriptableObject { - public FixedString32 name; - public int frames; - public int maxFrames; - // 1.0f / maxFrames. - public float frameTime; - // frameTime * frames. - public float duration; - } - - public struct VA_AnimationLibrary - { - public BlobArray animations; - } + [SerializeField] + private VA_AnimationBook[] animationBooks; - public static class VA_AnimationLibraryUtils - { - public static int GetAnimation(ref VA_AnimationLibrary animationsRef, FixedString32 animationName) + [HideInInspector] + public List animations = null; + + public void Create() { - for (int i = 0; i < animationsRef.animations.Length; i++) - { - if (animationsRef.animations[i].name == animationName) - { - return i; - } - } + foreach (VA_AnimationBook book in animationBooks) + { + book.Create(); + } - return -1; - } + ConvertAnimations(); + } + + private void OnValidate() + { + // TODO: Check for naming conflicts in AnimationBooks. + } + + private void ConvertAnimations() + { + animations = new List(); + + if (animationBooks != null) + { + for (int b = 0; b < animationBooks.Length; b++) + { + if(animationBooks[b].animationPages != null) + { + for (int p = 0; p < animationBooks[b].animationPages.Count; p++) + { + animations.Add(new VA_AnimationData + { + name = new Unity.Collections.FixedString32(animationBooks[b].animationPages[p].name), + maxFrames = animationBooks[b].maxFrames, + frames = animationBooks[b].animationPages[p].frames, + frameTime = 1.0f / animationBooks[b].maxFrames, + duration = 1.0f / animationBooks[b].maxFrames * animationBooks[b].animationPages[p].frames + }); + } + } + } + } + } } } \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationLibrary.cs.meta b/Runtime/Scripts/VA_AnimationLibrary.cs.meta index 39fd402..8e82ab2 100644 --- a/Runtime/Scripts/VA_AnimationLibrary.cs.meta +++ b/Runtime/Scripts/VA_AnimationLibrary.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: 79884e6263d984c44af76267d129d76b +guid: 0d1625f26e651894b954faf1934378dc MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs index c20fd74..50e9d6c 100644 --- a/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs +++ b/Runtime/Scripts/VA_AnimationLibraryComponentAuthoring.cs @@ -7,7 +7,7 @@ namespace TAO.VertexAnimation [UnityEngine.DisallowMultipleComponent] public class VA_AnimationLibraryComponentAuthoring : UnityEngine.MonoBehaviour { - public VA_AnimationLibrarySO animationLibrary; + public VA_AnimationLibrary animationLibrary; } public class VA_AnimationLibraryConversionSystem : GameObjectConversionSystem @@ -16,11 +16,14 @@ namespace TAO.VertexAnimation { Entities.ForEach((VA_AnimationLibraryComponentAuthoring animationLib) => { + animationLib.animationLibrary.Create(); + + // Blob builder to build. using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp)) { // Construct the root. - ref VA_AnimationLibrary animationDataBlobAsset = ref blobBuilder.ConstructRoot(); + ref VA_AnimationLibraryData animationDataBlobAsset = ref blobBuilder.ConstructRoot(); // Set all the data. BlobBuilderArray animationDataArray = blobBuilder.Allocate(ref animationDataBlobAsset.animations, animationLib.animationLibrary.animations.Count); @@ -32,7 +35,7 @@ namespace TAO.VertexAnimation } // Construct blob asset reference. - BlobAssetReference animLibAssetRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); + BlobAssetReference animLibAssetRef = blobBuilder.CreateBlobAssetReference(Allocator.Persistent); // Add it to the asset store. // TODO: Generate Hash based on Guid. diff --git a/Runtime/Scripts/VA_AnimationLibraryData.cs b/Runtime/Scripts/VA_AnimationLibraryData.cs new file mode 100644 index 0000000..30189dc --- /dev/null +++ b/Runtime/Scripts/VA_AnimationLibraryData.cs @@ -0,0 +1,38 @@ +using Unity.Entities; +using Unity.Collections; + +namespace TAO.VertexAnimation +{ + [System.Serializable] + public struct VA_AnimationData + { + public FixedString32 name; + public int frames; + public int maxFrames; + // 1.0f / maxFrames. + public float frameTime; + // frameTime * frames. + public float duration; + } + + public struct VA_AnimationLibraryData + { + public BlobArray animations; + } + + public static class VA_AnimationLibraryUtils + { + public static int GetAnimation(ref VA_AnimationLibraryData animationsRef, FixedString32 animationName) + { + for (int i = 0; i < animationsRef.animations.Length; i++) + { + if (animationsRef.animations[i].name == animationName) + { + return i; + } + } + + return -1; + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimationLibraryData.cs.meta b/Runtime/Scripts/VA_AnimationLibraryData.cs.meta new file mode 100644 index 0000000..39fd402 --- /dev/null +++ b/Runtime/Scripts/VA_AnimationLibraryData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 79884e6263d984c44af76267d129d76b +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Runtime/Scripts/VA_AnimationLibrarySO.cs b/Runtime/Scripts/VA_AnimationLibrarySO.cs deleted file mode 100644 index 1af284c..0000000 --- a/Runtime/Scripts/VA_AnimationLibrarySO.cs +++ /dev/null @@ -1,46 +0,0 @@ -using System.Collections.Generic; -using UnityEngine; - -namespace TAO.VertexAnimation -{ - [CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "AnimationLibrary", order = 0)] - public class VA_AnimationLibrarySO : ScriptableObject - { - [SerializeField] - private VA_AnimationBookSO[] animationBooks; - - [HideInInspector] - public List animations = null; - - private void OnValidate() - { - SetupAnimations(); - } - - private void SetupAnimations() - { - animations = new List(); - - if (animationBooks != null) - { - for (int b = 0; b < animationBooks.Length; b++) - { - if(animationBooks[b].animationPages != null) - { - for (int p = 0; p < animationBooks[b].animationPages.Length; p++) - { - animations.Add(new VA_AnimationData - { - name = new Unity.Collections.FixedString32(animationBooks[b].animationPages[p].name), - maxFrames = animationBooks[b].maxFrames, - frames = animationBooks[b].animationPages[p].frames, - frameTime = 1.0f / animationBooks[b].maxFrames, - duration = 1.0f / animationBooks[b].maxFrames * animationBooks[b].animationPages[p].frames - }); - } - } - } - } - } - } -} \ No newline at end of file diff --git a/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs b/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs index b71aa92..e3a2256 100644 --- a/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs +++ b/Runtime/Scripts/VA_AnimatorComponentAuthoring.cs @@ -17,7 +17,7 @@ namespace TAO.VertexAnimation public int animationIndex; public int animationIndexSchedule; public float animationTime; - public BlobAssetReference animationLibrary; + public BlobAssetReference animationLibrary; } [UpdateAfter(typeof(VA_AnimationLibraryConversionSystem))] @@ -25,7 +25,7 @@ namespace TAO.VertexAnimation { protected override void OnUpdate() { - BlobAssetStore.TryGet(new Unity.Entities.Hash128("AnimationLib"), out BlobAssetReference animLib); + BlobAssetStore.TryGet(new Unity.Entities.Hash128("AnimationLib"), out BlobAssetReference animLib); Entities.ForEach((VA_AnimatorComponentAuthoring animator) => { diff --git a/Runtime/Scripts/VA_AnimatorSystem.cs b/Runtime/Scripts/VA_AnimatorSystem.cs index 7af742f..779d9bb 100644 --- a/Runtime/Scripts/VA_AnimatorSystem.cs +++ b/Runtime/Scripts/VA_AnimatorSystem.cs @@ -53,7 +53,7 @@ namespace TAO.VertexAnimation Entities.ForEach((ref VA_AnimatorComponent ac) => { // Get the animation lib data. - ref VA_AnimationLibrary animationsRef = ref ac.animationLibrary.Value; + ref VA_AnimationLibraryData animationsRef = ref ac.animationLibrary.Value; ac.animationTime += deltaTime; @@ -74,7 +74,7 @@ namespace TAO.VertexAnimation Entities.ForEach((Entity entity, ref VA_AnimatorComponent ac) => { // Get the animation lib data. - ref VA_AnimationLibrary animationLib = ref ac.animationLibrary.Value; + ref VA_AnimationLibraryData animationLib = ref ac.animationLibrary.Value; int animationIndex = VA_AnimationLibraryUtils.GetAnimation(ref animationLib, "Shoot"); diff --git a/Runtime/Scripts/VA_Texture2DArrayUtils.cs b/Runtime/Scripts/VA_Texture2DArrayUtils.cs new file mode 100644 index 0000000..21b1375 --- /dev/null +++ b/Runtime/Scripts/VA_Texture2DArrayUtils.cs @@ -0,0 +1,64 @@ +using UnityEngine; + +namespace TAO.VertexAnimation +{ + public static class VA_Texture2DArrayUtils + { + public static Texture2DArray CreateTextureArray(Texture2D[] a_textures, bool a_useMipChain, bool a_isLinear, + TextureWrapMode a_wrapMode = TextureWrapMode.Repeat, FilterMode a_filterMode = FilterMode.Bilinear, int a_anisoLevel = 1, string a_name = "") + { + if(!IsValidForTextureArray(a_textures)) + { + return null; + } + + Texture2DArray textureArray = new Texture2DArray(a_textures[0].width, a_textures[0].height, a_textures.Length, a_textures[0].format, a_useMipChain, a_isLinear); + + for (int i = 0; i < a_textures.Length; i++) + { + Graphics.CopyTexture(a_textures[i], 0, 0, textureArray, i, 0); + } + + textureArray.wrapMode = a_wrapMode; + textureArray.filterMode = a_filterMode; + textureArray.anisoLevel = a_anisoLevel; + textureArray.name = a_name; + + textureArray.Apply(false, false); + + return textureArray; + } + + public static bool IsValidForTextureArray(Texture2D[] a_textures) + { + if (a_textures == null || a_textures.Length <= 0) + { + Debug.LogError("No textures assigned!"); + return false; + } + + for (int i = 0; i < a_textures.Length; i++) + { + if (a_textures[i] == null) + { + Debug.LogError("Texture " + i.ToString() + " not assigned!"); + return false; + } + + if (a_textures[0].width != a_textures[i].width || a_textures[0].height != a_textures[i].height) + { + Debug.LogError("Texture " + a_textures[i].name + " has a different size!"); + return false; + } + + if (a_textures[0].format != a_textures[i].format || a_textures[0].graphicsFormat != a_textures[i].graphicsFormat) + { + Debug.LogError("Texture " + a_textures[i].name + " has a different format/graphics format!"); + return false; + } + } + + return true; + } + } +} \ No newline at end of file diff --git a/Runtime/Scripts/VA_Texture2DArrayUtils.cs.meta b/Runtime/Scripts/VA_Texture2DArrayUtils.cs.meta new file mode 100644 index 0000000..cfb53be --- /dev/null +++ b/Runtime/Scripts/VA_Texture2DArrayUtils.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 85b760f664e13f84a940f7859bc9a684 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: