mirror of
				https://github.com/maxartz15/VertexAnimation.git
				synced 2025-11-04 02:15:59 +01:00 
			
		
		
		
	AssetBuilder
Removed functionality from the books. Seperated editor and play data.
This commit is contained in:
		@@ -10,9 +10,9 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
        private Vector2 textureGroupScollPos;
 | 
			
		||||
        private Vector2 animationPagesScollPos;
 | 
			
		||||
 | 
			
		||||
        private UnityEditor.Editor previewEditor = null;
 | 
			
		||||
        private int previewIndex = 0;
 | 
			
		||||
        private int curviewIndex = 0;
 | 
			
		||||
        //private UnityEditor.Editor previewEditor = null;
 | 
			
		||||
        //private int previewIndex = 0;
 | 
			
		||||
        //private int curviewIndex = 0;
 | 
			
		||||
 | 
			
		||||
        void OnEnable()
 | 
			
		||||
        {
 | 
			
		||||
@@ -29,6 +29,7 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
            SyncListSize();
 | 
			
		||||
            AnimationPagesGUI();
 | 
			
		||||
            MaterialGUI();
 | 
			
		||||
            AssetBuilderGUI();
 | 
			
		||||
            Texture2DGUI();
 | 
			
		||||
 | 
			
		||||
            serializedObject.ApplyModifiedProperties();
 | 
			
		||||
@@ -36,20 +37,20 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
 | 
			
		||||
        private void SyncListSize()
 | 
			
		||||
        {
 | 
			
		||||
            foreach (var page in animationBook.animationPages)
 | 
			
		||||
            foreach (var page in animationBook.editorData.animationPages)
 | 
			
		||||
            {
 | 
			
		||||
                if(page.textures.Count < animationBook.textureGroups.Count)
 | 
			
		||||
                if(page.textures.Count < animationBook.editorData.textureGroups.Count)
 | 
			
		||||
                {
 | 
			
		||||
                    int diff = animationBook.textureGroups.Count - page.textures.Count;
 | 
			
		||||
                    int diff = animationBook.editorData.textureGroups.Count - page.textures.Count;
 | 
			
		||||
 | 
			
		||||
                    for (int i = 0; i < diff; i++)
 | 
			
		||||
                    {
 | 
			
		||||
                        page.textures.Add(null);
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
                else if(page.textures.Count > animationBook.textureGroups.Count)
 | 
			
		||||
                else if(page.textures.Count > animationBook.editorData.textureGroups.Count)
 | 
			
		||||
                {
 | 
			
		||||
                    int diff = page.textures.Count - animationBook.textureGroups.Count;
 | 
			
		||||
                    int diff = page.textures.Count - animationBook.editorData.textureGroups.Count;
 | 
			
		||||
 | 
			
		||||
                    for (int i = 0; i < diff; i++)
 | 
			
		||||
                    {
 | 
			
		||||
@@ -61,16 +62,19 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
 | 
			
		||||
        private void GeneralGUI()
 | 
			
		||||
        {
 | 
			
		||||
            SerializedProperty editorData = serializedObject.FindProperty("editorData");
 | 
			
		||||
 | 
			
		||||
            using (new EditorGUILayout.VerticalScope())
 | 
			
		||||
            {
 | 
			
		||||
                EditorGUILayout.LabelField("General", EditorStyles.centeredGreyMiniLabel);
 | 
			
		||||
                EditorGUILayout.PropertyField(serializedObject.FindProperty("maxFrames"));
 | 
			
		||||
                EditorGUILayout.PropertyField(editorData.FindPropertyRelative("maxFrames"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void TextureGroupsGUI()
 | 
			
		||||
        {
 | 
			
		||||
            SerializedProperty textureGroups = serializedObject.FindProperty("textureGroups");
 | 
			
		||||
            SerializedProperty editorData = serializedObject.FindProperty("editorData");
 | 
			
		||||
            SerializedProperty textureGroups = editorData.FindPropertyRelative("textureGroups");
 | 
			
		||||
            int removeWidth = 16;
 | 
			
		||||
            int nameWidth = 152;
 | 
			
		||||
            int optionWidth = 110;
 | 
			
		||||
@@ -114,7 +118,7 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
 | 
			
		||||
                if (GUILayout.Button("+", EditorStyles.miniButton))
 | 
			
		||||
                {
 | 
			
		||||
                    animationBook.textureGroups.Add(new TextureGroup
 | 
			
		||||
                    animationBook.editorData.textureGroups.Add(new VA_AnimationBook.EditorTextureGroup
 | 
			
		||||
                    {
 | 
			
		||||
                        shaderParamName = "_ShaderPropertyName",
 | 
			
		||||
                        isLinear = false
 | 
			
		||||
@@ -125,7 +129,8 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
 | 
			
		||||
        private void AnimationPagesGUI()
 | 
			
		||||
        {
 | 
			
		||||
            SerializedProperty animationPages = serializedObject.FindProperty("animationPages");
 | 
			
		||||
            SerializedProperty editorData = serializedObject.FindProperty("editorData");
 | 
			
		||||
            SerializedProperty animationPages = editorData.FindPropertyRelative("animationPages");
 | 
			
		||||
            int removeWidth = 16;
 | 
			
		||||
            int nameWidth = 100;
 | 
			
		||||
            int frameWidth = 50;
 | 
			
		||||
@@ -141,7 +146,7 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
                    EditorGUILayout.LabelField("", GUILayout.Width(removeWidth));
 | 
			
		||||
                    EditorGUILayout.LabelField("name", GUILayout.Width(nameWidth));
 | 
			
		||||
                    EditorGUILayout.LabelField("frames", GUILayout.Width(frameWidth));
 | 
			
		||||
                    foreach (var t in animationBook.textureGroups)
 | 
			
		||||
                    foreach (var t in animationBook.editorData.textureGroups)
 | 
			
		||||
                    {
 | 
			
		||||
                        EditorGUILayout.LabelField(t.shaderParamName, GUILayout.MinWidth(textureWidth));
 | 
			
		||||
                    }
 | 
			
		||||
@@ -180,7 +185,7 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
                if (GUILayout.Button("auto fill", EditorStyles.miniButton))
 | 
			
		||||
                {
 | 
			
		||||
                    Undo.RecordObject(animationBook, "AutoFill");
 | 
			
		||||
                    animationBook.AutoFill();
 | 
			
		||||
                    VA_AssetBuilder.AutoFill(ref animationBook);
 | 
			
		||||
                    EditorUtility.SetDirty(animationBook);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
@@ -188,20 +193,40 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
 | 
			
		||||
        private void MaterialGUI()
 | 
			
		||||
        {
 | 
			
		||||
            SerializedProperty editorData = serializedObject.FindProperty("editorData");
 | 
			
		||||
 | 
			
		||||
            using (new EditorGUILayout.VerticalScope())
 | 
			
		||||
            {
 | 
			
		||||
                EditorGUILayout.LabelField("Materials", EditorStyles.centeredGreyMiniLabel);
 | 
			
		||||
                EditorGUILayout.PropertyField(serializedObject.FindProperty("materials"));
 | 
			
		||||
                EditorGUILayout.PropertyField(editorData.FindPropertyRelative("materials"));
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void AssetBuilderGUI()
 | 
			
		||||
        {
 | 
			
		||||
            using (new EditorGUILayout.HorizontalScope())
 | 
			
		||||
            {
 | 
			
		||||
                if (GUILayout.Button("build assets", EditorStyles.miniButtonLeft))
 | 
			
		||||
                {
 | 
			
		||||
                    VA_AssetBuilder.GeneratePlayData();
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                if (GUILayout.Button("clear assets", EditorStyles.miniButtonRight))
 | 
			
		||||
                {
 | 
			
		||||
                    VA_AssetBuilder.ClearBuildData();
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void Texture2DGUI()
 | 
			
		||||
        {
 | 
			
		||||
            SerializedProperty editorData = serializedObject.FindProperty("editorData");
 | 
			
		||||
 | 
			
		||||
            if (HasPreviewGUI())
 | 
			
		||||
            {
 | 
			
		||||
                using (new EditorGUILayout.VerticalScope())
 | 
			
		||||
                {
 | 
			
		||||
                    SerializedProperty texture2DArray = serializedObject.FindProperty("texture2DArray");
 | 
			
		||||
                    SerializedProperty texture2DArray = editorData.FindPropertyRelative("texture2DArray");
 | 
			
		||||
 | 
			
		||||
                    EditorGUILayout.LabelField("Texture2DArray", EditorStyles.centeredGreyMiniLabel);
 | 
			
		||||
 | 
			
		||||
@@ -210,32 +235,32 @@ namespace TAO.VertexAnimation.Editor
 | 
			
		||||
                        EditorGUILayout.PropertyField(texture2DArray);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    previewIndex = EditorGUILayout.IntSlider("Preview" ,previewIndex, 0, texture2DArray.arraySize - 1);
 | 
			
		||||
                    //previewIndex = EditorGUILayout.IntSlider("Preview" ,previewIndex, 0, texture2DArray.arraySize - 1);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public override bool HasPreviewGUI()
 | 
			
		||||
        {
 | 
			
		||||
            bool hasPreview = false;
 | 
			
		||||
        //public override bool HasPreviewGUI()
 | 
			
		||||
        //{
 | 
			
		||||
        //    bool hasPreview = false;
 | 
			
		||||
 | 
			
		||||
            if(animationBook.texture2DArray != null && animationBook.texture2DArray.Count > 0 && animationBook.texture2DArray[previewIndex] != null)
 | 
			
		||||
            {
 | 
			
		||||
                hasPreview = true;
 | 
			
		||||
            }
 | 
			
		||||
        //    if(animationBook.editorData.texture2DArray != null && animationBook.editorData.texture2DArray.Count > 0 && animationBook.editorData.texture2DArray[previewIndex] != null)
 | 
			
		||||
        //    {
 | 
			
		||||
        //        hasPreview = true;
 | 
			
		||||
        //    }
 | 
			
		||||
 | 
			
		||||
            return hasPreview;
 | 
			
		||||
        }
 | 
			
		||||
        //    return hasPreview;
 | 
			
		||||
        //}
 | 
			
		||||
 | 
			
		||||
        public override void OnPreviewGUI(Rect r, GUIStyle background)
 | 
			
		||||
        {
 | 
			
		||||
            if (previewEditor == null || curviewIndex != previewIndex)
 | 
			
		||||
            {
 | 
			
		||||
                curviewIndex = previewIndex;
 | 
			
		||||
                previewEditor = CreateEditor(animationBook.texture2DArray[previewIndex]);
 | 
			
		||||
            }
 | 
			
		||||
        //public override void OnPreviewGUI(Rect r, GUIStyle background)
 | 
			
		||||
        //{
 | 
			
		||||
        //    if (previewEditor == null || curviewIndex != previewIndex)
 | 
			
		||||
        //    {
 | 
			
		||||
        //        curviewIndex = previewIndex;
 | 
			
		||||
        //        previewEditor = CreateEditor(animationBook.editorData.texture2DArray[previewIndex]);
 | 
			
		||||
        //    }
 | 
			
		||||
 | 
			
		||||
            previewEditor.OnInteractivePreviewGUI(r, background);
 | 
			
		||||
        }
 | 
			
		||||
        //    previewEditor.OnInteractivePreviewGUI(r, background);
 | 
			
		||||
        //}
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										328
									
								
								Editor/Scripts/VA_AssetBuilder.cs
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										328
									
								
								Editor/Scripts/VA_AssetBuilder.cs
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,328 @@
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using UnityEngine;
 | 
			
		||||
using UnityEditor;
 | 
			
		||||
using UnityEditor.Build;
 | 
			
		||||
using UnityEditor.Build.Reporting;
 | 
			
		||||
using Unity.Collections;
 | 
			
		||||
 | 
			
		||||
namespace TAO.VertexAnimation.Editor
 | 
			
		||||
{
 | 
			
		||||
    [InitializeOnLoad]
 | 
			
		||||
    public class VA_AssetBuilder : IPreprocessBuildWithReport, IPostprocessBuildWithReport
 | 
			
		||||
    {
 | 
			
		||||
        static VA_AssetBuilder()
 | 
			
		||||
        {
 | 
			
		||||
            EditorApplication.playModeStateChanged += OnPlayModeEnter;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public int callbackOrder => 0;
 | 
			
		||||
        private static bool deleteGeneratedAssets = true;
 | 
			
		||||
 | 
			
		||||
        private const string parentFolder = "Assets";
 | 
			
		||||
        private const string childFolder = "VA_AssetBuilder";
 | 
			
		||||
        private static string FolderPath => string.Format("{0}/{1}", parentFolder, childFolder);
 | 
			
		||||
 | 
			
		||||
        public void OnPreprocessBuild(BuildReport report)
 | 
			
		||||
        {
 | 
			
		||||
            GeneratePlayData();
 | 
			
		||||
            Debug.Log("VA_AssetBuilder generated play data.");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public void OnPostprocessBuild(BuildReport report)
 | 
			
		||||
        {
 | 
			
		||||
            if(!deleteGeneratedAssets)
 | 
			
		||||
            {
 | 
			
		||||
                return;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            ClearBuildData();
 | 
			
		||||
            Debug.Log("VA_AssetBuilder cleared play data.");
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private static void OnPlayModeEnter(PlayModeStateChange state)
 | 
			
		||||
        {
 | 
			
		||||
            switch (state)
 | 
			
		||||
            {
 | 
			
		||||
                case PlayModeStateChange.EnteredEditMode:
 | 
			
		||||
                    //ClearBuildData();
 | 
			
		||||
                    //Debug.Log("VA_AssetBuilder cleared editor data.");
 | 
			
		||||
                    break;
 | 
			
		||||
                case PlayModeStateChange.ExitingEditMode:
 | 
			
		||||
                    //GeneratePlayData();
 | 
			
		||||
                    GenerateEditorData();
 | 
			
		||||
                    Debug.Log("VA_AssetBuilder generated editor data.");
 | 
			
		||||
                    break;
 | 
			
		||||
                case PlayModeStateChange.EnteredPlayMode:
 | 
			
		||||
                    break;
 | 
			
		||||
                case PlayModeStateChange.ExitingPlayMode:
 | 
			
		||||
                    break;
 | 
			
		||||
                default:
 | 
			
		||||
                    break;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static void GenerateEditorData()
 | 
			
		||||
        {
 | 
			
		||||
            string filter = string.Format("t:{0}", typeof(VA_AnimationBook).Name);
 | 
			
		||||
            string[] guids = AssetDatabase.FindAssets(filter);
 | 
			
		||||
 | 
			
		||||
            foreach (var guid in guids)
 | 
			
		||||
            {
 | 
			
		||||
                VA_AnimationBook book = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(VA_AnimationBook)) as VA_AnimationBook;
 | 
			
		||||
                            
 | 
			
		||||
                // Generate run time data.
 | 
			
		||||
                //GenerateTextures(ref book);
 | 
			
		||||
 | 
			
		||||
                // Assign run time data.
 | 
			
		||||
                ConvertEditorDataToPlayData(ref book);
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [MenuItem("Assets/TAO Vertex Animation/Generate Build Data", false, 65)]
 | 
			
		||||
        public static void GeneratePlayData()
 | 
			
		||||
        {
 | 
			
		||||
            string filter = string.Format("t:{0}", typeof(VA_AnimationBook).Name);
 | 
			
		||||
            string[] guids = AssetDatabase.FindAssets(filter);
 | 
			
		||||
 | 
			
		||||
            foreach (var guid in guids)
 | 
			
		||||
            {
 | 
			
		||||
                VA_AnimationBook book = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(VA_AnimationBook)) as VA_AnimationBook;
 | 
			
		||||
 | 
			
		||||
                // Generate all assets.
 | 
			
		||||
                GenerateTextures(ref book);
 | 
			
		||||
 | 
			
		||||
                // Assign run time data.
 | 
			
		||||
                ConvertEditorDataToPlayData(ref book);
 | 
			
		||||
 | 
			
		||||
                // Save them to disk.
 | 
			
		||||
                if (!AssetDatabase.IsValidFolder(FolderPath))
 | 
			
		||||
                {
 | 
			
		||||
                    deleteGeneratedAssets = true;
 | 
			
		||||
                    AssetDatabase.CreateFolder(parentFolder, childFolder);
 | 
			
		||||
                }
 | 
			
		||||
                else
 | 
			
		||||
                {
 | 
			
		||||
                    deleteGeneratedAssets = false;
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                // Generate run time data.
 | 
			
		||||
                List<string> savedAssets = new List<string>();
 | 
			
		||||
                foreach (var t in book.editorData.texture2DArray)
 | 
			
		||||
                {
 | 
			
		||||
                    string assetPath = string.Format("{0}/{1}.asset", FolderPath, t.name);
 | 
			
		||||
 | 
			
		||||
                    // Delete existing asset.
 | 
			
		||||
                    if (!string.IsNullOrEmpty(AssetDatabase.AssetPathToGUID(assetPath)))
 | 
			
		||||
                    {
 | 
			
		||||
                        AssetDatabase.DeleteAsset(assetPath);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    AssetDatabase.CreateAsset(t, assetPath);
 | 
			
		||||
                    savedAssets.Add(assetPath);
 | 
			
		||||
                }
 | 
			
		||||
                AssetDatabase.SaveAssets();
 | 
			
		||||
 | 
			
		||||
                book.playData.texture2DArray = new List<Texture2DArray>();
 | 
			
		||||
                foreach (var s in savedAssets)
 | 
			
		||||
                {
 | 
			
		||||
                    var savedT = AssetDatabase.LoadAssetAtPath(s, typeof(Texture2DArray)) as Texture2DArray;
 | 
			
		||||
                    book.playData.texture2DArray.Add(savedT);
 | 
			
		||||
                }
 | 
			
		||||
                AssetDatabase.SaveAssets();
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [MenuItem("Assets/TAO Vertex Animation/Clear Build Data", false, 66)]
 | 
			
		||||
        public static void ClearBuildData()
 | 
			
		||||
        {
 | 
			
		||||
            string filter = string.Format("t:{0}", typeof(VA_AnimationBook).Name);
 | 
			
		||||
            string[] guids = AssetDatabase.FindAssets(filter);
 | 
			
		||||
 | 
			
		||||
            // Clear Generated Data.
 | 
			
		||||
            foreach (var guid in guids)
 | 
			
		||||
            {
 | 
			
		||||
                VA_AnimationBook book = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), typeof(VA_AnimationBook)) as VA_AnimationBook;
 | 
			
		||||
                book.playData.texture2DArray = null;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            // Remove generated assets from disk.
 | 
			
		||||
            if (AssetDatabase.IsValidFolder(FolderPath))
 | 
			
		||||
            {
 | 
			
		||||
                AssetDatabase.DeleteAsset(FolderPath);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            AssetDatabase.SaveAssets();
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Assign the texture ID's to the texture entries.
 | 
			
		||||
        private static void ReferenceDuplicates(ref VA_AnimationBook book)
 | 
			
		||||
        {
 | 
			
		||||
            for (int i = 0; i < book.editorData.textureGroups.Count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                List<Texture2D> t = new List<Texture2D>();
 | 
			
		||||
 | 
			
		||||
                for (int j = 0; j < book.editorData.animationPages.Count; j++)
 | 
			
		||||
                {
 | 
			
		||||
                    // Check if exist.
 | 
			
		||||
                    if (!t.Contains(book.editorData.animationPages[j].textures[i].texture2D))
 | 
			
		||||
                    {
 | 
			
		||||
                        t.Add(book.editorData.animationPages[j].textures[i].texture2D);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    // Add index reference.
 | 
			
		||||
                    book.editorData.animationPages[j].textures[i].textureArrayIndex = t.IndexOf(book.editorData.animationPages[j].textures[i].texture2D);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Get the textures from a specific texture index.
 | 
			
		||||
        private static List<Texture2D> GetTextures(ref VA_AnimationBook book, int textureIndex)
 | 
			
		||||
        {
 | 
			
		||||
            List<Texture2D> textures = new List<Texture2D>();
 | 
			
		||||
 | 
			
		||||
            foreach (var ap in book.editorData.animationPages)
 | 
			
		||||
            {
 | 
			
		||||
                // Check if exist.
 | 
			
		||||
                if (!textures.Contains(ap.textures[textureIndex].texture2D))
 | 
			
		||||
                {
 | 
			
		||||
                    textures.Add(ap.textures[textureIndex].texture2D);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return textures;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Generate texture arrays.
 | 
			
		||||
        public static void GenerateTextures(ref VA_AnimationBook book)
 | 
			
		||||
        {
 | 
			
		||||
            ReferenceDuplicates(ref book);
 | 
			
		||||
 | 
			
		||||
            book.editorData.texture2DArray = new List<Texture2DArray>();
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < book.editorData.textureGroups.Count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                var t = GetTextures(ref book, i).ToArray();
 | 
			
		||||
 | 
			
		||||
                if (VA_Texture2DArrayUtils.IsValidForTextureArray(t))
 | 
			
		||||
                {
 | 
			
		||||
                    book.editorData.texture2DArray.Add(VA_Texture2DArrayUtils.CreateTextureArray(t, false, book.editorData.textureGroups[i].isLinear, book.editorData.textureGroups[i].wrapMode, book.editorData.textureGroups[i].filterMode, 1, book.name + book.editorData.textureGroups[i].shaderParamName));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Auto fill names and frames.
 | 
			
		||||
        public static void AutoFill(ref VA_AnimationBook book)
 | 
			
		||||
        {
 | 
			
		||||
            if (book.editorData.animationPages != null)
 | 
			
		||||
            {
 | 
			
		||||
                for (int i = 0; i < book.editorData.animationPages.Count; i++)
 | 
			
		||||
                {
 | 
			
		||||
                    VA_AnimationBook.EditorAnimationPage ap = book.editorData.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;
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
                    book.editorData.animationPages[i] = ap;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static int GetFirstAnimationMapIndex(in List<VA_AnimationBook.EditorTextureEntry> textures, in List<VA_AnimationBook.EditorTextureGroup> textureGroups)
 | 
			
		||||
        {
 | 
			
		||||
            for (int i = 0; i < textureGroups.Count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                if (textureGroups[i].textureType == VA_AnimationBook.TextureType.AnimationMap)
 | 
			
		||||
                {
 | 
			
		||||
                    return textures[i].textureArrayIndex;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public static int GetFirstColorMapIndex(in List<VA_AnimationBook.EditorTextureEntry> textures, in List<VA_AnimationBook.EditorTextureGroup> textureGroups)
 | 
			
		||||
        {
 | 
			
		||||
            for (int i = 0; i < textureGroups.Count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                if (textureGroups[i].textureType == VA_AnimationBook.TextureType.ColorMap)
 | 
			
		||||
                {
 | 
			
		||||
                    return textures[i].textureArrayIndex;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        // Convert editor data into play data.
 | 
			
		||||
        // NOTE: Textures need to be assigned with stored ones on build.
 | 
			
		||||
        public static void ConvertEditorDataToPlayData(ref VA_AnimationBook book)
 | 
			
		||||
        {
 | 
			
		||||
            book.playData = new VA_AnimationBook.PlayData
 | 
			
		||||
            {
 | 
			
		||||
                maxFrames = book.editorData.maxFrames,
 | 
			
		||||
                materials = book.editorData.materials
 | 
			
		||||
            };
 | 
			
		||||
 | 
			
		||||
            foreach (var tg in book.editorData.textureGroups)
 | 
			
		||||
            {
 | 
			
		||||
                book.playData.textureGroups.Add(new VA_AnimationBook.PlayTextureGroup
 | 
			
		||||
                {
 | 
			
		||||
                    shaderParamName = tg.shaderParamName,
 | 
			
		||||
                    textureType = tg.textureType
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            foreach (var ap in book.editorData.animationPages)
 | 
			
		||||
            {
 | 
			
		||||
                // NOTE: for some reason FixedString32 data gets lost when entering play mode.
 | 
			
		||||
                // That is why this is here... and also the animationPages...
 | 
			
		||||
                //book.playData.animations.Add(new VA_AnimationData
 | 
			
		||||
                //{
 | 
			
		||||
                //    name = ap.name,
 | 
			
		||||
                //    frames = ap.frames,
 | 
			
		||||
                //    maxFrames = book.editorData.maxFrames,
 | 
			
		||||
                //    frameTime = 1.0f / book.editorData.maxFrames,
 | 
			
		||||
                //    duration = 1.0f / book.editorData.maxFrames * ap.frames,
 | 
			
		||||
                //    animationMapIndex = GetFirstAnimationMapIndex(in ap.textures, in book.editorData.textureGroups),
 | 
			
		||||
                //    colorMapIndex = GetFirstColorMapIndex(in ap.textures, in book.editorData.textureGroups)
 | 
			
		||||
                //});
 | 
			
		||||
 | 
			
		||||
                var pap = new VA_AnimationBook.PlayAnimationPage
 | 
			
		||||
                {
 | 
			
		||||
                    name = ap.name,
 | 
			
		||||
                    frames = ap.frames,
 | 
			
		||||
                    textures = new List<VA_AnimationBook.PlayTextureEntry>()
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
                foreach (var t in ap.textures)
 | 
			
		||||
                {
 | 
			
		||||
                    pap.textures.Add(new VA_AnimationBook.PlayTextureEntry 
 | 
			
		||||
                    {
 | 
			
		||||
                        textureArrayIndex = t.textureArrayIndex
 | 
			
		||||
                    });
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                book.playData.animationPages.Add(pap);
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            book.playData.texture2DArray = book.editorData.texture2DArray;
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										11
									
								
								Editor/Scripts/VA_AssetBuilder.cs.meta
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										11
									
								
								Editor/Scripts/VA_AssetBuilder.cs.meta
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,11 @@
 | 
			
		||||
fileFormatVersion: 2
 | 
			
		||||
guid: f21cb651117dd1c4681e87105b7a3f10
 | 
			
		||||
MonoImporter:
 | 
			
		||||
  externalObjects: {}
 | 
			
		||||
  serializedVersion: 2
 | 
			
		||||
  defaultReferences: []
 | 
			
		||||
  executionOrder: 0
 | 
			
		||||
  icon: {instanceID: 0}
 | 
			
		||||
  userData: 
 | 
			
		||||
  assetBundleName: 
 | 
			
		||||
  assetBundleVariant: 
 | 
			
		||||
@@ -1,7 +1,9 @@
 | 
			
		||||
{
 | 
			
		||||
    "name": "TAO.VertexAnimation.Editor",
 | 
			
		||||
    "rootNamespace": "TAO.VertexAnimation.Editor",
 | 
			
		||||
    "references": [
 | 
			
		||||
        "TAO.VertexAnimation"
 | 
			
		||||
        "TAO.VertexAnimation",
 | 
			
		||||
        "Unity.Collections"
 | 
			
		||||
    ],
 | 
			
		||||
    "includePlatforms": [
 | 
			
		||||
        "Editor"
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,4 @@
 | 
			
		||||
using System.Collections;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using UnityEngine;
 | 
			
		||||
 | 
			
		||||
namespace TAO.VertexAnimation
 | 
			
		||||
@@ -7,18 +6,10 @@ namespace TAO.VertexAnimation
 | 
			
		||||
    [CreateAssetMenu(fileName = "new AnimationBook", menuName = "VA_Animation/AnimationBook", order = 400)]
 | 
			
		||||
    public class VA_AnimationBook : ScriptableObject
 | 
			
		||||
    {
 | 
			
		||||
        public int maxFrames;
 | 
			
		||||
        public List<TextureGroup> textureGroups = new List<TextureGroup>() { new TextureGroup { shaderParamName = "_PositionMap", textureType = TextureType.AnimationMap, wrapMode = TextureWrapMode.Repeat, filterMode = FilterMode.Point, isLinear = false } };
 | 
			
		||||
        public List<VA_AnimationPage> animationPages = new List<VA_AnimationPage>();
 | 
			
		||||
 | 
			
		||||
        public Material[] materials;
 | 
			
		||||
        public List<Texture2DArray> texture2DArray = null;
 | 
			
		||||
 | 
			
		||||
        public void Create()
 | 
			
		||||
        {
 | 
			
		||||
            GenerateTextures();
 | 
			
		||||
            SetMaterials();
 | 
			
		||||
        }
 | 
			
		||||
        public PlayData playData = null;
 | 
			
		||||
#if UNITY_EDITOR
 | 
			
		||||
        public EditorData editorData = new EditorData();
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
        private void OnValidate()
 | 
			
		||||
        {
 | 
			
		||||
@@ -26,77 +17,24 @@ namespace TAO.VertexAnimation
 | 
			
		||||
            // TODO: Debug message box instead of debug logs.
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void ReferenceDuplicates()
 | 
			
		||||
        public void SetMaterials()
 | 
			
		||||
        {
 | 
			
		||||
            for (int i = 0; i < textureGroups.Count; i++)
 | 
			
		||||
            if (playData.materials != null)
 | 
			
		||||
            {
 | 
			
		||||
                List<Texture2D> t = new List<Texture2D>();
 | 
			
		||||
 | 
			
		||||
                for (int j = 0; j < animationPages.Count; j++)
 | 
			
		||||
                {
 | 
			
		||||
                    // Check if exist.
 | 
			
		||||
                    if (!t.Contains(animationPages[j].textures[i].texture2D))
 | 
			
		||||
                    {
 | 
			
		||||
                        t.Add(animationPages[j].textures[i].texture2D);
 | 
			
		||||
                    }
 | 
			
		||||
 | 
			
		||||
                    // Add index reference.
 | 
			
		||||
                    animationPages[j].textures[i].textureArrayIndex = t.IndexOf(animationPages[j].textures[i].texture2D);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void GenerateTextures()
 | 
			
		||||
        {
 | 
			
		||||
            ReferenceDuplicates();
 | 
			
		||||
 | 
			
		||||
            texture2DArray.Clear();
 | 
			
		||||
 | 
			
		||||
            for (int i = 0; i < textureGroups.Count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                var t = GetTextures(i).ToArray();
 | 
			
		||||
 | 
			
		||||
                if (VA_Texture2DArrayUtils.IsValidForTextureArray(t))
 | 
			
		||||
                {
 | 
			
		||||
                    texture2DArray.Add(VA_Texture2DArrayUtils.CreateTextureArray(t, false, textureGroups[i].isLinear, textureGroups[i].wrapMode, textureGroups[i].filterMode, 1, name + textureGroups[i].shaderParamName));
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private List<Texture2D> GetTextures(int textureIndex)
 | 
			
		||||
        {
 | 
			
		||||
            List<Texture2D> textures = new List<Texture2D>();
 | 
			
		||||
 | 
			
		||||
            foreach (var ap in animationPages)
 | 
			
		||||
            {
 | 
			
		||||
                // Check if exist.
 | 
			
		||||
                if (!textures.Contains(ap.textures[textureIndex].texture2D))
 | 
			
		||||
                {
 | 
			
		||||
                    textures.Add(ap.textures[textureIndex].texture2D);
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return textures;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private void SetMaterials()
 | 
			
		||||
        {
 | 
			
		||||
            if (materials != null)
 | 
			
		||||
            {
 | 
			
		||||
                foreach (Material mat in materials)
 | 
			
		||||
                foreach (Material mat in playData.materials)
 | 
			
		||||
                {
 | 
			
		||||
                    if (mat != null)
 | 
			
		||||
                    {
 | 
			
		||||
                        if (mat.HasProperty("_MaxFrames"))
 | 
			
		||||
                        {
 | 
			
		||||
                            mat.SetFloat("_MaxFrames", maxFrames);
 | 
			
		||||
                            mat.SetFloat("_MaxFrames", playData.maxFrames);
 | 
			
		||||
                        }
 | 
			
		||||
 | 
			
		||||
                        for (int i = 0; i < texture2DArray.Count; i++)
 | 
			
		||||
                        for (int i = 0; i < playData.texture2DArray.Count; i++)
 | 
			
		||||
                        {
 | 
			
		||||
                            if (mat.HasProperty(textureGroups[i].shaderParamName))
 | 
			
		||||
                            if (mat.HasProperty(playData.textureGroups[i].shaderParamName))
 | 
			
		||||
                            {
 | 
			
		||||
                                mat.SetTexture(textureGroups[i].shaderParamName, texture2DArray[i]);
 | 
			
		||||
                                mat.SetTexture(playData.textureGroups[i].shaderParamName, playData.texture2DArray[i]);
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                    }
 | 
			
		||||
@@ -104,116 +42,134 @@ namespace TAO.VertexAnimation
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public List<VA_AnimationData> GetAnimationData()
 | 
			
		||||
        #region PlayData
 | 
			
		||||
        [System.Serializable]
 | 
			
		||||
        public class PlayData
 | 
			
		||||
        {
 | 
			
		||||
            List<VA_AnimationData> data = new List<VA_AnimationData>();
 | 
			
		||||
            public List<PlayTextureGroup> textureGroups = new List<PlayTextureGroup>();
 | 
			
		||||
            public List<PlayAnimationPage> animationPages = new List<PlayAnimationPage>();
 | 
			
		||||
 | 
			
		||||
            foreach (var ap in animationPages)
 | 
			
		||||
            {               
 | 
			
		||||
                data.Add(new VA_AnimationData
 | 
			
		||||
                {
 | 
			
		||||
                    name = ap.name,
 | 
			
		||||
                    frames = ap.frames,
 | 
			
		||||
                    maxFrames = maxFrames,
 | 
			
		||||
                    frameTime = 1.0f / maxFrames,
 | 
			
		||||
                    duration = 1.0f / maxFrames * ap.frames,
 | 
			
		||||
                    animationMapIndex = GetFirstAnimationMapIndex(in ap.textures),
 | 
			
		||||
                    colorMapIndex = GetFirstColorMapIndex(in ap.textures)
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
            public int maxFrames;
 | 
			
		||||
            public Material[] materials;
 | 
			
		||||
            public List<Texture2DArray> texture2DArray = new List<Texture2DArray>();
 | 
			
		||||
 | 
			
		||||
            return data;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private int GetFirstAnimationMapIndex(in List<TextureEntry> textures)
 | 
			
		||||
        {
 | 
			
		||||
            for (int i = 0; i < textureGroups.Count; i++)
 | 
			
		||||
            // NOTE: for some reason FixedString32 data gets lost when entering play mode.
 | 
			
		||||
            // That is why this is here... and also the animationPages...
 | 
			
		||||
            public List<VA_AnimationData> GetAnimations
 | 
			
		||||
            {
 | 
			
		||||
                if(textureGroups[i].textureType == TextureType.AnimationMap)
 | 
			
		||||
                get
 | 
			
		||||
                {
 | 
			
		||||
                    return textures[i].textureArrayIndex;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            return -1;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        private int GetFirstColorMapIndex(in List<TextureEntry> textures)
 | 
			
		||||
        {
 | 
			
		||||
            for (int i = 0; i < textureGroups.Count; i++)
 | 
			
		||||
            {
 | 
			
		||||
                if (textureGroups[i].textureType == TextureType.ColorMap)
 | 
			
		||||
                {
 | 
			
		||||
                    return textures[i].textureArrayIndex;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            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)
 | 
			
		||||
                    List<VA_AnimationData> animations = new List<VA_AnimationData>();
 | 
			
		||||
                    foreach (var ap in animationPages)
 | 
			
		||||
                    {
 | 
			
		||||
                        string textureName = ap.textures[0].texture2D.name;
 | 
			
		||||
 | 
			
		||||
                        string[] parts = textureName.Split('_');
 | 
			
		||||
 | 
			
		||||
                        foreach (var p in parts)
 | 
			
		||||
                        animations.Add(new VA_AnimationData
 | 
			
		||||
                        {
 | 
			
		||||
                            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;
 | 
			
		||||
                                }
 | 
			
		||||
                            }
 | 
			
		||||
                        }
 | 
			
		||||
                            name = ap.name,
 | 
			
		||||
                            frames = ap.frames,
 | 
			
		||||
                            maxFrames = maxFrames,
 | 
			
		||||
                            frameTime = 1.0f / maxFrames,
 | 
			
		||||
                            duration = 1.0f / maxFrames * ap.frames,
 | 
			
		||||
                            animationMapIndex = GetFirstAnimationMapIndex(in ap.textures, in textureGroups),
 | 
			
		||||
                            colorMapIndex = GetFirstColorMapIndex(in ap.textures, in textureGroups)
 | 
			
		||||
                        });
 | 
			
		||||
                    }
 | 
			
		||||
                    animationPages[i] = ap;
 | 
			
		||||
                    return animations;
 | 
			
		||||
                }
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public static int GetFirstAnimationMapIndex(in List<PlayTextureEntry> textures, in List<PlayTextureGroup> textureGroups)
 | 
			
		||||
            {
 | 
			
		||||
                for (int i = 0; i < textureGroups.Count; i++)
 | 
			
		||||
                {
 | 
			
		||||
                    if (textureGroups[i].textureType == TextureType.AnimationMap)
 | 
			
		||||
                    {
 | 
			
		||||
                        return textures[i].textureArrayIndex;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
 | 
			
		||||
            public static int GetFirstColorMapIndex(in List<PlayTextureEntry> textures, in List<PlayTextureGroup> textureGroups)
 | 
			
		||||
            {
 | 
			
		||||
                for (int i = 0; i < textureGroups.Count; i++)
 | 
			
		||||
                {
 | 
			
		||||
                    if (textureGroups[i].textureType == TextureType.ColorMap)
 | 
			
		||||
                    {
 | 
			
		||||
                        return textures[i].textureArrayIndex;
 | 
			
		||||
                    }
 | 
			
		||||
                }
 | 
			
		||||
 | 
			
		||||
                return -1;
 | 
			
		||||
            }
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    [System.Serializable]
 | 
			
		||||
    public struct VA_AnimationPage
 | 
			
		||||
    {
 | 
			
		||||
        public string name;
 | 
			
		||||
        public int frames;
 | 
			
		||||
        public List<TextureEntry> textures;
 | 
			
		||||
    }
 | 
			
		||||
        [System.Serializable]
 | 
			
		||||
        public struct PlayAnimationPage
 | 
			
		||||
        {
 | 
			
		||||
            public string name;
 | 
			
		||||
            public int frames;
 | 
			
		||||
            public List<PlayTextureEntry> textures;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    [System.Serializable]
 | 
			
		||||
    public struct TextureGroup
 | 
			
		||||
    {
 | 
			
		||||
        public string shaderParamName;
 | 
			
		||||
        public TextureType textureType;
 | 
			
		||||
        public TextureWrapMode wrapMode;
 | 
			
		||||
        public FilterMode filterMode;
 | 
			
		||||
        public bool isLinear;
 | 
			
		||||
    }
 | 
			
		||||
        [System.Serializable]
 | 
			
		||||
        public struct PlayTextureGroup
 | 
			
		||||
        {
 | 
			
		||||
            public string shaderParamName;
 | 
			
		||||
            public TextureType textureType;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
    [System.Serializable]
 | 
			
		||||
    public class TextureEntry
 | 
			
		||||
    {
 | 
			
		||||
        public Texture2D texture2D = null;
 | 
			
		||||
        public int textureArrayIndex = -1;
 | 
			
		||||
    }
 | 
			
		||||
        [System.Serializable]
 | 
			
		||||
        public struct PlayTextureEntry
 | 
			
		||||
        {
 | 
			
		||||
            public int textureArrayIndex;
 | 
			
		||||
        }
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
    public enum TextureType
 | 
			
		||||
    {
 | 
			
		||||
        AnimationMap,
 | 
			
		||||
        ColorMap
 | 
			
		||||
        #region EditorData
 | 
			
		||||
#if UNITY_EDITOR
 | 
			
		||||
        [System.Serializable]
 | 
			
		||||
        public class EditorData
 | 
			
		||||
        {
 | 
			
		||||
            public List<EditorTextureGroup> textureGroups = new List<EditorTextureGroup>() { new EditorTextureGroup { shaderParamName = "_PositionMap", textureType = TextureType.AnimationMap, wrapMode = TextureWrapMode.Repeat, filterMode = FilterMode.Point, isLinear = false } };
 | 
			
		||||
            public List<EditorAnimationPage> animationPages = new List<EditorAnimationPage>();
 | 
			
		||||
 | 
			
		||||
            public int maxFrames;
 | 
			
		||||
            public Material[] materials;
 | 
			
		||||
            public List<Texture2DArray> texture2DArray = null;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [System.Serializable]
 | 
			
		||||
        public struct EditorAnimationPage
 | 
			
		||||
        {
 | 
			
		||||
            public string name;
 | 
			
		||||
            public int frames;
 | 
			
		||||
            public List<EditorTextureEntry> textures;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [System.Serializable]
 | 
			
		||||
        public struct EditorTextureGroup
 | 
			
		||||
        {
 | 
			
		||||
            public string shaderParamName;
 | 
			
		||||
            public TextureType textureType;
 | 
			
		||||
            public TextureWrapMode wrapMode;
 | 
			
		||||
            public FilterMode filterMode;
 | 
			
		||||
            public bool isLinear;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        [System.Serializable]
 | 
			
		||||
        public class EditorTextureEntry
 | 
			
		||||
        {
 | 
			
		||||
            public Texture2D texture2D = null;
 | 
			
		||||
            public int textureArrayIndex = -1;
 | 
			
		||||
        }
 | 
			
		||||
#endif
 | 
			
		||||
        #endregion
 | 
			
		||||
 | 
			
		||||
        public enum TextureType
 | 
			
		||||
        {
 | 
			
		||||
            AnimationMap,
 | 
			
		||||
            ColorMap
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
@@ -7,37 +7,25 @@ namespace TAO.VertexAnimation
 | 
			
		||||
	public class VA_AnimationLibrary : ScriptableObject
 | 
			
		||||
	{
 | 
			
		||||
		[SerializeField]
 | 
			
		||||
		private VA_AnimationBook[] animationBooks;
 | 
			
		||||
		private List<VA_AnimationBook> animationBooks = new List<VA_AnimationBook>();
 | 
			
		||||
 | 
			
		||||
		[HideInInspector]
 | 
			
		||||
		public List<VA_AnimationData> animations = null;
 | 
			
		||||
 | 
			
		||||
		public void Create()
 | 
			
		||||
		public void Init()
 | 
			
		||||
		{
 | 
			
		||||
			foreach (VA_AnimationBook book in animationBooks)
 | 
			
		||||
			{
 | 
			
		||||
				book.Create();
 | 
			
		||||
			}
 | 
			
		||||
			animations = new List<VA_AnimationData>();
 | 
			
		||||
 | 
			
		||||
			ConvertAnimations();
 | 
			
		||||
			foreach (VA_AnimationBook ab in animationBooks)
 | 
			
		||||
			{
 | 
			
		||||
				ab.SetMaterials();
 | 
			
		||||
				animations.AddRange(ab.playData.GetAnimations);
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private void OnValidate()
 | 
			
		||||
		{
 | 
			
		||||
			// TODO: Check for naming conflicts in AnimationBooks.
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		private void ConvertAnimations()
 | 
			
		||||
		{
 | 
			
		||||
			animations = new List<VA_AnimationData>();
 | 
			
		||||
 | 
			
		||||
			if (animationBooks != null)
 | 
			
		||||
			{
 | 
			
		||||
				foreach (var ab in animationBooks)
 | 
			
		||||
				{
 | 
			
		||||
					animations.AddRange(ab.GetAnimationData());
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
@@ -16,7 +16,7 @@ namespace TAO.VertexAnimation
 | 
			
		||||
		{
 | 
			
		||||
			Entities.ForEach((VA_AnimationLibraryComponentAuthoring animationLib) =>
 | 
			
		||||
			{
 | 
			
		||||
				animationLib.animationLibrary.Create();
 | 
			
		||||
				animationLib.animationLibrary.Init();
 | 
			
		||||
 | 
			
		||||
				// Blob builder to build.
 | 
			
		||||
				using (BlobBuilder blobBuilder = new BlobBuilder(Allocator.Temp))
 | 
			
		||||
 
 | 
			
		||||
@@ -63,7 +63,7 @@ namespace TAO.VertexAnimation
 | 
			
		||||
                if (!a_textures[0].isReadable)
 | 
			
		||||
                {
 | 
			
		||||
#if UNITY_EDITOR
 | 
			
		||||
                    Debug.LogWarning("Texture " + a_textures[i].name + " is not readable!");
 | 
			
		||||
                    //Debug.LogWarning("Texture " + a_textures[i].name + " is not readable!");
 | 
			
		||||
                    return true;
 | 
			
		||||
#else
 | 
			
		||||
                    Debug.LogError("Texture " + a_textures[i].name + " is not readable!");
 | 
			
		||||
 
 | 
			
		||||
@@ -1,5 +1,6 @@
 | 
			
		||||
{
 | 
			
		||||
    "name": "TAO.VertexAnimation",
 | 
			
		||||
    "rootNamespace": "TAO.VertexAnimation",
 | 
			
		||||
    "references": [
 | 
			
		||||
        "GUID:2665a8d13d1b3f18800f46e256720795",
 | 
			
		||||
        "GUID:734d92eba21c94caba915361bd5ac177",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user