12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273 |
- using Immersal.AR;
- using UnityEngine;
- using Blue;
- using UnityEngine.UI;
- using static IsLocation;
- /// <summary>
- /// 打开景点后是否开启点云定位功能
- /// </summary>
- public class ImmersalLocalControl : AbstractController
- {
- private Color32 blue= new Color32(0, 120, 255, 255);
- private Color32 white= new Color32(255, 255, 255, 255);
- private XRLocalizer XRLocalizer =>SceneIOCContainer.Instance.Pull("XRLocalizer")as XRLocalizer;
- private Toggle Y_Location_Toggle =>SceneIOCContainer.Instance.Pull("Y_Location_Toggle")as Toggle;
- private Toggle N_Location_Toggle =>SceneIOCContainer.Instance.Pull("N_Location_Toggle")as Toggle;
- public int id;
- public int projectId;
- public bool isOn; // 是否开启
- private bool firstOpen = true; // 第一次打开
- private void Awake()
- {
- if (!AutoERNIEBot.Auto)
- {
- this.RegisterEvent<SetImmersalLocalEvent>(Unload);
- }
- }
- private void OnEnable()
- {
- if(AutoERNIEBot.Auto) return;
- if(firstOpen)
- {
- firstOpen = false;
- return;
- }
- Debug.LogError($"{name}是否定位:"+isOn);
- if(isOn)
- {
- // 启动脚本,开启定位
- XRLocalizer.enabled = true;
- SetLocalTime.isFind = true;
- Y_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = blue;
- Y_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = blue;
- N_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = white;
- N_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = white;
- }
- else
- {
- XRLocalizer.enabled = false;
- Y_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = white;
- Y_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = white;
- N_Location_Toggle.transform.Find("Background").GetComponent<Image>().color = blue;
- N_Location_Toggle.transform.Find("Background/Checkmark").GetComponent<Image>().color = blue;
- }
- this.RegisterEvent<SetImmersalLocalEvent>(Unload);
- }
- private void OnDisable()
- {
- if(AutoERNIEBot.Auto) return;
- this.UnRegisterEvent<SetImmersalLocalEvent>(Unload);
- }
- private void Unload(SetImmersalLocalEvent e)
- {
- isOn = e.isLocation;
- this.SendCommand(new ImmersalSetLocalCommand(id,projectId,isOn));
- }
- }
|