Simplify editor

Animations can now be used by scriptable object reference.
Bake saves book and animations.
Checks to update instead of create+overwrite assets to keep references/configuration.
This commit is contained in:
max
2021-01-19 13:59:31 +01:00
parent 2d6e920017
commit c465ec6585
7 changed files with 169 additions and 87 deletions

View File

@ -6,7 +6,7 @@ namespace TAO.VertexAnimation
{
public static class NamingConventionUtils
{
public struct TextureInfo
public struct PositionMapInfo
{
public string name;
public int frames;
@ -14,9 +14,9 @@ namespace TAO.VertexAnimation
public int fps;
}
public static TextureInfo GetTextureInfo(this string name)
public static PositionMapInfo GetTextureInfo(this string name)
{
TextureInfo textureInfo = new TextureInfo();
PositionMapInfo textureInfo = new PositionMapInfo();
string[] parts = name.Split('_');
foreach (var p in parts)

View File

@ -1,3 +1,4 @@
using Unity.Collections;
using UnityEngine;
namespace TAO.VertexAnimation
@ -26,5 +27,10 @@ namespace TAO.VertexAnimation
a_data.name = this.name;
Data = a_data;
}
public FixedString32 GetName()
{
return Data.name;
}
}
}

View File

@ -21,10 +21,7 @@ namespace TAO.VertexAnimation
}
}
public int MaxFrames
{
get; private set;
}
public int MaxFrames { get; private set; } = 0;
public Texture2DArray positionMap = null;
public List<VA_Animation> animations = new List<VA_Animation>();
@ -34,9 +31,10 @@ namespace TAO.VertexAnimation
{
if (animations != null && animations.Count != 0)
{
if (!animations.Contains(animation) && animation.Data.maxFrames == MaxFrames)
if (!animations.Contains(animation))
{
animations.Add(animation);
OnValidate();
return true;
}
}
@ -45,7 +43,7 @@ namespace TAO.VertexAnimation
// Add first animation.
animations.Add(animation);
// Set maxFrames for this animation book.
MaxFrames = animations[0].Data.maxFrames;
OnValidate();
return true;
}
@ -67,16 +65,10 @@ namespace TAO.VertexAnimation
return false;
}
public void RemoveAnimation(VA_Animation animation)
public void UpdateMaterials()
{
if (animations != null)
{
animations.Remove(animation);
}
}
OnValidate();
public void SetMaterials()
{
if (materials != null)
{
foreach (var mat in materials)
@ -97,8 +89,21 @@ namespace TAO.VertexAnimation
}
}
private void UpdateMaxFrames()
{
if (animations != null && animations.Count != 0)
{
if (animations[0] != null)
{
MaxFrames = animations[0].Data.maxFrames;
}
}
}
private void OnValidate()
{
UpdateMaxFrames();
if (animations != null)
{
foreach (var a in animations)
@ -115,7 +120,7 @@ namespace TAO.VertexAnimation
if (positionMap != null)
{
if (positionMap.depth > animations.Count)
if (positionMap.depth < animations.Count)
{
Debug.LogWarning(string.Format("More animations ({0}) than positionMaps in {1}!", animations.Count, this.name));
}

View File

@ -1,4 +1,5 @@
using System.Collections.Generic;
using Unity.Collections;
using UnityEngine;
namespace TAO.VertexAnimation
@ -12,24 +13,58 @@ namespace TAO.VertexAnimation
[HideInInspector]
public List<VA_AnimationData> animationData = null;
#if UNITY_EDITOR
[SerializeField]
private List<VA_Animation> loadedAnimationsPreview = null;
#endif
public void Init()
{
animationData = new List<VA_AnimationData>();
foreach (VA_AnimationBook book in animationBooks)
{
book.SetMaterials();
book.UpdateMaterials();
foreach (VA_Animation animation in book.animations)
if (book != null)
{
animationData.Add(animation.Data);
foreach (VA_Animation animation in book.animations)
{
animationData.Add(animation.Data);
}
}
}
}
private void OnValidate()
{
// TODO: Check for naming conflicts in AnimationBooks.
Dictionary<string, VA_Animation> usedNames = new Dictionary<string, VA_Animation>();
foreach (VA_AnimationBook book in animationBooks)
{
if (book != null)
{
foreach (VA_Animation animation in book.animations)
{
if (!usedNames.ContainsKey(animation.name))
{
usedNames.Add(animation.name, animation);
}
else
{
Debug.LogWarning(string.Format("Naming conflict found in {0} - Animation {1} and {2} have the same name!", name, usedNames[animation.name].name, animation.name));
}
}
}
}
#if UNITY_EDITOR
loadedAnimationsPreview = new List<VA_Animation>();
foreach (var un in usedNames)
{
loadedAnimationsPreview.Add(un.Value);
}
#endif
}
}
}