using Immersal.AR; using UnityEngine; /// /// 设置SceneRoot的位置和旋转 /// 未定位时设置场景位置 /// 定位后设置场景位置 /// public class SetSceneRootPosRot : AbstractController { private Transform mSceneRoot; private Transform mA; void Start() { mSceneRoot = GameObject.Find("ARSpaceForAll/mesh_test/SceneRoot").transform; mA = GameObject.Find("ARSpaceForAll/mesh_test").transform.Find("A"); } private Vector3 spacePos = Vector3.zero; // 定位后 private Vector3 tempPos = Vector3.zero; // 定位前 private Vector3 tempRot = Vector3.zero; // 定位前 private void Update() { if (ARSpace.isFind) { Debug.Log("定位成功"); spacePos.y = -1.5f; spacePos.z = mA.localPosition.z; mSceneRoot.localPosition = spacePos; mSceneRoot.localEulerAngles = Vector3.zero; } else { Debug.Log("正在定位"); tempPos.y = -1.5f; mSceneRoot.position = tempPos; tempRot.y = mSceneRoot.parent.localEulerAngles.y * -1; mSceneRoot.localEulerAngles = tempRot; } } }