Features.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System;
  2. using System.Linq;
  3. using System.Text;
  4. using XUnity.AutoTranslator.Plugin.Core.Constants;
  5. namespace XUnity.AutoTranslator.Plugin.Core
  6. {
  7. /// <summary>
  8. /// Class that allows you to check which features are availble of the Unity version that is used.
  9. /// </summary>
  10. public static class Features
  11. {
  12. internal static bool SupportsClipboard { get; } = false;
  13. /// <summary>
  14. /// Gets a bool indicating if the class CustomYieldInstruction is available.
  15. /// </summary>
  16. public static bool SupportsCustomYieldInstruction { get; } = false;
  17. /// <summary>
  18. /// Gets a bool indicating if the SceneManager class is available.
  19. /// </summary>
  20. public static bool SupportsSceneManager { get; } = false;
  21. /// <summary>
  22. /// Gets a bool indicating if this game is running in a .NET 4.x runtime.
  23. /// </summary>
  24. public static bool SupportsNet4x { get; } = false;
  25. static Features()
  26. {
  27. try
  28. {
  29. SupportsClipboard = ClrTypes.TextEditor?.GetProperty( "text" )?.GetSetMethod() != null;
  30. }
  31. catch( Exception )
  32. {
  33. }
  34. try
  35. {
  36. SupportsCustomYieldInstruction = ClrTypes.CustomYieldInstruction != null;
  37. }
  38. catch( Exception )
  39. {
  40. }
  41. try
  42. {
  43. SupportsSceneManager = ClrTypes.Scene != null && ClrTypes.SceneManager != null;
  44. }
  45. catch( Exception )
  46. {
  47. }
  48. try
  49. {
  50. SupportsNet4x = ClrTypes.Task != null;
  51. }
  52. catch( Exception )
  53. {
  54. }
  55. }
  56. }
  57. }