2020-12-06 02:36:15 +01:00
|
|
|
|
using Unity.Collections;
|
|
|
|
|
using Unity.Entities;
|
|
|
|
|
using Unity.Rendering;
|
|
|
|
|
using Unity.Transforms;
|
2020-12-08 17:36:20 +01:00
|
|
|
|
using Unity.Mathematics;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
|
|
|
|
namespace TAO.VertexAnimation
|
|
|
|
|
{
|
2020-12-08 00:33:06 +01:00
|
|
|
|
//TODO: SetComponent.
|
|
|
|
|
//TODO: Disable thread safety.
|
|
|
|
|
//TODO: Blob data for static animation data.
|
|
|
|
|
|
|
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
|
//public class VA_AnimatorSystem : SystemBase
|
|
|
|
|
//{
|
2020-12-08 00:33:06 +01:00
|
|
|
|
// private EndSimulationEntityCommandBufferSystem endSimulationEntityCommandBufferSystem;
|
|
|
|
|
|
|
|
|
|
// protected override void OnCreate()
|
|
|
|
|
// {
|
|
|
|
|
// base.OnCreate();
|
|
|
|
|
|
|
|
|
|
// endSimulationEntityCommandBufferSystem = World.GetExistingSystem<EndSimulationEntityCommandBufferSystem>();
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
// protected override void OnUpdate()
|
|
|
|
|
// {
|
|
|
|
|
// var ecb = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter();
|
|
|
|
|
|
|
|
|
|
// Entities.ForEach((Entity entity, int entityInQueryIndex, in VA_AnimatorComponent ac, in DynamicBuffer<Child> children) =>
|
|
|
|
|
// {
|
|
|
|
|
// for (int i = 0; i < children.Length; i++)
|
|
|
|
|
// {
|
|
|
|
|
// // Get child.
|
|
|
|
|
// Entity child = children[i].Value;
|
|
|
|
|
|
|
|
|
|
// // Overwrite existing component.
|
|
|
|
|
// ecb.AddComponent(entityInQueryIndex, child, new VA_AnimationTimeComponent { Value = ac.animationTime });
|
|
|
|
|
// ecb.AddComponent(entityInQueryIndex, child, new VA_AnimationIndexComponent { Value = ac.animationIndex });
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// .ScheduleParallel();
|
|
|
|
|
|
|
|
|
|
// endSimulationEntityCommandBufferSystem.AddJobHandleForProducer(Dependency);
|
|
|
|
|
// }
|
2020-12-06 02:36:15 +01:00
|
|
|
|
//}
|
2020-12-08 00:33:06 +01:00
|
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
|
//[UpdateBefore(typeof(HybridRendererSystem))]
|
|
|
|
|
public class VA_AnimatorSystem : SystemBase
|
|
|
|
|
{
|
|
|
|
|
protected override void OnUpdate()
|
|
|
|
|
{
|
|
|
|
|
var atc = GetComponentDataFromEntity<VA_AnimationTimeComponent>(false);
|
2020-12-08 00:33:06 +01:00
|
|
|
|
var aic = GetComponentDataFromEntity<VA_AnimationIndexComponent>(false);
|
|
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
|
Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer<Child> children) =>
|
2020-12-08 00:33:06 +01:00
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < children.Length; i++)
|
|
|
|
|
{
|
|
|
|
|
// Get child.
|
|
|
|
|
Entity child = children[i].Value;
|
|
|
|
|
|
|
|
|
|
// Get a copy of the time Component of the child.
|
|
|
|
|
VA_AnimationTimeComponent atcCopy = atc[child];
|
|
|
|
|
// Set new value.
|
|
|
|
|
atcCopy.Value = ac.animationTime;
|
|
|
|
|
// Update original.
|
|
|
|
|
atc[child] = atcCopy;
|
|
|
|
|
|
|
|
|
|
VA_AnimationIndexComponent aicCopy = aic[child];
|
|
|
|
|
aicCopy.Value = ac.animationIndex;
|
|
|
|
|
aic[child] = aicCopy;
|
|
|
|
|
}
|
|
|
|
|
})
|
|
|
|
|
.Run();
|
|
|
|
|
}
|
2020-12-06 02:36:15 +01:00
|
|
|
|
}
|
2020-12-08 00:33:06 +01:00
|
|
|
|
|
2020-12-08 17:36:20 +01:00
|
|
|
|
//public class VA_AnimatorSystem2 : SystemBase
|
|
|
|
|
//{
|
|
|
|
|
// protected override void OnCreate()
|
|
|
|
|
// {
|
|
|
|
|
// base.OnCreate();
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
2020-12-08 17:36:20 +01:00
|
|
|
|
// Enabled = false;
|
|
|
|
|
// }
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
2020-12-08 17:36:20 +01:00
|
|
|
|
// protected override void OnUpdate()
|
|
|
|
|
// {
|
|
|
|
|
// Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer<Child> children) =>
|
|
|
|
|
// {
|
|
|
|
|
// for (int i = 0; i < children.Length; i++)
|
|
|
|
|
// {
|
|
|
|
|
// // Get child.
|
|
|
|
|
// Entity child = children[i].Value;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
2020-12-08 17:36:20 +01:00
|
|
|
|
// //if(HasComponent<VA_AnimationTimeComponent>(child))
|
|
|
|
|
// //{
|
|
|
|
|
// var atc = GetComponent<VA_AnimationTimeComponent>(child);
|
|
|
|
|
// atc.Value = ac.animationTime;
|
|
|
|
|
// SetComponent(child, atc);
|
|
|
|
|
// //}
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
2020-12-08 17:36:20 +01:00
|
|
|
|
// //if(HasComponent<VA_AnimationIndexComponent>(child))
|
|
|
|
|
// //{
|
|
|
|
|
// var aic = GetComponent<VA_AnimationIndexComponent>(child);
|
|
|
|
|
// aic.Value = ac.animationIndex;
|
|
|
|
|
// SetComponent(child, aic);
|
|
|
|
|
// //}
|
|
|
|
|
// }
|
|
|
|
|
// })
|
|
|
|
|
// .Run();
|
|
|
|
|
// }
|
|
|
|
|
//}
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
|
|
|
|
[UpdateBefore(typeof(VA_AnimatorSystem))]
|
|
|
|
|
public class VA_AnimationTimeSystem : SystemBase
|
|
|
|
|
{
|
|
|
|
|
protected override void OnUpdate()
|
|
|
|
|
{
|
2020-12-08 17:36:20 +01:00
|
|
|
|
float deltaTime = UnityEngine.Time.deltaTime;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
|
|
|
|
|
Entities.ForEach((ref VA_AnimatorComponent ac) =>
|
|
|
|
|
{
|
2020-12-08 17:36:20 +01:00
|
|
|
|
// Get the animation lib data.
|
|
|
|
|
ref VA_AnimationDataBlobAsset animationsRef = ref ac.animationsRef.Value;
|
|
|
|
|
int aFrames = animationsRef.animations[ac.animationIndex].frames;
|
|
|
|
|
int aMaxFrames = animationsRef.animations[ac.animationIndex].maxFrames;
|
|
|
|
|
|
|
|
|
|
ac.animationTime += deltaTime;
|
|
|
|
|
|
|
|
|
|
// Time per frame.
|
|
|
|
|
float fTime = 1.0f / aMaxFrames;
|
|
|
|
|
// Animation time.
|
|
|
|
|
float cTime = fTime * (aFrames);
|
|
|
|
|
|
|
|
|
|
if (ac.animationTime > cTime)
|
|
|
|
|
{
|
|
|
|
|
ac.animationTime = ac.animationTime - cTime;
|
|
|
|
|
}
|
|
|
|
|
|
2020-12-06 02:36:15 +01:00
|
|
|
|
}).ScheduleParallel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[UpdateBefore(typeof(VA_AnimatorSystem))]
|
|
|
|
|
public class VA_AnimationIndexSystem : SystemBase
|
|
|
|
|
{
|
|
|
|
|
protected override void OnUpdate()
|
|
|
|
|
{
|
|
|
|
|
Entities.ForEach((Entity entity, ref VA_AnimatorComponent ac) =>
|
|
|
|
|
{
|
2020-12-08 00:33:06 +01:00
|
|
|
|
//int index = entity.Index % 2;
|
|
|
|
|
//ac.animationIndex = index;
|
|
|
|
|
ac.animationIndex = 0;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
}).ScheduleParallel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|