当一个对象在 Hololens 中的另一个对象内部时,如何选择内部游戏对象? [英] How to select the inner gameobject when an object is inside another in hololens?

查看:31
本文介绍了当一个对象在 Hololens 中的另一个对象内部时,如何选择内部游戏对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试创建一个应用程序,其中一个游戏对象可以位于另一个游戏对象中.我希望能够在内部游戏对象位于外部游戏对象内部时移动内部游戏对象.当用户看着内部对象并执行空中敲击手势时,外部对象是移动的对象.有什么办法可以在 MRTK 中实现这种行为.

I am trying to create an application where a gameobject can be inside another gameobject. I want to be able to move the inner gameobject while it is inside the outer one. When the user is looking at the inner one, and does the air tap gesture the outer object is the one that moves. Is there any way to implement this behavior in MRTK.

推荐答案

我想你的意思是:外部对象的碰撞器阻挡了光线投射,所以你无法击中内部碰撞器.

I think what you mean is: The outer object's Collider is blocking the Raycast so you can't hit the inner Collider.

尝试使用 RaycastAll 然后检查子对象是否被命中,如果是,则选择子对象,如果是父对象.

try using getting all of them using RaycastAll and then check whether a child object is hit if yes select the child instead if the parent.

我将使用 Linq WhereLinq Any 为此

I will use Linq Where and Linq Any for that

类似的东西

using System.Linq;

...

var hits = Physics.RaycastAll(transform.position, transform.forward, 100.0F);

GameObject selectedObject = null;

// go through all hits
foreach (var hit in hits)
{
    // get all children colliders of the hit object
    var colliders = hit.gameObject.GetComponentsInChildren<Collider>(true);
    // since these will also include this hit collider itself filter it/them out
    var childrenColliders =  colliders.Where(c => c.gameObject != hit.gameObject);

    // Finally check if any children is contained in the hits
    // if yes then this object can not be selected
    if(childrenColliders.Any(c => hits.Contains(c)) continue;

    // otherwise you have found a child that has no further hit children
    selectedObject = hit.gameObject;

    break;
}

这篇关于当一个对象在 Hololens 中的另一个对象内部时,如何选择内部游戏对象?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆