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
|
|
|
|
|
{
|
|
|
|
|
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;
|
|
|
|
|
|
2020-12-09 18:36:32 +01:00
|
|
|
|
atc[child] = new VA_AnimationTimeComponent { Value = ac.animationTime };
|
2020-12-08 00:33:06 +01:00
|
|
|
|
|
2020-12-09 18:36:32 +01:00
|
|
|
|
//// 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;
|
|
|
|
|
|
|
|
|
|
aic[child] = new VA_AnimationIndexComponent { Value = ac.animationIndex };
|
|
|
|
|
|
|
|
|
|
//VA_AnimationIndexComponent aicCopy = aic[child];
|
|
|
|
|
//aicCopy.Value = ac.animationIndex;
|
|
|
|
|
//aic[child] = aicCopy;
|
2020-12-08 00:33:06 +01:00
|
|
|
|
}
|
|
|
|
|
})
|
2020-12-09 18:36:32 +01:00
|
|
|
|
.WithNativeDisableContainerSafetyRestriction(atc)
|
|
|
|
|
.WithNativeDisableContainerSafetyRestriction(aic)
|
|
|
|
|
.ScheduleParallel();
|
2020-12-08 00:33:06 +01:00
|
|
|
|
}
|
2020-12-06 02:36:15 +01:00
|
|
|
|
}
|
2020-12-08 00:33:06 +01:00
|
|
|
|
|
2020-12-09 18:36:32 +01:00
|
|
|
|
// Example systems to update animation parameters.
|
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.
|
2020-12-09 18:36:32 +01:00
|
|
|
|
ref VA_AnimationLibrary animationsRef = ref ac.animationLibrary.Value;
|
2020-12-08 17:36:20 +01:00
|
|
|
|
|
|
|
|
|
ac.animationTime += deltaTime;
|
|
|
|
|
|
2020-12-09 18:36:32 +01:00
|
|
|
|
if (ac.animationTime > animationsRef.animations[ac.animationIndex].duration)
|
2020-12-08 17:36:20 +01:00
|
|
|
|
{
|
2020-12-09 18:36:32 +01:00
|
|
|
|
ac.animationTime = ac.animationTime - animationsRef.animations[ac.animationIndex].duration;
|
2020-12-08 17:36:20 +01:00
|
|
|
|
}
|
|
|
|
|
|
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-09 18:36:32 +01:00
|
|
|
|
// Get the animation lib data.
|
|
|
|
|
ref VA_AnimationLibrary animationLib = ref ac.animationLibrary.Value;
|
|
|
|
|
|
|
|
|
|
int animationIndex = VA_AnimationLibraryUtils.GetAnimation(ref animationLib, "Shoot");
|
|
|
|
|
|
|
|
|
|
//int index = entity.Index % 2;
|
|
|
|
|
//ac.animationIndex = index;
|
|
|
|
|
ac.animationIndex = animationIndex;
|
2020-12-06 02:36:15 +01:00
|
|
|
|
}).ScheduleParallel();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|