DataItem.cs 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using GHZLangChao;
  4. using Newtonsoft.Json;
  5. using Newtonsoft.Json.Linq;
  6. using SC.XR.Unity.Module_InputSystem;
  7. using TMPro;
  8. using UnityEngine;
  9. using UnityEngine.UI;
  10. public class DataItem : MonoBehaviour
  11. {
  12. public string ID;
  13. public int tagId;
  14. public Vector3 offsetPos;
  15. public int eulerAxle;
  16. public TextMeshProUGUI idText;
  17. // public Transform selectPanel;
  18. public bool isSelect;
  19. //public BladeServerData bSData;
  20. //public ServerData serverData;
  21. public MachineParameters machineParameters;
  22. public RectTransform bgTransform;
  23. public Donghua dongHua;
  24. private BoxCollider boxCollider;
  25. private MeshRenderer meshRenderer;
  26. private ManipulationHandler manipulationHandler;
  27. private void OnEnable()
  28. {
  29. dongHua.Show();
  30. }
  31. private void Start()
  32. {
  33. boxCollider = this.GetComponent<BoxCollider>();
  34. boxCollider.enabled = false;
  35. meshRenderer = this.GetComponent<MeshRenderer>();
  36. meshRenderer.enabled = false;
  37. manipulationHandler = this.GetComponent<ManipulationHandler>();
  38. manipulationHandler.enabled = false;
  39. }
  40. public void Init( MachineParameters machineParameters)
  41. {
  42. this.ID = machineParameters.deviceId;
  43. this.offsetPos = machineParameters.offsetPos;
  44. this.eulerAxle = machineParameters.eulerAxle;
  45. idText.text = " 当前设备ID为: " + ID;
  46. this.gameObject.name = "DataItem" + ID;
  47. BladeServerManager.Instance.listTagTracking.Add(this);
  48. // this.selectPanel = BladeServerManager.Instance.selectPanel;
  49. this.machineParameters = machineParameters;
  50. this.tagId = machineParameters.tagID;
  51. //bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,MachineRoomManager.Instance.data.cabinetW);
  52. //bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, MachineRoomManager.Instance.data.cabinetH);
  53. }
  54. private List<DeviceParameters> DeviceParameterList;
  55. public List<DeviceInfo_Item> DeviceInfoList = new List<DeviceInfo_Item>();
  56. public void SetDeviceParametersData(List<DeviceParameters> DeviceParameterList)
  57. {
  58. // Debug.Log(DeviceParameterList.Count);
  59. this.DeviceParameterList = DeviceParameterList;
  60. for (int i = 0; i < DeviceInfoList.Count;i++)
  61. {
  62. if (DeviceParameterList[i].cabinetNumber == null||string.IsNullOrEmpty(DeviceParameterList[i].cabinetNumber))
  63. DeviceInfoList[i].InitNull();
  64. else
  65. DeviceInfoList[i].Init(DeviceParameterList[i], i, this);// 数据只有一个,所以都是0
  66. }
  67. }
  68. //public void Init( int id ,Vector3 offsetPos, int eulerAxle ,BladeServerData data ,float width, float height)
  69. //{
  70. // this.ID = id;
  71. // this.offsetPos = offsetPos;
  72. // this.eulerAxle = eulerAxle;
  73. // idText.text = " 当前设备ID为: "+ ID;
  74. // this.gameObject.name = "DataItem"+ID;
  75. // BladeServerManager.Instance.listTagTracking.Add(this);
  76. // this.selectPanel = BladeServerManager.Instance.selectPanel;
  77. // this.bSData = data;
  78. // this.serverData = null;
  79. // bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
  80. // bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
  81. //}
  82. //public void Init(int id, Vector3 offsetPos, int eulerAxle, ServerData serverData, float width, float height)
  83. //{
  84. // this.ID = id;
  85. // this.offsetPos = offsetPos;
  86. // this.eulerAxle = eulerAxle;
  87. // idText.text = " 当前设备ID为: " + ID;
  88. // this.gameObject.name = "DataItem" + ID;
  89. // BladeServerManager.Instance.listTagTracking.Add(this);
  90. // this.selectPanel = BladeServerManager.Instance.selectPanel;
  91. // this.bSData = null;
  92. // this.serverData = serverData;
  93. // bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, width);
  94. // bgTransform.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, height);
  95. //}
  96. public void SetSelect(bool state)
  97. {
  98. meshRenderer.enabled = state;
  99. boxCollider.enabled = state;
  100. manipulationHandler.enabled = state;
  101. }
  102. public void SelectObj(Transform selectPanel )
  103. {
  104. transform.position = new Vector3(selectPanel.position.x, selectPanel.position.y, 0);
  105. }
  106. private void Update()
  107. {
  108. //if(isSelect)
  109. //{
  110. // // transform.position = new Vector3(selectPanel.position.x, selectPanel.position.y, transform.position.z);
  111. //}
  112. 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));
  113. // Debug.Log(dis + " Dis DGJ ===> " + BladeServerManager.Instance.fadeDis);
  114. if (dis > BladeServerManager.Instance.fadeDis)
  115. Hide();
  116. }
  117. public void Hide()
  118. {
  119. dongHua.Hide();
  120. }
  121. public void SaveEdiotrData( Transform foundTag)
  122. {
  123. //Transform point = foundTag.GetChild(0);
  124. //point.position = transform.position;
  125. //offsetPos = point.localPosition;
  126. transform.SetParent(foundTag);
  127. offsetPos = transform.localPosition;
  128. transform.SetParent(null);
  129. SaveData();
  130. }
  131. public void SaveData()
  132. {
  133. if (machineParameters != null)
  134. {
  135. UpdateCabinet updateData = new UpdateCabinet();
  136. updateData.deviceId = machineParameters.deviceId;
  137. updateData.tagID = machineParameters.tagID.ToString();
  138. updateData.offsetPos = machineParameters.offsetPos;
  139. updateData.eulerAxle = machineParameters.eulerAxle.ToString();
  140. string data = JsonConvert.SerializeObject(updateData);
  141. machineParameters.offsetPos = offsetPos;
  142. HttpTool.Instance.Post(HttpActionLang.updateCabinet, data, UpdateCabinetCallBack);
  143. }
  144. MachineRoomManager.Instance.SaveAllData();
  145. }
  146. private void UpdateCabinetCallBack(string msg)
  147. {
  148. Debug.Log(msg);
  149. JObject json = JObject.Parse(msg);
  150. if (json["code"].ToString() == "200")
  151. {
  152. Debug.Log(" 更新机柜参数成功 ");
  153. }
  154. else
  155. {
  156. Debug.LogError(" 更新机柜参数出错 !!! " + HttpActionLang.updateCabinet);
  157. }
  158. }
  159. }
  160. public class UpdateCabinet
  161. {
  162. public string deviceId { get; set; }
  163. public string tagID { get; set; }
  164. public Vector3 offsetPos { get; set; }
  165. public string eulerAxle { get; set; }
  166. }