using System.Collections; using System.Collections.Generic; using GHZLangChao; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using SC.XR.Unity.Module_InputSystem; using TMPro; using UnityEngine; using UnityEngine.UI; public class DataItem : MonoBehaviour { public string ID; public int tagId; public Vector3 offsetPos; public int eulerAxle; public TextMeshProUGUI idText; // public Transform selectPanel; public bool isSelect; //public BladeServerData bSData; //public ServerData serverData; public MachineParameters machineParameters; public RectTransform bgTransform; public Donghua dongHua; private BoxCollider boxCollider; private MeshRenderer meshRenderer; private ManipulationHandler manipulationHandler; private void OnEnable() { dongHua.Show(); } private void Start() { boxCollider = this.GetComponent(); boxCollider.enabled = false; meshRenderer = this.GetComponent(); meshRenderer.enabled = false; manipulationHandler = this.GetComponent(); manipulationHandler.enabled = false; } public void Init( MachineParameters machineParameters) { this.ID = machineParameters.deviceId; this.offsetPos = machineParameters.offsetPos; this.eulerAxle = machineParameters.eulerAxle; idText.text = " 当前设备ID为: " + ID; this.gameObject.name = "DataItem" + ID; BladeServerManager.Instance.listTagTracking.Add(this); // this.selectPanel = BladeServerManager.Instance.selectPanel; this.machineParameters = machineParameters; this.tagId = machineParameters.tagID; //bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,MachineRoomManager.Instance.data.cabinetW); //bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, MachineRoomManager.Instance.data.cabinetH); } private List DeviceParameterList; public List DeviceInfoList = new List(); public void SetDeviceParametersData(List DeviceParameterList) { Debug.Log(DeviceParameterList.Count); this.DeviceParameterList = DeviceParameterList; for (int i = 0; i < DeviceInfoList.Count;i++) { if (DeviceParameterList[i].cabinetNumber == null||string.IsNullOrEmpty(DeviceParameterList[i].cabinetNumber)) DeviceInfoList[i].InitNull(); else DeviceInfoList[i].Init(DeviceParameterList[i], i, this);// 数据只有一个,所以都是0 } } //public void Init( int id ,Vector3 offsetPos, int eulerAxle ,BladeServerData data ,float width, float height) //{ // this.ID = id; // this.offsetPos = offsetPos; // this.eulerAxle = eulerAxle; // idText.text = " 当前设备ID为: "+ ID; // this.gameObject.name = "DataItem"+ID; // BladeServerManager.Instance.listTagTracking.Add(this); // this.selectPanel = BladeServerManager.Instance.selectPanel; // this.bSData = data; // this.serverData = null; // bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); // bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); //} //public void Init(int id, Vector3 offsetPos, int eulerAxle, ServerData serverData, float width, float height) //{ // this.ID = id; // this.offsetPos = offsetPos; // this.eulerAxle = eulerAxle; // idText.text = " 当前设备ID为: " + ID; // this.gameObject.name = "DataItem" + ID; // BladeServerManager.Instance.listTagTracking.Add(this); // this.selectPanel = BladeServerManager.Instance.selectPanel; // this.bSData = null; // this.serverData = serverData; // bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width); // bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height); //} public void SetSelect(bool state) { meshRenderer.enabled = state; boxCollider.enabled = state; manipulationHandler.enabled = state; } public void SelectObj(Transform selectPanel ) { transform.position = new Vector3(selectPanel.position.x, selectPanel.position.y, 0); } private void Update() { //if(isSelect) //{ // // transform.position = new Vector3(selectPanel.position.x, selectPanel.position.y, transform.position.z); //} float dis = Vector3.Distance(new Vector3(transform.position.x, 0, transform.position.z), new Vector3(OpenXRCamera.Instance.head.transform.position.x, 0, OpenXRCamera.Instance.head.transform.position.z)); if (dis > BladeServerManager.Instance.fadeDis) Hide(); } public void Hide() { dongHua.Hide(); } public void SaveEdiotrData( Transform foundTag) { //Transform point = foundTag.GetChild(0); //point.position = transform.position; //offsetPos = point.localPosition; transform.SetParent(foundTag); offsetPos = transform.localPosition; transform.SetParent(null); SaveData(); } public void SaveData() { if (machineParameters != null) { UpdateCabinet updateData = new UpdateCabinet(); updateData.deviceId = machineParameters.deviceId; updateData.tagID = machineParameters.tagID.ToString(); updateData.offsetPos = machineParameters.offsetPos; updateData.eulerAxle = machineParameters.eulerAxle.ToString(); string data = JsonConvert.SerializeObject(updateData); machineParameters.offsetPos = offsetPos; HttpTool.Instance.Post(HttpActionLang.updateCabinet, data, UpdateCabinetCallBack); } MachineRoomManager.Instance.SaveAllData(); } private void UpdateCabinetCallBack(string msg) { Debug.Log(msg); JObject json = JObject.Parse(msg); if (json["code"].ToString() == "200") { Debug.Log(" 更新机柜参数成功 "); } else { Debug.LogError(" 更新机柜参数出错 !!! " + HttpActionLang.updateCabinet); } } } public class UpdateCabinet { public string deviceId { get; set; } public string tagID { get; set; } public Vector3 offsetPos { get; set; } public string eulerAxle { get; set; } }