SavePanel.cs 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using Blue;
  2. using Newtonsoft.Json;
  3. using SC.XR.Unity;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.UI;
  7. public class SavePanel : AbstractController
  8. {
  9. public Button saveBtn;
  10. public Button cancleBtn;
  11. public Transform meshTest;
  12. public Transform parent;
  13. public SCToggleSwitch3D sCToggleSwitch3D;
  14. [SerializeField] private GameObject ARMap;
  15. private List<ScenePosRotInfo> posRotlist = new List<ScenePosRotInfo>();
  16. private ScenePosRotInfo pos = new ScenePosRotInfo();
  17. private ScenePosRotInfo rot = new ScenePosRotInfo();
  18. private void Start()
  19. {
  20. posRotlist.Add(pos); posRotlist.Add(rot);
  21. meshTest = GameObject.Find("ARSpaceForAll/mesh_test").gameObject.transform;
  22. parent = GameObject.Find("ARSpaceForAll").transform;
  23. ARMap = GameObject.Find("ARSpaceForAll/AR_Map");
  24. ARMap.SetActive(false);
  25. sCToggleSwitch3D = transform.parent.GetComponent<SCToggleSwitch3D>();
  26. saveBtn.onClick.AddListener(Save);
  27. cancleBtn.onClick.AddListener(Cancle);
  28. }
  29. private string URL = "https://api-fat1.ghz-tech.com/mr-navigator/v1/project/createposition";
  30. private void Save()
  31. {
  32. meshTest.transform.parent = parent;
  33. posRotlist[0].x = meshTest.localPosition.x;
  34. posRotlist[0].y = meshTest.localPosition.y;
  35. posRotlist[0].z = meshTest.localPosition.z;
  36. posRotlist[1].x = meshTest.localEulerAngles.x;
  37. posRotlist[1].y = meshTest.localEulerAngles.y;
  38. posRotlist[1].z = meshTest.localEulerAngles.z;
  39. string jsonString = JsonConvert.SerializeObject(posRotlist);
  40. this.SendCommand(new UploadCommand(URL, jsonString));
  41. sCToggleSwitch3D.isOn = false;
  42. gameObject.SetActive(false);
  43. }
  44. private void Cancle()
  45. {
  46. meshTest.transform.parent = parent;
  47. List<ScenePosRotInfo> TempPosRotlist = this.GetService<IUpOrDownloadService>().PosRot;
  48. float posX = TempPosRotlist[0].x;
  49. float posY = TempPosRotlist[0].y;
  50. float posZ = TempPosRotlist[0].z;
  51. Vector3 pos = new Vector3(posX, posY, posZ);
  52. meshTest.localPosition = pos;
  53. float rotX = TempPosRotlist[1].x;
  54. float rotY = TempPosRotlist[1].y;
  55. float rotZ = TempPosRotlist[1].z;
  56. meshTest.localEulerAngles = new Vector3(rotX, rotY, rotZ);
  57. sCToggleSwitch3D.isOn = false;
  58. gameObject.SetActive(false);
  59. }
  60. private void OnEnable()
  61. {
  62. if(ARMap!=null)
  63. ARMap.SetActive(false);
  64. SetSceneActive.active = true;
  65. }
  66. private void OnDisable()
  67. {
  68. if(ARMap!=null)
  69. ARMap.SetActive(true);
  70. SetSceneActive.active = false;
  71. }
  72. }