Mirror of Svelto.ECS because we're a fan of it
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

38 lines
950B

  1. using System.Runtime.CompilerServices;
  2. using System.Threading;
  3. using Svelto.Common;
  4. using Svelto.ECS.Internal;
  5. namespace Svelto.ECS
  6. {
  7. public static class BurstCompatibleCounter
  8. {
  9. public static int counter;
  10. }
  11. public class ComponentTypeID<T> where T : struct, _IInternalEntityComponent
  12. {
  13. static readonly SharedStaticWrapper<ComponentID, ComponentTypeID<T>> _id;
  14. public static ComponentID id
  15. {
  16. [MethodImpl(MethodImplOptions.AggressiveInlining)]
  17. get => _id.Data;
  18. }
  19. static ComponentTypeID()
  20. {
  21. Init();
  22. }
  23. #if UNITY_BURST
  24. [Unity.Burst.BurstDiscard]
  25. //SharedStatic values must be initialized from not burstified code
  26. #endif
  27. static void Init()
  28. {
  29. _id.Data = Interlocked.Increment(ref BurstCompatibleCounter.counter);
  30. ComponentTypeMap.Add(typeof(T), id);
  31. }
  32. }
  33. }