GpuEcsAttachmentSystem.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. using Unity.Burst;
  2. using Unity.Collections;
  3. using Unity.Entities;
  4. using Unity.Transforms;
  5. namespace GPUECSAnimationBaker.Engine.AnimatorSystem
  6. {
  7. [BurstCompile]
  8. public partial struct GpuEcsAttachmentSystem : ISystem
  9. {
  10. private BufferLookup<GpuEcsCurrentAttachmentAnchorBufferElement> gpuEcsCurrentAttachmentAnchorLookup;
  11. [BurstCompile]
  12. public void OnCreate(ref SystemState state)
  13. {
  14. gpuEcsCurrentAttachmentAnchorLookup = state.GetBufferLookup<GpuEcsCurrentAttachmentAnchorBufferElement>(isReadOnly: true);
  15. }
  16. [BurstCompile]
  17. public void OnUpdate(ref SystemState state)
  18. {
  19. gpuEcsCurrentAttachmentAnchorLookup.Update(ref state);
  20. state.Dependency = new GpuEcsAttachmentJob()
  21. {
  22. gpuEcsCurrentAttachmentAnchorLookup = gpuEcsCurrentAttachmentAnchorLookup
  23. }.ScheduleParallel(state.Dependency);
  24. }
  25. [BurstCompile]
  26. private partial struct GpuEcsAttachmentJob : IJobEntity
  27. {
  28. [ReadOnly] public BufferLookup<GpuEcsCurrentAttachmentAnchorBufferElement> gpuEcsCurrentAttachmentAnchorLookup;
  29. public void Execute(ref LocalTransform localTransform, in GpuEcsAttachmentComponent gpuEcsAttachment)
  30. {
  31. DynamicBuffer<GpuEcsCurrentAttachmentAnchorBufferElement> currentAttachmentAnchors
  32. = gpuEcsCurrentAttachmentAnchorLookup[gpuEcsAttachment.gpuEcsAnimatorEntity];
  33. GpuEcsCurrentAttachmentAnchorBufferElement currentAnchor = currentAttachmentAnchors[gpuEcsAttachment.attachmentAnchorId];
  34. localTransform = LocalTransform.FromMatrix(currentAnchor.currentTransform);
  35. }
  36. }
  37. }
  38. }