ImmersalLocalizerController.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using Immersal.AR;
  2. using UnityEngine;
  3. using Blue;
  4. using UnityEngine.UI;
  5. using System.Collections;
  6. using Newtonsoft.Json;
  7. using System.Collections.Generic;
  8. /// <summary>
  9. /// 控制Immersal定位
  10. /// </summary>
  11. public class ImmersalLocalizerController: AbstractController
  12. {
  13. private XRLocalizer XRLocalizer =>SceneIOCContainer.Instance.Pull("XRLocalizer")as XRLocalizer;
  14. private Toggle Y_Location_Toggle =>SceneIOCContainer.Instance.Pull("Y_Location_Toggle")as Toggle;
  15. private Toggle N_Location_Toggle =>SceneIOCContainer.Instance.Pull("N_Location_Toggle")as Toggle;
  16. private Color32 blue= new Color32(0, 120, 255, 255);
  17. private Color32 white= new Color32(255, 255, 255, 255);
  18. private void Awake()
  19. {
  20. this.RegisterEvent<StartImmersalLocalizerEvent>(e =>
  21. {
  22. XRLocalizer.enabled = true;
  23. }).UnRegisterWhenGameObjectDestroyed(gameObject);
  24. this.RegisterEvent<SuccessImmersalLocalizerEvent>(e =>
  25. {
  26. if (!AutoERNIEBot.Auto)
  27. {
  28. Y_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = white;
  29. Y_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = white;
  30. N_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = blue;
  31. N_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = blue;
  32. StartCoroutine(XRLocalizerActive());
  33. InstantiateCommand Command = new InstantiateCommand(
  34. InstantiateSystem.Instance.BlueObject.NormalPopUp,
  35. "定位成功");
  36. this.SendCommand(Command);
  37. }
  38. }).UnRegisterWhenGameObjectDestroyed(gameObject);
  39. }
  40. private IEnumerator XRLocalizerActive()
  41. {
  42. yield return new WaitForSeconds(0.01f);
  43. XRLocalizer.enabled = false;
  44. }
  45. }