ImmersalLocalControl.cs 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. using Immersal.AR;
  2. using UnityEngine;
  3. using Blue;
  4. using UnityEngine.UI;
  5. using static IsLocation;
  6. /// <summary>
  7. /// 打开景点后是否开启点云定位功能
  8. /// </summary>
  9. public class ImmersalLocalControl : AbstractController
  10. {
  11. private Color32 blue= new Color32(0, 120, 255, 255);
  12. private Color32 white= new Color32(255, 255, 255, 255);
  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. public int id;
  17. public int projectId;
  18. public bool isOn; // 是否开启
  19. private bool firstOpen = true; // 第一次打开
  20. private void Awake()
  21. {
  22. if (!AutoERNIEBot.Auto)
  23. {
  24. this.RegisterEvent<SetImmersalLocalEvent>(Unload);
  25. }
  26. }
  27. private void OnEnable()
  28. {
  29. if(AutoERNIEBot.Auto) return;
  30. if(firstOpen)
  31. {
  32. firstOpen = false;
  33. return;
  34. }
  35. Debug.LogError($"{name}是否定位:"+isOn);
  36. if(isOn)
  37. {
  38. // 启动脚本,开启定位
  39. XRLocalizer.enabled = true;
  40. SetLocalTime.isFind = true;
  41. Y_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = blue;
  42. Y_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = blue;
  43. N_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = white;
  44. N_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = white;
  45. }
  46. else
  47. {
  48. XRLocalizer.enabled = false;
  49. Y_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = white;
  50. Y_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = white;
  51. N_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = blue;
  52. N_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = blue;
  53. }
  54. this.RegisterEvent<SetImmersalLocalEvent>(Unload);
  55. }
  56. private void OnDisable()
  57. {
  58. if(AutoERNIEBot.Auto) return;
  59. this.UnRegisterEvent<SetImmersalLocalEvent>(Unload);
  60. }
  61. private void Unload(SetImmersalLocalEvent e)
  62. {
  63. isOn = e.isLocation;
  64. this.SendCommand(new ImmersalSetLocalCommand(id,projectId,isOn));
  65. }
  66. }