您可以使用以下代码来禁用和启用输入系统:
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;
}