LightGlueRuntimeFacade.cs 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. using System;
  2. namespace LightGlue.Unity.Runtime
  3. {
  4. /// <summary>
  5. /// 业务侧统一入口门面:
  6. /// - 默认使用 LightGlueRuntimeAdapter
  7. /// - 允许外部注入自定义实现(便于测试或替换)
  8. /// </summary>
  9. public static class LightGlueRuntimeFacade
  10. {
  11. public static ILightGlueRuntime Runtime { get; private set; }
  12. public static event Action<LightGluePositionUpdate> OnPositionUpdate;
  13. public static void Configure(ILightGlueRuntime runtime)
  14. {
  15. if (Runtime != null)
  16. Runtime.OnPositionUpdate -= ForwardOnPositionUpdate;
  17. Runtime = runtime;
  18. if (Runtime != null)
  19. Runtime.OnPositionUpdate += ForwardOnPositionUpdate;
  20. }
  21. public static void Ensure()
  22. {
  23. if (Runtime == null)
  24. {
  25. Runtime = new LightGlueRuntimeAdapter();
  26. Runtime.OnPositionUpdate += ForwardOnPositionUpdate;
  27. }
  28. Runtime.Init();
  29. }
  30. private static void ForwardOnPositionUpdate(LightGluePositionUpdate update)
  31. {
  32. OnPositionUpdate?.Invoke(update);
  33. }
  34. // 推荐新语义入口
  35. public static void StartRuntime()
  36. {
  37. Ensure();
  38. Runtime.StartRuntime();
  39. }
  40. public static void StopRuntime()
  41. {
  42. Ensure();
  43. Runtime.StopRuntime();
  44. }
  45. public static void ShowPluginUI()
  46. {
  47. Ensure();
  48. Runtime.ShowPluginUI();
  49. }
  50. public static void HidePluginUI()
  51. {
  52. Ensure();
  53. Runtime.HidePluginUI();
  54. }
  55. public static void SetUIRuntimeMode(LightGlueUIRuntimeMode mode)
  56. {
  57. Ensure();
  58. Runtime.SetUIRuntimeMode(mode);
  59. }
  60. public static void SetHardwareMode(LightGlueHardwareMode mode)
  61. {
  62. Ensure();
  63. Runtime.SetHardwareMode(mode);
  64. }
  65. }
  66. }