AttachmentManagerBehaviour.cs 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. using System;
  2. using GPUECSAnimationBaker.Engine.AnimatorSystem;
  3. using Unity.Entities;
  4. using UnityEngine;
  5. namespace GPUECSAnimationBaker.Samples.SampleScenes._5_Attachments
  6. {
  7. public class AttachmentManagerBehaviour : MonoBehaviour
  8. {
  9. public AttachmentPrefabInfo[] attachmentPrefabs;
  10. }
  11. [Serializable]
  12. public class AttachmentPrefabInfo
  13. {
  14. public AnchorIdsMariaAttachments anchor;
  15. public GameObject attachmentPrefab;
  16. }
  17. public class AttachmentManagerBaker : Baker<AttachmentManagerBehaviour>
  18. {
  19. public override void Bake(AttachmentManagerBehaviour authoring)
  20. {
  21. Entity entity = GetEntity(TransformUsageFlags.None);
  22. DynamicBuffer<AttachmentPrefabBufferElement> attachmentPrefabBuffer = AddBuffer<AttachmentPrefabBufferElement>(entity);
  23. for (int prefabIndex = 0; prefabIndex < authoring.attachmentPrefabs.Length; prefabIndex++)
  24. {
  25. AttachmentPrefabInfo attachmentPrefabInfo = authoring.attachmentPrefabs[prefabIndex];
  26. attachmentPrefabBuffer.Add(new AttachmentPrefabBufferElement()
  27. {
  28. anchor = attachmentPrefabInfo.anchor,
  29. attachmentPrefab = GetEntity(attachmentPrefabInfo.attachmentPrefab, TransformUsageFlags.Dynamic)
  30. });
  31. }
  32. }
  33. }
  34. }