DataItem.cs 6.5 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. if (dis > BladeServerManager.Instance.fadeDis)
  114. Hide();
  115. }
  116. public void Hide()
  117. {
  118. dongHua.Hide();
  119. }
  120. public void SaveEdiotrData( Transform foundTag)
  121. {
  122. //Transform point = foundTag.GetChild(0);
  123. //point.position = transform.position;
  124. //offsetPos = point.localPosition;
  125. transform.SetParent(foundTag);
  126. offsetPos = transform.localPosition;
  127. transform.SetParent(null);
  128. SaveData();
  129. }
  130. public void SaveData()
  131. {
  132. if (machineParameters != null)
  133. {
  134. UpdateCabinet updateData = new UpdateCabinet();
  135. updateData.deviceId = machineParameters.deviceId;
  136. updateData.tagID = machineParameters.tagID.ToString();
  137. updateData.offsetPos = machineParameters.offsetPos;
  138. updateData.eulerAxle = machineParameters.eulerAxle.ToString();
  139. string data = JsonConvert.SerializeObject(updateData);
  140. machineParameters.offsetPos = offsetPos;
  141. HttpLangChaoTool.Instance.Post(HttpLangChaoAction.updateCabinet, data, UpdateCabinetCallBack);
  142. }
  143. MachineRoomManager.Instance.SaveAllData();
  144. }
  145. private void UpdateCabinetCallBack(string msg)
  146. {
  147. Debug.Log(msg);
  148. JObject json = JObject.Parse(msg);
  149. if (json["code"].ToString() == "200")
  150. {
  151. Debug.Log(" 更新机柜参数成功 ");
  152. }
  153. else
  154. {
  155. Debug.LogError(" 更新机柜参数出错 !!! " + HttpLangChaoAction.updateCabinet);
  156. }
  157. }
  158. }
  159. public class UpdateCabinet
  160. {
  161. public string deviceId { get; set; }
  162. public string tagID { get; set; }
  163. public Vector3 offsetPos { get; set; }
  164. public string eulerAxle { get; set; }
  165. }