|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using UnityEngine.UI;
|
|
|
|
|
|
using UDE_HAND_INTERACTION;
|
|
|
|
|
|
using Unity.XR.CoreUtils;
|
|
|
|
|
|
|
|
|
|
|
|
public class UIManager : MonoBehaviour
|
|
|
|
|
|
{
|
|
|
|
|
|
public static readonly string CurrentSDKVersion = "1.5";
|
|
|
|
|
|
public XROrigin XR_Origin;
|
|
|
|
|
|
public GameObject[] Panels;
|
|
|
|
|
|
public GameObject ChoosePanel;
|
|
|
|
|
|
public GameObject JoyRangeCalibPanel;
|
|
|
|
|
|
|
|
|
|
|
|
public FingerPressController ConfirmChoose;
|
|
|
|
|
|
public FingerPressController FinRangeCalib;
|
|
|
|
|
|
private GameObject OriginPanel;
|
|
|
|
|
|
private int PanelIndex = 0;
|
|
|
|
|
|
|
|
|
|
|
|
private BleManager bleManager;
|
|
|
|
|
|
|
|
|
|
|
|
public FingerPressController[] ContinueBtns;
|
|
|
|
|
|
public FingerPressController ExitBtn;
|
|
|
|
|
|
public FingerPressController[] BackBtns;
|
|
|
|
|
|
public FingerPressController[] HeightSwitch;
|
|
|
|
|
|
public GameObject SkipCalibration;
|
|
|
|
|
|
|
|
|
|
|
|
public GameObject[] Hands;
|
|
|
|
|
|
public Sprite[] HandsIconsSet;
|
|
|
|
|
|
public Sprite[] HandsSignalSet;
|
|
|
|
|
|
public Sprite[] HandsBatterySet;
|
|
|
|
|
|
|
|
|
|
|
|
private Image[] HandsIcons = new Image[2];
|
|
|
|
|
|
private Text[] DeviceNames = new Text[2];
|
|
|
|
|
|
private Image[] HandSignals = new Image[2];
|
|
|
|
|
|
private Image[] HandsBattery = new Image[2];
|
|
|
|
|
|
private Image[] SeparateLine = new Image[2];
|
|
|
|
|
|
|
|
|
|
|
|
public Color ConnectColor;
|
|
|
|
|
|
public Color DisconnectColor;
|
|
|
|
|
|
private Color DefaultColor;
|
|
|
|
|
|
|
|
|
|
|
|
public Image[] LoadBar;
|
|
|
|
|
|
public Text[] Msg;
|
|
|
|
|
|
private bool EnterCalibrationPanel = false;
|
|
|
|
|
|
private float TimeCnt = 3;
|
|
|
|
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
|
|
{
|
|
|
|
|
|
bleManager = GetComponent<BleManager>();
|
|
|
|
|
|
if (bleManager.handDrivers[0].UsingAndroidService || bleManager.handDrivers[1].UsingAndroidService)
|
|
|
|
|
|
{
|
|
|
|
|
|
Panels = new GameObject[1] { Panels[0] };
|
|
|
|
|
|
bleManager.UsingAndroidService = true;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Start()
|
|
|
|
|
|
{
|
|
|
|
|
|
Panels[PanelIndex].SetActive(true);
|
|
|
|
|
|
Panels[0].transform.Find("Version").GetComponent<Text>().text = CurrentSDKVersion;
|
|
|
|
|
|
ExitBtn.OnSelect.AddListener(() => { Application.Quit(); });
|
|
|
|
|
|
|
|
|
|
|
|
foreach (var btn in ContinueBtns)
|
|
|
|
|
|
{
|
|
|
|
|
|
btn.OnSelect.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if(Panels.Length > 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
Panels[PanelIndex++].SetActive(false);
|
|
|
|
|
|
Panels[PanelIndex].SetActive(true);
|
|
|
|
|
|
EnterCalibrationPanel = true;
|
|
|
|
|
|
TimeCnt = 3;
|
|
|
|
|
|
if(PanelIndex == 3)
|
|
|
|
|
|
{
|
|
|
|
|
|
bleManager.Calibration(0);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
transform.GetChild(0).gameObject.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
foreach (var btn in BackBtns)
|
|
|
|
|
|
{
|
|
|
|
|
|
btn.OnSelect.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
if(ChoosePanel.activeInHierarchy && PanelIndex == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
ChoosePanel.SetActive(false);
|
|
|
|
|
|
}
|
|
|
|
|
|
Panels[PanelIndex--].SetActive(false);
|
|
|
|
|
|
Panels[PanelIndex].SetActive(true);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
DefaultColor = Hands[0].GetComponent<Image>().color;
|
|
|
|
|
|
for (int i = 0; i < 2; ++i)
|
|
|
|
|
|
{
|
|
|
|
|
|
HandsIcons[i] = Hands[i].transform.GetChild(0).GetComponent<Image>();
|
|
|
|
|
|
DeviceNames[i] = Hands[i].transform.GetChild(1).GetComponent<Text>();
|
|
|
|
|
|
HandSignals[i] = Hands[i].transform.GetChild(2).GetComponent<Image>();
|
|
|
|
|
|
HandsBattery[i] = Hands[i].transform.GetChild(3).GetComponent<Image>();
|
|
|
|
|
|
SeparateLine[i] = Hands[i].transform.GetChild(4).GetComponent<Image>();
|
|
|
|
|
|
}
|
|
|
|
|
|
ConfirmChoose.OnSelect.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
bleManager.LeftSpecificConnect = ChoosePanel.GetComponent<ChooseBle>().LeftChoice;
|
|
|
|
|
|
bleManager.RightSpecificConnect = ChoosePanel.GetComponent<ChooseBle>().RightChoice;
|
|
|
|
|
|
OriginPanel.SetActive(true);
|
|
|
|
|
|
ChoosePanel.SetActive(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
if(HeightSwitch.Length > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
HeightSwitch[0].OnSelect.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
transform.root.position = new Vector3(0, 1.2f, 0.5f);
|
|
|
|
|
|
XR_Origin.transform.Find("Camera Offset").position = new Vector3(0, 1.2f, 0);
|
|
|
|
|
|
XR_Origin.transform.Find("WorldOffset").position = new Vector3(0, 1.2f, 0);
|
|
|
|
|
|
});
|
|
|
|
|
|
HeightSwitch[1].OnSelect.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
transform.root.position = new Vector3(0, 1.6f, 0.5f);
|
|
|
|
|
|
XR_Origin.transform.Find("Camera Offset").position = new Vector3(0, 1.6f, 0);
|
|
|
|
|
|
XR_Origin.transform.Find("WorldOffset").position = new Vector3(0, 1.6f, 0);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
FinRangeCalib.OnSelect.AddListener(() =>
|
|
|
|
|
|
{
|
|
|
|
|
|
bleManager.JoyRangeCalibration(false);
|
|
|
|
|
|
transform.GetChild(0).gameObject.SetActive(false);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
|
{
|
|
|
|
|
|
if(bleManager.NeedChooseConnect && string.IsNullOrEmpty(bleManager.LeftSpecificConnect) && string.IsNullOrEmpty(bleManager.RightSpecificConnect))
|
|
|
|
|
|
{
|
|
|
|
|
|
OriginPanel = Panels[1];
|
|
|
|
|
|
if (PanelIndex == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
Panels[1].SetActive(false);
|
|
|
|
|
|
ChoosePanel.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
var Layouts = ChoosePanel.transform.GetComponentsInChildren<GridLayoutGroup>();
|
|
|
|
|
|
int[] Indexs = new int[2] { 0, 0 };
|
|
|
|
|
|
foreach (var device in bleManager.DevicesList)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (device[^1] == 'L')
|
|
|
|
|
|
{
|
|
|
|
|
|
var SpecificDevice = Layouts[0].transform.GetChild(Indexs[0]).gameObject;
|
|
|
|
|
|
SpecificDevice.SetActive(true);
|
|
|
|
|
|
SpecificDevice.transform.GetChild(0).Find("DeviceName").GetComponent<Text>().text = device;
|
|
|
|
|
|
Indexs[0]++;
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(device[^1] == 'R')
|
|
|
|
|
|
{
|
|
|
|
|
|
var SpecificDevice = Layouts[1].transform.GetChild(Indexs[1]).gameObject;
|
|
|
|
|
|
SpecificDevice.SetActive(true);
|
|
|
|
|
|
SpecificDevice.transform.GetChild(0).Find("DeviceName").GetComponent<Text>().text = device;
|
|
|
|
|
|
Indexs[1]++;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(OriginPanel != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
ChoosePanel.SetActive(false);
|
|
|
|
|
|
if (PanelIndex == 1)
|
|
|
|
|
|
{
|
|
|
|
|
|
Panels[1].SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(!string.IsNullOrEmpty(ChoosePanel.GetComponent<ChooseBle>().LeftChoice) && !string.IsNullOrEmpty(ChoosePanel.GetComponent<ChooseBle>().RightChoice))
|
|
|
|
|
|
{
|
|
|
|
|
|
ConfirmChoose.transform.parent.gameObject.SetActive(true);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (bleManager.LeftConnectState)
|
|
|
|
|
|
{
|
|
|
|
|
|
Hands[0].GetComponent<Image>().color = Color.white;
|
|
|
|
|
|
HandsIcons[0].sprite = HandsIconsSet[1];
|
|
|
|
|
|
DeviceNames[0].color = Color.white;
|
|
|
|
|
|
DeviceNames[0].text = bleManager.LeftDeviceName;
|
|
|
|
|
|
HandSignals[0].sprite = HandsSignalSet[1];
|
|
|
|
|
|
HandsBattery[0].sprite = HandsBatterySet[1];
|
|
|
|
|
|
SeparateLine[0].color = ConnectColor;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Hands[0].GetComponent<Image>().color = DefaultColor;
|
|
|
|
|
|
HandsIcons[0].sprite = HandsIconsSet[0];
|
|
|
|
|
|
DeviceNames[0].color = DisconnectColor;
|
|
|
|
|
|
DeviceNames[0].text = "...";
|
|
|
|
|
|
HandSignals[0].sprite = HandsSignalSet[0];
|
|
|
|
|
|
HandsBattery[0].sprite = HandsBatterySet[0];
|
|
|
|
|
|
SeparateLine[0].color = DisconnectColor;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if(bleManager.RightConnectState)
|
|
|
|
|
|
{
|
|
|
|
|
|
Hands[1].GetComponent<Image>().color = Color.white;
|
|
|
|
|
|
HandsIcons[1].sprite = HandsIconsSet[3];
|
|
|
|
|
|
DeviceNames[1].color = Color.white;
|
|
|
|
|
|
DeviceNames[1].text = bleManager.RightDeviceName;
|
|
|
|
|
|
HandSignals[1].sprite = HandsSignalSet[1];
|
|
|
|
|
|
HandsBattery[1].sprite = HandsBatterySet[1];
|
|
|
|
|
|
SeparateLine[1].color = ConnectColor;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
Hands[1].GetComponent<Image>().color = DefaultColor;
|
|
|
|
|
|
HandsIcons[1].sprite = HandsIconsSet[2];
|
|
|
|
|
|
DeviceNames[1].color = DisconnectColor;
|
|
|
|
|
|
DeviceNames[1].text = "...";
|
|
|
|
|
|
HandSignals[1].sprite = HandsSignalSet[0];
|
|
|
|
|
|
HandsBattery[1].sprite = HandsBatterySet[0];
|
|
|
|
|
|
SeparateLine[1].color = DisconnectColor;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
ContinueBtns[1].transform.parent.gameObject.SetActive(bleManager.LeftConnectState && bleManager.RightConnectState);
|
|
|
|
|
|
SkipCalibration?.SetActive(PlayerPrefs.GetInt(bleManager.LeftDeviceName) == 1 && PlayerPrefs.GetInt(bleManager.RightDeviceName) == 1);
|
|
|
|
|
|
|
|
|
|
|
|
if (PanelIndex > 2 && EnterCalibrationPanel)
|
|
|
|
|
|
{
|
|
|
|
|
|
TimeCnt -= Time.deltaTime;
|
|
|
|
|
|
if(TimeCnt >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
LoadBar[PanelIndex - 3].fillAmount = 1 - (TimeCnt / 3);
|
|
|
|
|
|
Msg[PanelIndex - 3].text = "Preparation phase " + (int)(TimeCnt + 1) + "s";
|
|
|
|
|
|
}
|
|
|
|
|
|
else if(TimeCnt > -1)
|
|
|
|
|
|
{
|
|
|
|
|
|
LoadBar[PanelIndex - 3].fillAmount = -TimeCnt;
|
|
|
|
|
|
Msg[PanelIndex - 3].text = "Calibrating<EFBFBD><EFBFBD>Hold your pose";
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
LoadBar[PanelIndex - 3].fillAmount = 1;
|
|
|
|
|
|
bleManager.Calibration(PanelIndex - 2);
|
|
|
|
|
|
if (PanelIndex == 5)
|
|
|
|
|
|
{
|
|
|
|
|
|
EnterCalibrationPanel = false;
|
|
|
|
|
|
Panels[PanelIndex].SetActive(false);
|
|
|
|
|
|
JoyRangeCalibPanel.SetActive(true);
|
|
|
|
|
|
bleManager.JoyRangeCalibration(true);
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
Panels[PanelIndex++].SetActive(false);
|
|
|
|
|
|
Panels[PanelIndex].SetActive(true);
|
|
|
|
|
|
TimeCnt = 3;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|