Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
796B

  1. using Svelto.DataStructures;
  2. namespace Svelto.ECS.ResourceManager
  3. {
  4. /// <summary>
  5. /// To do. Or we reuse the ID or we need to clear this
  6. /// </summary>
  7. /// <typeparam name="T"></typeparam>
  8. static class ResourcesECSDB<T>
  9. {
  10. static readonly FasterList<T> _resources = new FasterList<T>();
  11. internal static ref T resources(uint id)
  12. {
  13. return ref _resources[(int) id - 1];
  14. }
  15. internal static uint ToECS(in T resource)
  16. {
  17. _resources.Add(resource);
  18. return (uint)_resources.count;
  19. }
  20. public static T FromECS(uint id)
  21. {
  22. if (id - 1 < _resources.count)
  23. return _resources[(int) id - 1];
  24. return default;
  25. }
  26. }
  27. }