QRScannerManager.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. namespace EZXR.Glass.QRScanner
  5. {
  6. public class QRScannerManager : MonoBehaviour
  7. {
  8. private static ScannerHandler scannerHandler;
  9. private static Action startListeners;
  10. private static Action<bool, string> completeListeners;
  11. public static void RequestOpen()
  12. {
  13. if (scannerHandler == null)
  14. {
  15. var instance = Instantiate(Resources.Load<GameObject>("ScannerWindow"));
  16. scannerHandler = instance.GetComponent<ScannerHandler>();
  17. }
  18. scannerHandler.gameObject.SetActive(true);
  19. scannerHandler.SetupListeners(startListeners, completeListeners);
  20. }
  21. public static void RequestClose()
  22. {
  23. //startListeners = null;
  24. //completeListeners = null;
  25. if (scannerHandler != null)
  26. {
  27. scannerHandler.gameObject.SetActive(false);
  28. scannerHandler.SetupListeners(null, null);
  29. }
  30. }
  31. public static void RegisterStartListener(Action onStart)
  32. {
  33. startListeners += onStart;
  34. scannerHandler?.SetupListeners(startListeners, completeListeners);
  35. }
  36. public static void UnregisterStartListener(Action onStart)
  37. {
  38. startListeners -= onStart;
  39. scannerHandler?.SetupListeners(startListeners, completeListeners);
  40. }
  41. public static void RegisterCompleteListener(Action<bool, string> onComplete)
  42. {
  43. completeListeners += onComplete;
  44. scannerHandler?.SetupListeners(startListeners, completeListeners);
  45. }
  46. public static void UnregisterCompleteListener(Action<bool, string> onComplete)
  47. {
  48. completeListeners -= onComplete;
  49. scannerHandler?.SetupListeners(startListeners, completeListeners);
  50. }
  51. }
  52. }