2020-12-06 02:36:15 +01:00
|
|
|
|
using Unity.Entities;
|
|
|
|
|
using Unity.Transforms;
|
|
|
|
|
using Unity.Collections;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
namespace TAO.VertexAnimation
|
|
|
|
|
{
|
|
|
|
|
[DisallowMultipleComponent]
|
|
|
|
|
public class VA_AnimatorComponentAuthoring : MonoBehaviour
|
|
|
|
|
{
|
2022-02-19 13:29:16 +01:00
|
|
|
|
public VA_AnimationLibrary lib;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//[GenerateAuthoringComponent]
|
|
|
|
|
public struct VA_AnimatorComponent : IComponentData
|
|
|
|
|
{
|
|
|
|
|
public int animationIndex;
|
2021-02-09 17:21:42 +01:00
|
|
|
|
public int animationIndexNext;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
public float animationTime;
|
2020-12-10 19:51:02 +01:00
|
|
|
|
public BlobAssetReference<VA_AnimationLibraryData> animationLibrary;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
}
|
|
|
|
|
|
2020-12-09 18:36:32 +01:00
|
|
|
|
[UpdateAfter(typeof(VA_AnimationLibraryConversionSystem))]
|
2020-12-06 02:36:15 +01:00
|
|
|
|
public class VA_AnimatorConversionSystem : GameObjectConversionSystem
|
|
|
|
|
{
|
|
|
|
|
protected override void OnUpdate()
|
|
|
|
|
{
|
2021-01-13 10:16:22 +01:00
|
|
|
|
// Static because of multi scene setup.
|
2022-02-19 13:29:16 +01:00
|
|
|
|
//BlobAssetReference<VA_AnimationLibraryData> animLib = VA_AnimationLibraryConversionSystem.animLibAssetRef;
|
2020-12-08 17:36:20 +01:00
|
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
|
Entities.ForEach((VA_AnimatorComponentAuthoring animator) =>
|
|
|
|
|
{
|
2022-02-19 13:29:16 +01:00
|
|
|
|
|
|
|
|
|
BlobAssetStore.TryGet(animator.lib.key, out BlobAssetReference<VA_AnimationLibraryData> animLib);
|
|
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
|
Entity entity = GetPrimaryEntity(animator);
|
2020-12-08 17:36:20 +01:00
|
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
|
// Add animator to 'parent'.
|
|
|
|
|
VA_AnimatorComponent animatorComponent = new VA_AnimatorComponent
|
|
|
|
|
{
|
|
|
|
|
animationIndex = 0,
|
2021-02-09 17:21:42 +01:00
|
|
|
|
animationIndexNext = -1,
|
2020-12-06 02:36:15 +01:00
|
|
|
|
animationTime = 0,
|
2020-12-09 18:36:32 +01:00
|
|
|
|
animationLibrary = animLib
|
2020-12-08 17:36:20 +01:00
|
|
|
|
};
|
2020-12-06 02:36:15 +01:00
|
|
|
|
DstEntityManager.AddComponentData(entity, animatorComponent);
|
|
|
|
|
|
|
|
|
|
// Add the Material data to the children.
|
|
|
|
|
var children = animator.GetComponentsInChildren<MeshRenderer>();
|
|
|
|
|
for (int i = 0; i < children.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
Entity ent = GetPrimaryEntity(children[i]);
|
|
|
|
|
|
2020-12-14 20:27:44 +01:00
|
|
|
|
VA_AnimationDataComponent animationData = new VA_AnimationDataComponent();
|
2021-01-14 00:45:25 +01:00
|
|
|
|
DstEntityManager.AddComponentData(ent, animationData);
|
|
|
|
|
}
|
|
|
|
|
});
|
2020-12-06 02:36:15 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|