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.

70 lines
2.1KB

  1. using Svelto.ECS;
  2. #if DEBUG
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Reflection;
  6. public static class ExclusiveGroupDebugger
  7. {
  8. static ExclusiveGroupDebugger()
  9. {
  10. Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
  11. foreach (Assembly assembly in assemblies)
  12. {
  13. Type[] types = assembly.GetTypes();
  14. foreach (Type type in types)
  15. {
  16. if (type != null && type.IsClass && type.IsSealed && type.IsAbstract) //this means only static classes
  17. {
  18. var fields = type.GetFields();
  19. foreach (var field in fields)
  20. {
  21. if (field.IsStatic && typeof(ExclusiveGroup).IsAssignableFrom(field.FieldType))
  22. {
  23. var group = (ExclusiveGroup) field.GetValue(null);
  24. string name = $"{type.FullName}.{field.Name} ({(uint)group})";
  25. GroupMap.idToName[(ExclusiveGroupStruct) group] = name;
  26. }
  27. if (field.IsStatic && typeof(ExclusiveGroupStruct).IsAssignableFrom(field.FieldType))
  28. {
  29. var group = (ExclusiveGroupStruct) field.GetValue(null);
  30. string name = $"{type.FullName}.{field.Name} ({(uint)group})";
  31. GroupMap.idToName[@group] = name;
  32. }
  33. }
  34. }
  35. }
  36. }
  37. }
  38. public static string ToName(this in ExclusiveGroupStruct group)
  39. {
  40. if (GroupMap.idToName.TryGetValue(group, out var name) == false)
  41. name = $"<undefined:{((uint)group).ToString()}>";
  42. return name;
  43. }
  44. }
  45. public static class GroupMap
  46. {
  47. static GroupMap()
  48. {
  49. GroupMap.idToName = new Dictionary<uint, string>();
  50. }
  51. internal static readonly Dictionary<uint, string> idToName;
  52. }
  53. #else
  54. public static class ExclusiveGroupDebugger
  55. {
  56. public static string ToName(this in ExclusiveGroupStruct group)
  57. {
  58. return ((uint)group).ToString();
  59. }
  60. }
  61. #endif