2020-12-21 23:19:05 +01:00
|
|
|
|
using System.Collections.Generic;
|
2020-12-10 19:51:02 +01:00
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace TAO.VertexAnimation
|
|
|
|
|
{
|
2020-12-16 11:59:22 +01:00
|
|
|
|
[CreateAssetMenu(fileName = "new AnimationBook", menuName = "VA_Animation/AnimationBook", order = 400)]
|
2020-12-10 19:51:02 +01:00
|
|
|
|
public class VA_AnimationBook : ScriptableObject
|
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public PlayData playData = null;
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
public EditorData editorData = new EditorData();
|
|
|
|
|
#endif
|
2020-12-14 20:27:44 +01:00
|
|
|
|
|
|
|
|
|
private void OnValidate()
|
|
|
|
|
{
|
|
|
|
|
// TODO: Check for naming conflicts and textures.
|
|
|
|
|
// TODO: Debug message box instead of debug logs.
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public void SetMaterials()
|
2020-12-14 20:27:44 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
if (playData.materials != null)
|
2020-12-14 20:27:44 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
foreach (Material mat in playData.materials)
|
2020-12-14 20:27:44 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
if (mat != null)
|
2020-12-14 20:27:44 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
if (mat.HasProperty("_MaxFrames"))
|
|
|
|
|
{
|
|
|
|
|
mat.SetFloat("_MaxFrames", playData.maxFrames);
|
|
|
|
|
}
|
2020-12-14 20:27:44 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
for (int i = 0; i < playData.texture2DArray.Count; i++)
|
|
|
|
|
{
|
|
|
|
|
if (mat.HasProperty(playData.textureGroups[i].shaderParamName))
|
|
|
|
|
{
|
|
|
|
|
mat.SetTexture(playData.textureGroups[i].shaderParamName, playData.texture2DArray[i]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 20:27:44 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
#region PlayData
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class PlayData
|
2020-12-14 20:27:44 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public List<PlayTextureGroup> textureGroups = new List<PlayTextureGroup>();
|
|
|
|
|
public List<PlayAnimationPage> animationPages = new List<PlayAnimationPage>();
|
2020-12-14 20:27:44 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public int maxFrames;
|
|
|
|
|
public Material[] materials;
|
|
|
|
|
public List<Texture2DArray> texture2DArray = new List<Texture2DArray>();
|
2020-12-14 20:27:44 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
// 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
|
2020-12-10 19:51:02 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
get
|
2020-12-10 19:51:02 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
List<VA_AnimationData> animations = new List<VA_AnimationData>();
|
|
|
|
|
foreach (var ap in animationPages)
|
|
|
|
|
{
|
|
|
|
|
animations.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, in textureGroups),
|
|
|
|
|
colorMapIndex = GetFirstColorMapIndex(in ap.textures, in textureGroups)
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
return animations;
|
2020-12-10 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-14 20:27:44 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public static int GetFirstAnimationMapIndex(in List<PlayTextureEntry> textures, in List<PlayTextureGroup> textureGroups)
|
2020-12-14 20:27:44 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
for (int i = 0; i < textureGroups.Count; i++)
|
2020-12-14 20:27:44 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
if (textureGroups[i].textureType == TextureType.AnimationMap)
|
|
|
|
|
{
|
|
|
|
|
return textures[i].textureArrayIndex;
|
|
|
|
|
}
|
2020-12-14 20:27:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
return -1;
|
|
|
|
|
}
|
2020-12-14 20:27:44 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public static int GetFirstColorMapIndex(in List<PlayTextureEntry> textures, in List<PlayTextureGroup> textureGroups)
|
2020-12-10 19:51:02 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
for (int i = 0; i < textureGroups.Count; i++)
|
2020-12-10 19:51:02 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
if (textureGroups[i].textureType == TextureType.ColorMap)
|
2020-12-10 19:51:02 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
return textures[i].textureArrayIndex;
|
2020-12-10 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
2020-12-21 23:19:05 +01:00
|
|
|
|
|
|
|
|
|
return -1;
|
2020-12-10 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public struct PlayAnimationPage
|
2020-12-10 19:51:02 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public string name;
|
|
|
|
|
public int frames;
|
|
|
|
|
public List<PlayTextureEntry> textures;
|
2020-12-10 19:51:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public struct PlayTextureGroup
|
2020-12-10 19:51:02 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public string shaderParamName;
|
|
|
|
|
public TextureType textureType;
|
2020-12-14 20:27:44 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public struct PlayTextureEntry
|
2020-12-14 20:27:44 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public int textureArrayIndex;
|
2020-12-10 19:51:02 +01:00
|
|
|
|
}
|
2020-12-21 23:19:05 +01:00
|
|
|
|
#endregion
|
2020-12-16 11:59:22 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
#region EditorData
|
|
|
|
|
#if UNITY_EDITOR
|
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class EditorData
|
2020-12-16 11:59:22 +01:00
|
|
|
|
{
|
2020-12-21 23:19:05 +01:00
|
|
|
|
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>();
|
2020-12-16 11:59:22 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public int maxFrames;
|
|
|
|
|
public Material[] materials;
|
|
|
|
|
public List<Texture2DArray> texture2DArray = null;
|
2020-12-16 11:59:22 +01:00
|
|
|
|
}
|
2020-12-10 19:51:02 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public struct EditorAnimationPage
|
|
|
|
|
{
|
|
|
|
|
public string name;
|
|
|
|
|
public int frames;
|
|
|
|
|
public List<EditorTextureEntry> textures;
|
|
|
|
|
}
|
2020-12-10 19:51:02 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public struct EditorTextureGroup
|
|
|
|
|
{
|
|
|
|
|
public string shaderParamName;
|
|
|
|
|
public TextureType textureType;
|
|
|
|
|
public TextureWrapMode wrapMode;
|
|
|
|
|
public FilterMode filterMode;
|
|
|
|
|
public bool isLinear;
|
|
|
|
|
}
|
2020-12-14 20:27:44 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
[System.Serializable]
|
|
|
|
|
public class EditorTextureEntry
|
|
|
|
|
{
|
|
|
|
|
public Texture2D texture2D = null;
|
|
|
|
|
public int textureArrayIndex = -1;
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endregion
|
2020-12-14 20:27:44 +01:00
|
|
|
|
|
2020-12-21 23:19:05 +01:00
|
|
|
|
public enum TextureType
|
|
|
|
|
{
|
|
|
|
|
AnimationMap,
|
|
|
|
|
ColorMap
|
|
|
|
|
}
|
2020-12-14 20:27:44 +01:00
|
|
|
|
}
|
2020-12-10 19:51:02 +01:00
|
|
|
|
}
|