SavePanel.cs 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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. this.SendCommand(new EditorSettingCommand(true){ });
  75. SetSceneActive.Instance.active = true;
  76. goReference.SetActive(true);
  77. }
  78. private void OnDisable()
  79. {
  80. this.SendCommand(new EditorSettingCommand(false){ } );
  81. SetSceneActive.Instance.active = false;
  82. if(goReference!=null)
  83. goReference.SetActive(false);
  84. }
  85. }