【发布时间】:2018-04-24 07:45:17
【问题描述】:
我是 Unity 的 ARCore 新手。我的同事已经在 iOS 上制作了这个应用程序。但是我在拖动对象并将其设置在某个位置时遇到了一些问题。您也可以用 2 个手指旋转它。在这里,我给出了 m 拖动的 ARKit 等效代码。谁能帮我在 AR Core 上做同样的事情
switch (Input.touchCount) {
case 1:
if (touch.phase == TouchPhase.Began || touch.phase == TouchPhase.Moved) {
var screenPosition = Camera.main.ScreenToViewportPoint(touch.position);
ARPoint point = new ARPoint {
x = screenPosition.x,
y = screenPosition.y
};
// prioritize reults types
ARHitTestResultType[] resultTypes = {
//ARHitTestResultType.ARHitTestResultTypeExistingPlaneUsingExtent,
// if you want to use infinite planes use this:
ARHitTestResultType.ARHitTestResultTypeExistingPlane,
ARHitTestResultType.ARHitTestResultTypeHorizontalPlane,
ARHitTestResultType.ARHitTestResultTypeFeaturePoint
};
foreach (ARHitTestResultType resultType in resultTypes) {
if (HitTestWithResultType(point, resultType)) {
return;
}
}
}
break;
case 2:
if (touch.phase == TouchPhase.Moved || touch.phase == TouchPhase.Ended) {
Vector2 direction = touch.deltaPosition;
float yAngleIncrementVal = touch.deltaPosition.magnitude;
Vector3 currentRotation = transform.rotation.eulerAngles;
if (direction.x > 0) {
currentRotation.y += (yAngleIncrementVal * rotationScale);
}
else {
currentRotation.y -= (yAngleIncrementVal * rotationScale);
}
transform.rotation = Quaternion.Euler(currentRotation);
}
break;
}
}
此脚本将附加到将在平面上移动的游戏对象。如何拖动游戏对象并更新锚点以使其保持在平面上。谢谢你
【问题讨论】: