using Unity.Collections; using Unity.Entities; using Unity.Rendering; using Unity.Transforms; using UnityEngine; namespace TAO.VertexAnimation { //public class VA_AnimatorSystem : SystemBase //{ // private EndSimulationEntityCommandBufferSystem endSimulationEntityCommandBufferSystem; // protected override void OnCreate() // { // base.OnCreate(); // endSimulationEntityCommandBufferSystem = World.GetExistingSystem(); // } // protected override void OnUpdate() // { // var ecb = endSimulationEntityCommandBufferSystem.CreateCommandBuffer().AsParallelWriter(); // Entities.ForEach((Entity entity, int entityInQueryIndex, in VA_AnimatorComponent ac, in DynamicBuffer 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); // } //} //[UpdateBefore(typeof(HybridRendererSystem))] public class VA_AnimatorSystem : SystemBase { protected override void OnUpdate() { var atc = GetComponentDataFromEntity(false); var aic = GetComponentDataFromEntity(false); Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer children) => { 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(); } } public class VA_AnimatorSystem2 : SystemBase { protected override void OnCreate() { base.OnCreate(); Enabled = false; } protected override void OnUpdate() { Entities.ForEach((ref VA_AnimatorComponent ac, in DynamicBuffer children) => { for (int i = 0; i < children.Length; i++) { // Get child. Entity child = children[i].Value; //if(HasComponent(child)) //{ var atc = GetComponent(child); atc.Value = ac.animationTime; SetComponent(child, atc); //} //if(HasComponent(child)) //{ var aic = GetComponent(child); aic.Value = ac.animationIndex; SetComponent(child, aic); //} } }) .Run(); } } [UpdateBefore(typeof(VA_AnimatorSystem))] public class VA_AnimationTimeSystem : SystemBase { protected override void OnUpdate() { float time = UnityEngine.Time.deltaTime; Entities.ForEach((ref VA_AnimatorComponent ac) => { ac.animationTime += time; }).ScheduleParallel(); } } [UpdateBefore(typeof(VA_AnimatorSystem))] public class VA_AnimationIndexSystem : SystemBase { protected override void OnUpdate() { Entities.ForEach((Entity entity, ref VA_AnimatorComponent ac) => { int index = entity.Index % 2; ac.animationIndex = index; }).ScheduleParallel(); } } }