123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208 |
- 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>();
- boxCollider.enabled = false;
- meshRenderer = this.GetComponent<MeshRenderer>();
- meshRenderer.enabled = false;
- manipulationHandler = this.GetComponent<ManipulationHandler>();
- 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<DeviceParameters> DeviceParameterList;
- public List<DeviceInfo_Item> DeviceInfoList = new List<DeviceInfo_Item>();
- public void SetDeviceParametersData(List<DeviceParameters> 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));
- // Debug.Log(dis + " Dis DGJ ===> " + BladeServerManager.Instance.fadeDis);
- 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; }
- }
|