SavePanel.cs 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using Blue;
  2. using Newtonsoft.Json;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using UnityEngine.UI;
  6. public class SavePanel : AbstractController
  7. {
  8. public GameObject txtTip;
  9. public Button saveBtn;
  10. public Button cancleBtn;
  11. public Transform meshTest => (SceneIOCContainer.Instance.Pull("mesh_test") as GameObject).transform;
  12. public Transform aRSpaceForAll=>(SceneIOCContainer.Instance.Pull("ARSpaceForAll")as GameObject).transform;
  13. public GameObject parentObj;
  14. public Toggle parentToggle;
  15. private List<ScenePosRotInfo> posRotlist ;
  16. private ScenePosRotInfo pos = new ScenePosRotInfo();
  17. private ScenePosRotInfo rot = new ScenePosRotInfo();
  18. public LoadReference LoadReferenceController;
  19. private GameObject goReference // 参照物
  20. {
  21. get =>SceneIOCContainer.Instance.Pull("goRefrence")as GameObject;
  22. }
  23. private void Start()
  24. {
  25. saveBtn.onClick.AddListener(Save);
  26. cancleBtn.onClick.AddListener(Cancle);
  27. }
  28. public void setOpen(bool b)
  29. {
  30. if (b)
  31. {
  32. txtTip.SetActive(true);
  33. txtTip.GetComponentInChildren<Text>().text = "如需移动场景,请按住手柄拖动场景并走动\n场景将跟随您的脚步进行整体移动";
  34. }
  35. this.gameObject.SetActive(b);
  36. parentObj.SetActive(!b);
  37. }
  38. private string URL = "https://api-fat3.ghz-tech.com/mr-navigator/v1/project/createposition";
  39. private void Save()
  40. {
  41. meshTest.transform.parent = aRSpaceForAll;
  42. if (posRotlist == null)
  43. {
  44. posRotlist = new List<ScenePosRotInfo>();
  45. posRotlist.Add(pos); posRotlist.Add(rot);
  46. }
  47. posRotlist[0].x = meshTest.localPosition.x;
  48. posRotlist[0].y = meshTest.localPosition.y;
  49. posRotlist[0].z = meshTest.localPosition.z;
  50. posRotlist[1].x = meshTest.localEulerAngles.x;
  51. posRotlist[1].y = meshTest.localEulerAngles.y;
  52. posRotlist[1].z = meshTest.localEulerAngles.z;
  53. string jsonString = JsonConvert.SerializeObject(posRotlist);
  54. this.SendCommand(new PointPosRotUploadCommand(URL, jsonString));
  55. }
  56. void setIsOn()
  57. {
  58. parentToggle.isOn = false;
  59. }
  60. private void Cancle()
  61. {
  62. meshTest.transform.parent = aRSpaceForAll;
  63. if(posRotlist!=null)
  64. {
  65. meshTest.localPosition = new Vector3(posRotlist[0].x,posRotlist[0].y,posRotlist[0].z);
  66. meshTest.localEulerAngles = new Vector3(posRotlist[1].x,posRotlist[1].y,posRotlist[1].z);
  67. }
  68. this.gameObject.SetActive(false);
  69. parentObj.SetActive(true);
  70. Invoke("setIsOn", 0.1f);
  71. }
  72. private void OnEnable()
  73. {
  74. SetSceneActive.Instance.active = true;
  75. goReference.SetActive(true);
  76. }
  77. private void OnDisable()
  78. {
  79. SetSceneActive.Instance.active = false;
  80. if(goReference!=null)
  81. goReference.SetActive(false);
  82. }
  83. }