SetSceneRootPosRot.cs 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. using Immersal.AR;
  2. using UnityEngine;
  3. /// <summary>
  4. /// 设置SceneRoot的位置和旋转
  5. /// 未定位时设置场景位置
  6. /// 定位后设置场景位置
  7. /// </summary>
  8. public class SetSceneRootPosRot : AbstractController
  9. {
  10. private Transform mSceneRoot;
  11. private Transform mA;
  12. void Start()
  13. {
  14. mSceneRoot = GameObject.Find("ARSpaceForAll/mesh_test/SceneRoot").transform;
  15. mA = GameObject.Find("ARSpaceForAll/mesh_test").transform.Find("A");
  16. }
  17. private Vector3 spacePos = Vector3.zero; // 定位后
  18. private Vector3 tempPos = Vector3.zero; // 定位前
  19. private Vector3 tempRot = Vector3.zero; // 定位前
  20. private void Update()
  21. {
  22. if (ARSpace.isFind)
  23. {
  24. Debug.Log("定位成功");
  25. spacePos.y = -1.5f;
  26. spacePos.z = mA.localPosition.z;
  27. mSceneRoot.localPosition = spacePos;
  28. mSceneRoot.localEulerAngles = Vector3.zero;
  29. }
  30. else
  31. {
  32. Debug.Log("正在定位");
  33. tempPos.y = -1.5f;
  34. mSceneRoot.position = tempPos;
  35. tempRot.y = mSceneRoot.parent.localEulerAngles.y * -1;
  36. mSceneRoot.localEulerAngles = tempRot;
  37. }
  38. }
  39. }