2020-12-10 19:51:02 +01:00
using System.Collections.Generic ;
2021-01-19 13:59:31 +01:00
using Unity.Collections ;
2020-12-10 19:51:02 +01:00
using UnityEngine ;
2020-12-08 17:36:20 +01:00
namespace TAO.VertexAnimation
{
2021-01-18 13:42:45 +01:00
[CreateAssetMenu(fileName = "new AnimationLibrary", menuName = "TAO/VertexAnimation/AnimationLibrary", order = 400)]
2022-12-10 15:02:53 +01:00
public class AnimationLibrary : ScriptableObject
2020-12-08 17:36:20 +01:00
{
2020-12-10 19:51:02 +01:00
[SerializeField]
2022-12-10 15:02:53 +01:00
private List < AnimationBook > animationBooks = new List < AnimationBook > ( ) ;
2020-12-08 17:36:20 +01:00
2020-12-10 19:51:02 +01:00
[HideInInspector]
2021-01-19 01:18:25 +01:00
public List < VA_AnimationData > animationData = null ;
2020-12-10 19:51:02 +01:00
2021-01-19 13:59:31 +01:00
#if UNITY_EDITOR
[SerializeField]
2022-12-10 15:02:53 +01:00
private List < Animation > loadedAnimationsPreview = null ;
2021-01-19 13:59:31 +01:00
#endif
2020-12-21 23:19:05 +01:00
public void Init ( )
2020-12-10 19:51:02 +01:00
{
2021-01-19 01:18:25 +01:00
animationData = new List < VA_AnimationData > ( ) ;
2020-12-21 23:19:05 +01:00
2022-12-10 15:02:53 +01:00
foreach ( AnimationBook book in animationBooks )
2020-12-10 19:51:02 +01:00
{
2021-01-19 13:59:31 +01:00
book . UpdateMaterials ( ) ;
2021-01-19 01:18:25 +01:00
2021-01-19 13:59:31 +01:00
if ( book ! = null )
2021-01-19 01:18:25 +01:00
{
2022-12-10 15:02:53 +01:00
foreach ( Animation animation in book . animations )
2021-01-19 13:59:31 +01:00
{
2021-01-19 15:23:52 +01:00
// TODO: Fix data name, FixedString32 doesn't transfer from editor?
//animation.Data.name = new FixedString32(animation.name);
animationData . Add ( animation . GetData ( ) ) ;
2021-01-19 13:59:31 +01:00
}
2021-01-19 01:18:25 +01:00
}
2020-12-10 19:51:02 +01:00
}
}
2021-01-21 11:06:58 +01:00
public void OnValidate ( )
2020-12-10 19:51:02 +01:00
{
2022-12-10 15:02:53 +01:00
Dictionary < string , Animation > usedNames = new Dictionary < string , Animation > ( ) ;
2021-01-19 13:59:31 +01:00
2022-12-10 15:02:53 +01:00
foreach ( AnimationBook book in animationBooks )
2021-01-19 13:59:31 +01:00
{
if ( book ! = null )
{
2022-12-10 15:02:53 +01:00
foreach ( Animation animation in book . animations )
2021-01-19 13:59:31 +01:00
{
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
2022-12-10 15:02:53 +01:00
loadedAnimationsPreview = new List < Animation > ( ) ;
2021-01-19 13:59:31 +01:00
foreach ( var un in usedNames )
{
loadedAnimationsPreview . Add ( un . Value ) ;
}
#endif
2020-12-10 19:51:02 +01:00
}
2020-12-08 17:36:20 +01:00
}
}