mrtk - 如何暂时禁用 MixedRealityToolkit.InputSystem?
问题描述
例如,一旦用户单击按钮,我想在某些转换期间禁用所有输入。
当然,我可以禁用该按钮,但我正在寻找更通用的解决方案,以避免每个按钮再次出现相同的错误。
我尝试了PushInputDisable
/ PopInputDisable
,这似乎是我正在寻找的东西,但它inputsimulationservice
在弹出后会出现问题,并且总体而言,从 inputsystem 引发的大多数输入事件都没有插入到该禁用堆栈中。
我可以制作一个实现所有接口并使用的输入处理程序PushModalInputHandler
,但这对于我想要实现的目标来说似乎有点矫枉过正。另外,例如,它可能无法捕捉到语音命令。
任何简单的解决方案?
解决方案
您可以使用以下代码来禁用和启用输入系统:
public class DisableInputSystemTest : MonoBehaviour
{
private IMixedRealityInputSystem inputSystem = null;
private IMixedRealityInputSystem InputSystem
{
get
{
if (inputSystem == null)
{
MixedRealityServiceRegistry.TryGetService<IMixedRealityInputSystem>(out inputSystem);
}
return inputSystem;
}
}
public void DisableInputSystem()
{
InputSystem.Disable();
}
public void EnableInputSystem()
{
InputSystem.Enable();
}
}
请注意,在最新mrtk_development
的分支中存在一个错误(问题5085),在重新启用后,您将获得大量空指针,说“NullReferenceException:对象引用未设置为 Microsoft.MixedReality.Toolkit.Input.FocusProvider.RegisterPointers 对象的实例(Microsoft.MixedReality.Toolkit.Input.IMixedRealityInputSource inputSource) (在 Assets/MixedRealityToolkit.Services/InputSystem/FocusProvider.cs:689)"
要解决此问题,请将以下代码从MixedRealityInputSystem.Initalize()
的开头移动MixedRealityInputSystem.Enable()
:
MixedRealityInputSystemProfile profile = ConfigurationProfile as MixedRealityInputSystemProfile;
if (profile.PointerProfile != null)
{
if (profile.PointerProfile.GazeProviderType?.Type != null)
{
GazeProvider = CameraCache.Main.gameObject.EnsureComponent(profile.PointerProfile.GazeProviderType.Type) as IMixedRealityGazeProvider;
GazeProvider.GazeCursorPrefab = profile.PointerProfile.GazeCursorPrefab;
// Current implementation implements both provider types in one concrete class.
EyeGazeProvider = GazeProvider as IMixedRealityEyeGazeProvider;
}
else
{
Debug.LogError("The Input system is missing the required GazeProviderType!");
return;
}
}
else
{
Debug.LogError("The Input system is missing the required Pointer Profile!");
return;
}
推荐阅读
- reporting-services - SSRS 空白问题
- loopback - Loopback:远程方法 - 多次更新
- styles - 如何更改 Appwidget 文本的重力和样式
- javascript - React 样式组件中的“this”关键字有问题吗?
- kotlin - 如何在 kotlin 中使用 File.walk
- python - 消除 OpenCV EM 检测到的误报
- javascript - scrollTop() 在移动浏览器上不起作用
- java - Selenium WebDriver:如何在跨度下拉列表中选择一个值?
- java - java.lang.NoSuchMethodError 使用 FirebaseOptions.Builder 将 java 连接到 firebase
- javascript - 组件的多个实例,试图删除 onclick - 但总是最后一个被删除