SavePanel.cs 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  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. posRotlist[0].x = meshTest.localPosition.x;
  33. posRotlist[0].y = meshTest.localPosition.y;
  34. posRotlist[0].z = meshTest.localPosition.z;
  35. posRotlist[1].x = meshTest.localEulerAngles.x;
  36. posRotlist[1].y = meshTest.localEulerAngles.y;
  37. posRotlist[1].z = meshTest.localEulerAngles.z;
  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. List<ScenePosRotInfo> TempPosRotlist = this.GetService<IUpOrDownloadService>().PosRot;
  47. float posX = TempPosRotlist[0].x;
  48. float posY = TempPosRotlist[0].y;
  49. float posZ = TempPosRotlist[0].z;
  50. Vector3 pos = new Vector3(posX, posY, posZ);
  51. meshTest.localPosition = pos;
  52. float rotX = TempPosRotlist[1].x;
  53. float rotY = TempPosRotlist[1].y;
  54. float rotZ = TempPosRotlist[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. }