You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity/MRTK中Hololens 2交互手柄代理操控异常问题

HoloLens 2 + MRTK 容器交互代理问题解决方案

一、层级与碰撞体优先级调整

  • 给代理Cube创建独立层级ProxyInteraction,将原容器父物体的Box Collider移到代理Cube上,容器本身(AnchoredContainer)移除碰撞体。
  • 把容器内的单个元素统一放到InnerElements层级,确保MRTK交互系统同时检测ProxyInteraction和InnerElements两个层级。
  • 调整代理Cube的碰撞体范围:仅覆盖容器外围交互区域,比容器Bounds略大但避开内部元素的碰撞体,避免遮挡子元素的交互检测。

二、BoundsControl 参数修正

  • 代理Cube仅保留NearInteractionGrabbable脚本,不要挂载ObjectManipulator;ObjectManipulator和BoundsControl只挂载在AnchoredContainer上。
  • 在BoundsControl的Inspector面板中调整以下参数:
    • 「Handle Settings」:提高Minimum Handle Scale至0.15以上,避免缩放后手柄过小无法被检测;开启Handle Always Visible防止手柄隐藏;适当放大Handle Collider Size,提升手部/射线命中概率。
    • 「Solver Settings」:关闭Use Scale For Bounds,改用Fixed Bounds Size或基于容器渲染网格计算Bounds,避免代理Cube碰撞体干扰Bounds计算。

三、代理同步脚本优化

替换原同步逻辑,通过MRTK交互事件传递操控状态,避免Transform直接同步导致的帧冲突:

using UnityEngine;
using Microsoft.MixedReality.Toolkit.UI;

public class ProxyContainerSync : MonoBehaviour
{
    [SerializeField] private GameObject targetContainer;
    private ObjectManipulator _containerManipulator;
    private NearInteractionGrabbable _proxyGrabbable;

    void Awake()
    {
        _containerManipulator = targetContainer.GetComponent<ObjectManipulator>();
        _proxyGrabbable = GetComponent<NearInteractionGrabbable>();
        
        _proxyGrabbable.OnGrabbed.AddListener(OnProxyGrabbed);
        _proxyGrabbable.OnReleased.AddListener(OnProxyReleased);
    }

    void OnProxyGrabbed()
    {
        _containerManipulator.ForceSetGrabbed(true);
    }

    void OnProxyReleased()
    {
        _containerManipulator.ForceSetGrabbed(false);
    }

    void LateUpdate()
    {
        if (_proxyGrabbable.IsGrabbed)
        {
            targetContainer.transform.position = transform.position;
            targetContainer.transform.rotation = transform.rotation;
        }
    }
}
  • 确保AnchoredContainer的ObjectManipulator中开启Allow Manipulation On Grab,保证代理的操控事件能正确传递到容器。

四、MRTK交互层级配置

打开MRTK的Input System Profile,依次调整:

  • 「Pointers」→「Shell Hand Ray Pointer」:在Raycast Layer Masks中添加ProxyInteraction和InnerElements层级,移除容器原层级(若存在)。
  • 「Near Interaction」→「Near Interaction Touchable Settings」:将上述两个层级加入检测列表,确保手部直接交互能覆盖代理和内部元素。

五、调试辅助

  • 开启Unity编辑器的Gizmos→Colliders选项,实时查看碰撞体范围,确认代理Cube未遮挡内部元素碰撞体。
  • 调整MRTK「Input System Profile」中的Touch Sensitivity至0.1左右,降低手部微小移动导致的手柄丢失概率。

内容的提问来源于stack exchange,提问作者Alex

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.21 23:25:33