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.

40 lines
1.3KB

  1. namespace Svelto.ECS.Internal
  2. {
  3. delegate void SetEGIDWithoutBoxingActionCast<T>(ref T target, EGID egid) where T : struct, IEntityComponent;
  4. static class SetEGIDWithoutBoxing<T> where T : struct, IEntityComponent
  5. {
  6. public static readonly SetEGIDWithoutBoxingActionCast<T> SetIDWithoutBoxing = MakeSetter();
  7. public static void Warmup() { }
  8. static SetEGIDWithoutBoxingActionCast<T> MakeSetter()
  9. {
  10. if (ComponentBuilder<T>.HAS_EGID)
  11. {
  12. #if !ENABLE_IL2CPP
  13. var method = typeof(Trick).GetMethod(nameof(Trick.SetEGIDImpl)).MakeGenericMethod(typeof(T));
  14. return (SetEGIDWithoutBoxingActionCast<T>) System.Delegate.CreateDelegate(
  15. typeof(SetEGIDWithoutBoxingActionCast<T>), method);
  16. #else
  17. return (ref T target, EGID egid) =>
  18. {
  19. var needEgid = (target as INeedEGID);
  20. needEgid.ID = egid;
  21. target = (T) needEgid;
  22. };
  23. #endif
  24. }
  25. return null;
  26. }
  27. static class Trick
  28. {
  29. public static void SetEGIDImpl<U>(ref U target, EGID egid) where U : struct, INeedEGID
  30. {
  31. target.ID = egid;
  32. }
  33. }
  34. }
  35. }