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; } }