using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class TestVector : MonoBehaviour { //------------------------外部操作接口------------------------------------------ public static TestVector ins; //控制模型显示数量,模型最多同时支持4个,数组索引对应屏幕的渲染位置0:左上,1:右上;2:左下;3:右下 int modelCount = 4; public void SetAcc(params Vector3[] accList) { for (int i = 0; i < accList.Length; i++) { objectsList[i].Find("Acc").GetChild(0).localPosition = accList[i]; } } public void SetMag(params Vector3[] magList) { for (int i = 0; i < magList.Length; i++) { objectsList[i].Find("Mag").GetChild(0).localPosition = magList[i]; } } public void Set9AxisRotation(params Quaternion[] quatList) { for (int i = 0; i < quatList.Length; i++) { //渲染9Axis.update得出的Rotation objectsList[i].Find("AMesh").localRotation = quatList[i]; } } //-------------------------------------------------------------------------- [SerializeField] Button btnTap; List objectsList = new List(); bool isDebugging; void Start() { if (ins) { Destroy(gameObject); return; } ins = this; DontDestroyOnLoad(gameObject); // init for (int i = 0; i < modelCount; i++) { objectsList.Add(transform.Find("Objects" + i)); } btnTap.onClick.AddListener(() => { isDebugging = !isDebugging; RenderByDebugging(); }); RenderByDebugging(); StartCoroutine(AsyncCaptureExtraUI()); } void OnDestroy() { if (ins == this) ins = null; } // Update is called once per frame void RenderByDebugging() { btnTap.GetComponentInChildren().text = (isDebugging ? "关闭" : "开启") + "调试"; foreach (var o in objectsList) o.gameObject.SetActive(isDebugging); transform.Find("Canvas/ellipse-Image").gameObject.SetActive(isDebugging); transform.Find("Canvas/ExtraUI").gameObject.SetActive(isDebugging); StartCoroutine(AsyncNoticeBluetoothHolder()); } IEnumerator AsyncNoticeBluetoothHolder() { while (!BluetoothHolder.ins) { yield return null; } if (isDebugging) { BluetoothHolder.ins.ShowMagEllipse(this); } else { BluetoothHolder.ins.HideMagEllipse(this); } } IEnumerator AsyncCaptureExtraUI() { while (!BluetoothHolder.ins) { yield return null; } Transform a = BluetoothHolder.ins.transform.Find("Canvas/MagCalibrationButton"); Transform b = BluetoothHolder.ins.transform.Find("Canvas/GyrCalibrationButton"); a.parent = transform.Find("Canvas/ExtraUI"); b.parent = transform.Find("Canvas/ExtraUI"); a.localScale = Vector3.one; b.localScale = Vector3.one; a.GetComponent().anchoredPosition = new Vector3(-800, -40, 0); b.GetComponent().anchoredPosition = new Vector3(-800, -100, 0); } }