当一个对象在 Hololens 中的另一个对象内部时,如何选择内部游戏对象?

编程入门 行业动态 更新时间:2024-10-27 11:19:21
本文介绍了当一个对象在 Hololens 中的另一个对象内部时,如何选择内部游戏对象?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在尝试创建一个应用程序,其中一个游戏对象可以位于另一个游戏对象中.我希望能够在内部游戏对象位于外部游戏对象内部时移动内部游戏对象.当用户看着内部对象并执行空中敲击手势时,外部对象是移动的对象.有什么办法可以在 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 Where 和 Linq 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屋!

更多推荐

[db:关键词]

本文发布于:2023-04-28 17:28:15,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1176882.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:对象   如何选择   游戏   Hololens

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!