免责声明:我对 Unity3D 和 ARCore 还很陌生,所以请耐心等待。

我在 Unity3D 中使用 ARCore 创建一个场景,用户可以在其中选择屏幕上 ScrollView 中的模型并使用 Google 的 ARCore 框架放置它们。

到目前为止,我有它的工作;用户触摸 ScrollView 中的模型(在 Panel 屏幕上显示为当前选定的模型,因为我的计划是让 ScrollView 切换可见性以获得更多屏幕 View 空间)。

问题在于,当用户选择一个模型时,ARCore 会将模型放置在 ScrollView 和所选模型 Panel 对象所在的检测平面上(即使您第一次触摸开始滚动 ScrollView )。请参阅下文以帮助形象化。

android - 当用户触摸游戏对象时,如何阻止 ARCore 模型放置?-LMLPHP

我怎样才能让 ARCore 到 而不是 将对象放在 ScrollViewPanel 后面?我尝试的是向我的 Controller (实际上只是 Google HelloARController)添加一组对象,我想阻止 ARCore 的 Raycast 并使用 foreach 遍历它们以查看 Raycast 是否命中集合中的 GameObjects

Touch touch;
if (Input.touchCount < 1 || (touch = Input.GetTouch(0)).phase != TouchPhase.Began)
{
    return;
}

//my code; above is Google's
foreach (var item in BlockingObjects) { //BlockingObjects is a List<GameObject>
    if (IsTouchInObject(FirstPersonCamera.ScreenPointToRay(touch.position), item)) {
        return;
    }
}
//end of my code; below is Google's

TrackableHit hit;
TrackableHitFlag raycastFilter = TrackableHitFlag.PlaneWithinBounds | TrackableHitFlag.PlaneWithinPolygon;
IsTouchInObject 函数定义如下:
private bool IsTouchInObject(Ray ray, GameObject obj) {
    RaycastHit rch;
    Physics.Raycast (ray, out rch);
    return (rch.collider != null);
}

失败的是 rch.collider 总是 null (我知道我根本没有针对对象进行测试,一旦我可以让 RaycastGameObject 实际发生冲突,我就会担心这一点)。我尝试将 Physics/Physics2DRaycastHit/RacastHit2D 一起使用,并将 BoxCollider/BoxCollider2D 组件附加到我想检测命中的对象上,但我所做的一切都不起作用。

(此解决方案取自 Unity3D 论坛上的某些内容,其中有人有类似问题,但 AR 没有,他们有自己的 3D 世界和 2D 叠加。我找不到该论坛帖子提供引用,抱歉)。

任何帮助将不胜感激。

编辑/注意: 我现在注意到 Graphic Raycaster 上有一个 Canvas 组件,其中包含我的 ScrollViewPanel 。我尝试将 Blocking Objects 设置为 Two D (同时将 Box Collider 2D 添加到 ScrollViewPanel )和 Blocking MaskIgnore Raycast (以及其他一些东西),但无济于事。是否有这些属性的值组合可以做到这一点?

本着今天的精神:

帮助我,StackOverflow...呃...Kenobi...你是我唯一的希望。

最佳答案

您是否尝试过用以下方式包装 Raycast:

 if (!EventSystem.current.IsPointerOverGameObject(touch.fingerId)) {...}

https://answers.unity.com/questions/1406243/ui-in-arcore-helloar-example.html

关于android - 当用户触摸游戏对象时,如何阻止 ARCore 模型放置?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/47839170/

10-12 02:17