DeviceController.cs 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using QFramework;
  5. public class DeviceController : MonoBehaviour
  6. {
  7. public static DeviceController instance;
  8. public string DeviceName;
  9. private void Awake()
  10. {
  11. instance = this;
  12. ResKit.Init();
  13. UIKit.OpenPanel<PartLabelPanel>();
  14. }
  15. private void Start()
  16. {
  17. DeviceOfPartDataProxy deviceOfPartDataProxy = DAL.Instance.Get<DeviceOfPartDataProxy>();
  18. deviceOfPartDataProxy.ReadStepMsgInfoFromTable(DeviceName);
  19. PartInfo tmpPartInfo = GetDevicePartInfos(transform.GetComponent<PartMark>());
  20. UIKit.OpenPanel<PartListPanel>(new PartListPanelData() { m_PartInfo = tmpPartInfo});
  21. CameraSurround.instance.SetCameraPosition(true);
  22. }
  23. private void Update()
  24. {
  25. Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
  26. RaycastHit hit;
  27. if (Physics.Raycast(ray, out hit))
  28. {
  29. // 处理射线击中的对象
  30. if (hit.collider.GetComponent<PartMark>() != null)
  31. {
  32. PartMark tmpMark = hit.collider.GetComponentInParent<PartMark>();
  33. if (tmpMark != null)
  34. {
  35. UIKit.OpenPanel<PartLabelPanel>(UILevel.PopUI,new PartLabelPanelData() { partName = tmpMark.name });
  36. }
  37. }
  38. }
  39. else
  40. {
  41. UIKit.HidePanel<PartLabelPanel>();
  42. }
  43. if (Input.GetMouseButtonDown(0))
  44. {
  45. Ray ray1 = Camera.main.ScreenPointToRay(Input.mousePosition);
  46. RaycastHit hit1;
  47. if (Physics.Raycast(ray1, out hit1))
  48. {
  49. PartMark tmpMark = hit.collider.GetComponentInParent<PartMark>();
  50. if (tmpMark != null)
  51. {
  52. tmpMark.SetState(false);
  53. UIKit.GetPanel<PartListPanel>().SetPartItemState(tmpMark);
  54. }
  55. }
  56. }
  57. }
  58. public PartInfo GetDevicePartInfos(PartMark partMark)
  59. {
  60. //最父级
  61. PartInfo partInfo = new PartInfo(partMark.transform.name,partMark);
  62. //字级
  63. foreach (var item in partMark.m_ChildPartMarks)
  64. {
  65. partInfo.childPartInfos.Add(GetDevicePartInfos(item));
  66. }
  67. return partInfo;
  68. }
  69. }