够了,我会踩着我的骄傲!
我正在使用MRTK v2,并且工作正常,除了在某些点上我想关闭从运动控制器延伸到对象的线,这提供了输入。在环顾四周并试图在MRTK文档中找到它(这应该很容易,对吧?)之后,我仍然在撞墙,它开始痛了……
MRTK文档很好地解释了如何在此处配置它:
但我希望在脚本中做到这一点,在我的应用程序中根据需要启用和禁用它。
你知道该怎么做吗?
非常感谢!
发布于 2020-03-20 04:04:10
回答了我自己的问题。简单:
PointerUtils.SetMotionControllerRayPointerBehavior(PointerBehavior.AlwaysOff);
发布于 2019-06-04 08:09:29
问得好!这里有一种对我有效的方法。您可以在以下存储库中查看我的解决方案:https://github.com/julenka/MixedRealityToolkit-Unity/tree/so/linepointer_off。打开场景Assets/TurnOffLinePointerTest.unity,然后使用手动模拟按下按钮。打开/关闭指针的代码在Assets/PointerConfigurationExample.cs中。
注意:之所以需要使用这种修改中介而不是直接设置myPointer.IsActive = false的方法,是因为默认中介每一帧都会覆盖这些值。幸运的是,您可以自定义此行为。
步骤1:稍微更新一下MRTK,以便可以访问PointerMediator
将更改from this commit应用于您的MRTK克隆。此更改更新了MRTK中的FocusProvider以使PointerMediator可公开访问,并通过更新要保护的字段而不是私有字段,并使方法成为虚拟的,从而使DefaultPointerMediator可扩展。请参阅直接在MRTK中实现此更改的this pull request。
第2步:创建将关闭远指针的自定义PointerMediator
创建一个自定义指针中介器,如the one from this commit。
using System.Collections.Generic;
using Microsoft.MixedReality.Toolkit.Input;
public class CustomPointerMediator : DefaultPointerMediator
{
public bool FarPointersDisabled {get; set;}
public override void UpdatePointers()
{
base.UpdatePointers();
if (FarPointersDisabled)
{
foreach(var pointer in farInteractPointers)
{
pointer.IsActive = false;
}
}
}
}请注意,此中介器扩展了DefaultPointerMediator,因此它可以适应几乎所有的默认中介器逻辑。确保您已经完全应用了更改from the first commit,否则您将无法扩展DefaultPointerMediator。
步骤3:告诉MRTK使用您的自定义指针中介器
在您的指针配置文件中,将MRTK配置为使用自定义指针中介器,而不是默认的指针中介器。请注意,在图片中,我已经创建了一个自定义指针配置文件作为自定义输入系统的一部分(不要修改默认配置文件,否则当您更新MRTK时,您的更改可能会被覆盖)。

步骤4:使用自定义中介器打开/关闭行指针的组件
现在,您可以编写组件,该组件将使用您的自定义中介器来打开和关闭行指针。
public class PointerConfigurationExample : MonoBehaviour
{
/* Turns off all far interaction pointers */
public void TurnOffFarPointers()
{
Debug.Log("Line pointers off");
SetFarPointersDisabled(true);
}
public void TurnOnFarPointers()
{
Debug.Log("Line pointers on");
SetFarPointersDisabled(false);
}
private void SetFarPointersDisabled(bool isDisabled)
{
FocusProvider focusProvider = (FocusProvider) MixedRealityToolkit.InputSystem.FocusProvider;
if (focusProvider != null)
{
foreach(var mediator in focusProvider.PointerMediators)
{
// Note: you could check here to make sure you only disable pointers for hands
CustomPointerMediator myMediator = (CustomPointerMediator) (mediator.Value);
if (myMediator != null)
{
myMediator.FarPointersDisabled = isDisabled;
}
}
}
}
}https://stackoverflow.com/questions/56248329
复制相似问题