SavePanel.cs 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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 void Save()
  30. {
  31. meshTest.transform.parent = parent;
  32. pos.x = meshTest.localPosition.x;
  33. pos.y = meshTest.localPosition.y;
  34. pos.z = meshTest.localPosition.z;
  35. rot.x = meshTest.localEulerAngles.x;
  36. rot.y = meshTest.localEulerAngles.y;
  37. rot.z = meshTest.localEulerAngles.x;
  38. string jsonString = JsonConvert.SerializeObject(posRotlist);
  39. this.SendCommand(new UploadCommand(this.GetService<IUpOrDownloadService>().URL, jsonString));
  40. sCToggleSwitch3D.isOn = false;
  41. gameObject.SetActive(false);
  42. }
  43. private void Cancle()
  44. {
  45. meshTest.transform.parent = parent;
  46. posRotlist = this.GetService<IUpOrDownloadService>().PosRot;
  47. float posX = posRotlist[0].x;
  48. float posY = posRotlist[0].y;
  49. float posZ = posRotlist[0].z;
  50. Vector3 pos = new Vector3(posX, posY, posZ);
  51. meshTest.localPosition = pos;
  52. float rotX = posRotlist[1].x;
  53. float rotY = posRotlist[1].y;
  54. float rotZ = posRotlist[1].z;
  55. meshTest.localEulerAngles = new Vector3(rotX, rotY, rotZ);
  56. sCToggleSwitch3D.isOn = false;
  57. gameObject.SetActive(false);
  58. }
  59. private void OnEnable()
  60. {
  61. if(ARMap!=null)
  62. ARMap.SetActive(false);
  63. SetSceneActive.active = true;
  64. }
  65. private void OnDisable()
  66. {
  67. if(ARMap!=null)
  68. ARMap.SetActive(true);
  69. SetSceneActive.active = false;
  70. }
  71. }