Unity Udexreal开发插件包
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123 lines
4.4 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class CalibrationScore : MonoBehaviour
{
public BleManager bleManager;
public Color[] color_calibration;
private GameObject RightHand;
private GameObject LeftHand;
public TextMeshProUGUI[] DeviceNames;
public TextMeshProUGUI[] AlgorithmVersions;
public Image[] RightHandDots;
private Image[] LeftHandDots;
public Image[] Battery;
public Sprite[] BatteryIcons;
private readonly List<double[]> OffsetStandard = new()
{
new double[4]{0, 300, 750, 1050},
new double[4]{0, 210, 525, 790},
new double[4]{0, 150, 350, 525},
new double[4]{0, 200, 500, 750},
new double[4]{0, 100, 250, 375},
new double[4]{0, 35, 70, 150},
new double[4]{0, 230, 575, 865},
new double[4]{0, 100, 250, 375},
new double[4]{0, 35, 70, 150},
new double[4]{0, 280, 700, 1050},
new double[4]{0, 100, 250, 375},
new double[4]{0, 280, 700, 1050}
};
// Start is called before the first frame update
void Start()
{
RightHand = transform.Find("RightHandImg").gameObject;
LeftHand = transform.Find("LeftHandImg").gameObject;
var RightHandDots_ = RightHand.GetComponentsInChildren<Image>();
var LeftHandDots_ = LeftHand.GetComponentsInChildren<Image>();
RightHandDots = new Image[RightHandDots_.Length / 2 + 1];
LeftHandDots = new Image[RightHandDots_.Length / 2 + 1];
for (int i = 0, j = 0; i < RightHandDots_.Length; ++i)
{
if (RightHandDots_[i].name != "Image" && RightHandDots_[i].name[0] != 'B')
{
RightHandDots[j] = RightHandDots_[i];
LeftHandDots[j++] = LeftHandDots_[i];
}
}
}
// Update is called once per frame
void Update()
{
if (!gameObject.activeInHierarchy) return;
if (bleManager.LeftConnectState && bleManager.RightConnectState)
{
DeviceNames[0].text = bleManager.LeftDeviceName;
DeviceNames[1].text = bleManager.RightDeviceName;
AlgorithmVersions[0].text = bleManager.LeftAlgorithmVer;
AlgorithmVersions[1].text = bleManager.RightAlgorithmVer;
var RightCalibrationOffset = new double[12];
var LeftCalibrationOffset = new double[12];
var RightRealData = bleManager.RightRawData;
var LeftRealData = bleManager.LeftRawData;
if (bleManager.FinishCalibration)
{
RightCalibrationOffset = bleManager.RightCalibrationOffset;
LeftCalibrationOffset = bleManager.LeftCalibrationOffset;
}
for (int i = 0; i < 12; ++i)
{
int[] level = new int[2];
for(int j = 0; j < 4; ++j)
{
if (RightCalibrationOffset[i] >= OffsetStandard[i][j])
{
level[0] = j;
}
if (LeftCalibrationOffset[i] >= OffsetStandard[i][j])
{
level[1] = j;
}
}
RightHandDots[i + 1].color = color_calibration[level[0]];
RightHandDots[i + 1].GetComponentInChildren<TextMeshProUGUI>().text = Math.Round(RightRealData[i], 2).ToString();
LeftHandDots[i + 1].color = color_calibration[level[1]];
LeftHandDots[i + 1].GetComponentInChildren<TextMeshProUGUI>().text = Math.Round(LeftRealData[i], 2).ToString();
}
Battery[0].gameObject.SetActive(true);
Battery[1].gameObject.SetActive(true);
}
else
{
DeviceNames[0].text = "None";
DeviceNames[1].text = "None";
AlgorithmVersions[0].text = "";
AlgorithmVersions[1].text = "";
for (int i = 0; i < 12; ++i)
{
RightHandDots[i + 1].color = color_calibration[0];
RightHandDots[i + 1].GetComponentInChildren<TextMeshProUGUI>().text = "0";
LeftHandDots[i + 1].color = color_calibration[0];
LeftHandDots[i + 1].GetComponentInChildren<TextMeshProUGUI>().text = "0";
}
Battery[0].gameObject.SetActive(false);
Battery[1].gameObject.SetActive(false);
}
}
}