using Immersal.AR;
using UnityEngine;
using Blue;
using UnityEngine.UI;
using static IsLocation;
///
/// 打开景点后是否开启点云定位功能
///
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(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().color = blue;
Y_Location_Toggle.transform.Find("Background/Checkmark").GetComponent().color = blue;
N_Location_Toggle.transform.Find("Background").GetComponent().color = white;
N_Location_Toggle.transform.Find("Background/Checkmark").GetComponent().color = white;
}
else
{
XRLocalizer.enabled = false;
Y_Location_Toggle.transform.Find("Background").GetComponent().color = white;
Y_Location_Toggle.transform.Find("Background/Checkmark").GetComponent().color = white;
N_Location_Toggle.transform.Find("Background").GetComponent().color = blue;
N_Location_Toggle.transform.Find("Background/Checkmark").GetComponent().color = blue;
}
this.RegisterEvent(Unload);
}
private void OnDisable()
{
if(AutoERNIEBot.Auto) return;
this.UnRegisterEvent(Unload);
}
private void Unload(SetImmersalLocalEvent e)
{
isOn = e.isLocation;
this.SendCommand(new ImmersalSetLocalCommand(id,projectId,isOn));
}
}