BurstChecker.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. #if ENABLE_MONO && (DEVELOPMENT_BUILD || UNITY_EDITOR)
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Reflection;
  5. namespace SingularityGroup.HotReload {
  6. static class BurstChecker {
  7. //Use names instead of the types directly for compat with older unity versions
  8. const string whitelistAttrName = "BurstCompileAttribute";
  9. const string blacklistAttrName = "BurstDiscardAttribute";
  10. public static bool IsBurstCompiled(MethodBase method) {
  11. //blacklist has precedence over whitelist
  12. if(HasAttr(method.GetCustomAttributes(), blacklistAttrName)) {
  13. return false;
  14. }
  15. if(HasAttr(method.GetCustomAttributes(), whitelistAttrName)) {
  16. return true;
  17. }
  18. //Static methods inside a [BurstCompile] type are not burst compiled by default
  19. if(method.DeclaringType == null || method.IsStatic) {
  20. return false;
  21. }
  22. if(HasAttr(method.DeclaringType.GetCustomAttributes(), whitelistAttrName)) {
  23. return true;
  24. }
  25. //No matching attributes
  26. return false;
  27. }
  28. static bool HasAttr(IEnumerable<Attribute> attributes, string name) {
  29. foreach (var attr in attributes) {
  30. if(attr.GetType().Name == name) {
  31. return true;
  32. }
  33. }
  34. return false;
  35. }
  36. }
  37. }
  38. #endif