public IEnumerator TestSpeechEventCallsForGlobalHandlers() { // We need Gaze Cursor in this test to use it as source to emit events. IMixedRealityInputSystem inputSystem = null; MixedRealityServiceRegistry.TryGetService(out inputSystem); var object1 = new GameObject("Object 1"); // These 2 handlers are independent var objectBasedListener = object1.AddComponent <TestInputGlobalListenerObjectBased>(); var handlerBasedListener = object1.AddComponent <TestInputGlobalListenerHandlerBasedSpeechHandler>(); var object2 = new GameObject("Object 2"); // These 2 handlers are independent var handlerBasedListener1 = object2.AddComponent <TestInputGlobalListenerHandlerBasedAllHandlers>(); var handlerBasedListener2 = object2.AddComponent <TestInputGlobalListenerHandlerBasedSpeechHandler>(); yield return(null); LogAssert.Expect(LogType.Error, new Regex("Detected simultaneous usage of IMixedRealityEventSystem.Register and IMixedRealityEventSystem.RegisterHandler")); // Emit speech event, which should be received by all handlers. var gazeInputSource = inputSystem.DetectedInputSources.Where(x => x.SourceName.Equals("Gaze")).First(); inputSystem.RaiseSpeechCommandRecognized(gazeInputSource, RecognitionConfidenceLevel.High, new System.TimeSpan(), System.DateTime.Now, new SpeechCommands("menu", KeyCode.Alpha1, MixedRealityInputAction.None)); Assert.Zero(objectBasedListener.pointerClickedCount, "Pointer clicked event is received by old API handler."); Assert.Zero(objectBasedListener.pointerDownCount, "Pointer down event is received by old API handler."); Assert.Zero(objectBasedListener.pointerUpCount, "Pointer up event is received by old API handler."); Assert.Zero(objectBasedListener.pointerDraggedCount, "Pointer dragged event is received by old API handler."); Assert.AreEqual(objectBasedListener.speechCount, 1, "Speech event is not received by old API handler."); Assert.Zero(handlerBasedListener.pointerClickedCount, "Pointer clicked event is received by new API handler."); Assert.Zero(handlerBasedListener.pointerDownCount, "Pointer down event is received by new API handler."); Assert.Zero(handlerBasedListener.pointerUpCount, "Pointer up event is received by new API handler."); Assert.Zero(handlerBasedListener.pointerDraggedCount, "Pointer dragged event is received by new API handler."); Assert.AreEqual(handlerBasedListener.speechCount, 1, "Speech event is not received by new API handler."); Assert.Zero(handlerBasedListener1.pointerClickedCount, "Pointer clicked event is received by all-handlers component."); Assert.Zero(handlerBasedListener1.pointerDownCount, "Pointer down event is received by all-handlers component."); Assert.Zero(handlerBasedListener1.pointerUpCount, "Pointer up event is received by all-handlers component."); Assert.Zero(handlerBasedListener1.pointerDraggedCount, "Pointer dragged event is received by all-handlers component."); Assert.AreEqual(handlerBasedListener1.speechCount, 1, "Speech event is not received by all-handlers component."); // No pointer clicked event: Assert.Zero(handlerBasedListener2.pointerClickedCount, "Pointer clicked event is received by speech-handler component."); Assert.Zero(handlerBasedListener2.pointerDownCount, "Pointer down event is received by speech-handler component."); Assert.Zero(handlerBasedListener2.pointerUpCount, "Pointer up event is received by speech-handler component."); Assert.Zero(handlerBasedListener2.pointerDraggedCount, "Pointer dragged event is received by speech-handler component."); Assert.AreEqual(handlerBasedListener2.speechCount, 1, "Speech event is not received by speech-handler component."); Object.Destroy(object1); Object.Destroy(object2); yield return(null); }
public void Destroy() { IMixedRealityInputSystem inputSystem; if (MixedRealityServiceRegistry.TryGetService <IMixedRealityInputSystem>(out inputSystem)) { inputSystem.UnregisterHandler <IMixedRealityPointerHandler>(this); } }
/// <summary> /// Initializes the MRTK such that there are no other input system listeners /// (global or per-interface). /// </summary> internal static IEnumerator SetupMrtkWithoutGlobalInputHandlers() { if (!MixedRealityToolkit.IsInitialized) { Debug.LogError("MixedRealityToolkit must be initialized before it can be configured."); yield break; } IMixedRealityInputSystem inputSystem = null; MixedRealityServiceRegistry.TryGetService(out inputSystem); Assert.IsNotNull(inputSystem, "Input system must be initialized"); // Let input system to register all cursors and managers. yield return(null); // Switch off / Destroy all input components, which listen to global events UnityEngine.Object.Destroy(inputSystem.GazeProvider.GazeCursor as Behaviour); inputSystem.GazeProvider.Enabled = false; var diagnosticsVoiceControls = UnityEngine.Object.FindObjectsOfType <DiagnosticsSystemVoiceControls>(); foreach (var diagnosticsComponent in diagnosticsVoiceControls) { diagnosticsComponent.enabled = false; } // Let objects be destroyed yield return(null); // Forcibly unregister all other input event listeners. BaseEventSystem baseEventSystem = inputSystem as BaseEventSystem; MethodInfo unregisterHandler = baseEventSystem.GetType().GetMethod("UnregisterHandler"); // Since we are iterating over and removing these values, we need to snapshot them // before calling UnregisterHandler on each handler. var eventHandlersByType = new Dictionary <System.Type, List <BaseEventSystem.EventHandlerEntry> >(((BaseEventSystem)inputSystem).EventHandlersByType); foreach (var typeToEventHandlers in eventHandlersByType) { var handlerEntries = new List <BaseEventSystem.EventHandlerEntry>(typeToEventHandlers.Value); foreach (var handlerEntry in handlerEntries) { unregisterHandler.MakeGenericMethod(typeToEventHandlers.Key) .Invoke(baseEventSystem, new object[] { handlerEntry.handler }); } } // Check that input system is clean CollectionAssert.IsEmpty(((BaseEventSystem)inputSystem).EventListeners, "Input event system handler registry is not empty in the beginning of the test."); CollectionAssert.IsEmpty(((BaseEventSystem)inputSystem).EventHandlersByType, "Input event system handler registry is not empty in the beginning of the test."); yield return(null); }
/// <inheritdoc /> public bool UnregisterService<T>(T serviceInstance) where T : IMixedRealityService { if (serviceInstance == null) { return false; } Type interfaceType = typeof(T); if (!registeredServices.ContainsKey(interfaceType)) { return false; } registeredServices.Remove(interfaceType); return MixedRealityServiceRegistry.RemoveService<T>(serviceInstance, this); }
/// <summary> /// Uninitialize a service. /// </summary> /// <typeparam name="T">The interface type for the service to uninitialize.</typeparam> protected virtual void Uninitialize <T>() where T : IMixedRealityService { T serviceInstance = FindService <T>(); if (serviceInstance != null) { registeredServices.Remove(typeof(T)); MixedRealityServiceRegistry.RemoveService <T>(serviceInstance, this); } }
public void TestGetSpatialAwarenessSystem() { TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(true); // Retrieve Spatial Awareness System IMixedRealitySpatialAwarenessSystem spatialAwarenessSystem = null; MixedRealityServiceRegistry.TryGetService(out spatialAwarenessSystem); // Tests Assert.IsNotNull(spatialAwarenessSystem); }
public void Test02_TestGetMixedRealityInputSystem() { TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(true); // Retrieve Input System IMixedRealityInputSystem inputSystem = null; MixedRealityServiceRegistry.TryGetService <IMixedRealityInputSystem>(out inputSystem); // Tests Assert.IsNotNull(inputSystem); }
public void CreateInputSystem() { TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(); MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile = CreateDefaultInputSystemProfile(); // Add Input System bool didRegister = MixedRealityToolkit.Instance.RegisterService <IMixedRealityInputSystem>(new MixedRealityInputSystem(MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile)); // Tests Assert.IsTrue(didRegister); Assert.AreEqual(1, MixedRealityServiceRegistry.GetAllServices().Count); Assert.IsNotNull(MixedRealityToolkit.Instance.GetService <IMixedRealityInputSystem>()); }
private void OnDisable() { Camera.onPostRender -= PostRender; ISceneTransitionService transitionService; if (MixedRealityServiceRegistry.TryGetService <ISceneTransitionService>(out transitionService)) { transitionService.OnTransitionStarted -= OnTransitionStarted; } updateWisps = false; }
public void TestRegisterMixedRealityExtensionService() { TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(); // Register ITestExtensionService1 MixedRealityToolkit.Instance.RegisterService <ITestExtensionService1>(new TestExtensionService1("Test ExtensionService 1", 10, null)); // Retrieve ITestExtensionService1 Assert.IsNotNull(MixedRealityToolkit.Instance.GetService <IMixedRealityExtensionService>()); Assert.IsNotNull(MixedRealityToolkit.Instance.GetService <ITestExtensionService1>()); Assert.IsNotNull(MixedRealityToolkit.Instance.GetService <TestExtensionService1>()); Assert.IsNotNull(MixedRealityToolkit.Instance.GetService <BaseExtensionService>()); Assert.AreEqual(1, MixedRealityServiceRegistry.GetAllServices().Count); }
public void TestDataProviderRegistration() { TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(); MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile = AssetDatabase.LoadAssetAtPath <MixedRealityInputSystemProfile>(TestInputSystemProfilePath); var inputSystem = new MixedRealityInputSystem(MixedRealityToolkit.Instance.ActiveProfile.InputSystemProfile); Assert.IsTrue(MixedRealityToolkit.Instance.RegisterService <IMixedRealityInputSystem>(inputSystem)); // Since EditMode, we have to auto-enable MRTK input system ourselves MixedRealityToolkit.Instance.EnableAllServicesByType(typeof(IMixedRealityInputSystem)); Assert.AreEqual(1, MixedRealityServiceRegistry.GetAllServices().Count); Assert.IsNotNull(MixedRealityToolkit.Instance.GetService <IMixedRealityInputSystem>()); var dataProviderAccess = (inputSystem as IMixedRealityDataProviderAccess); Assert.IsNotNull(dataProviderAccess); var dataProvider = dataProviderAccess.GetDataProvider <TestInputDataProvider>(); Assert.IsNotNull(dataProvider); Assert.IsTrue(dataProvider.IsInitialized); Assert.IsTrue(dataProvider.IsEnabled); inputSystem.Disable(); Assert.IsFalse(dataProvider.IsEnabled); inputSystem.Enable(); // We still have reference to old dataProvider, check still disabled Assert.IsFalse(dataProvider.IsEnabled); // dataProvider has been unregistered in Disable and new one created by Enable. dataProvider = dataProviderAccess.GetDataProvider <TestInputDataProvider>(); Assert.IsNotNull(dataProvider); Assert.IsTrue(dataProvider.IsEnabled); inputSystem.Reset(); LogAssert.Expect(LogType.Log, "TestDataProvider Reset"); Assert.IsFalse(dataProvider.IsEnabled); // dataProvider has been unregistered and newly created in Reset dataProvider = dataProviderAccess.GetDataProvider <TestInputDataProvider>(); Assert.IsNotNull(dataProvider); Assert.IsTrue(dataProvider.IsInitialized); Assert.IsTrue(dataProvider.IsEnabled); }
public void TestRegisterMixedRealityExtensionServices() { TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(); // Add test ExtensionService MixedRealityToolkit.Instance.RegisterService <ITestExtensionService1>(new TestExtensionService1("Test ExtensionService 1", 10, null)); MixedRealityToolkit.Instance.RegisterService <ITestExtensionService2>(new TestExtensionService2("Test ExtensionService 2", 10, null)); // Retrieve all registered IMixedRealityExtensionServices var extensionServices = MixedRealityToolkit.Instance.GetServices <IMixedRealityExtensionService>(); var serviceCount = MixedRealityServiceRegistry.GetAllServices().Count; // Tests Assert.IsNotNull(MixedRealityToolkit.Instance.ActiveProfile); Assert.AreEqual(2, serviceCount); Assert.AreEqual(extensionServices.Count, serviceCount); }
public IEnumerator LoadHandInteractionExamplesScene() { AsyncOperation loadOp = SceneManager.LoadSceneAsync(HandInteractionExamplesSceneName); loadOp.allowSceneActivation = true; while (!loadOp.isDone) { yield return(null); } yield return(new WaitForSeconds(ScenePlayDuration)); IMixedRealityInputSystem inputSystem = null; MixedRealityServiceRegistry.TryGetService(out inputSystem); Assert.NotNull(inputSystem); }
/// <inheritdoc /> public bool RegisterService<T>(T serviceInstance) where T : IMixedRealityService { Type interfaceType = typeof(T); if (registeredServices.ContainsKey(interfaceType)) { Debug.LogError($"Failed to register {serviceInstance} service. There is already a registered service implementing {interfaceType}"); return false; } bool registered = MixedRealityServiceRegistry.AddService<T>(serviceInstance, this); if (registered) { registeredServices.Add(interfaceType, serviceInstance); } return registered; }
public IEnumerator TestGazeCursorArticulated() { TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(true); TestUtilities.InitializePlayspace(); RenderSettings.skybox = null; IMixedRealityInputSystem inputSystem; MixedRealityServiceRegistry.TryGetService(out inputSystem); Assert.IsNotNull(inputSystem, "MixedRealityInputSystem is null!"); yield return(null); // Verify that the gaze cursor is visible at the start Assert.IsTrue(inputSystem.GazeProvider.GazePointer.IsInteractionEnabled, "Gaze cursor should be visible at start"); // raise hand up -- gaze cursor should no longer be visible // disable user input InputSimulationService inputSimulationService = (inputSystem as IMixedRealityDataProviderAccess).GetDataProvider <InputSimulationService>(); Assert.IsNotNull(inputSimulationService, "InputSimulationService is null!"); inputSimulationService.UserInputEnabled = false; ArticulatedHandPose gesturePose = ArticulatedHandPose.GetGesturePose(ArticulatedHandPose.GestureId.Open); var handOpenPose = PlayModeTestUtilities.GenerateHandPose(ArticulatedHandPose.GestureId.Open, Handedness.Right, Vector3.forward * 0.1f); inputSimulationService.HandDataRight.Update(true, false, handOpenPose); yield return(null); // Gaze cursor should not be visible Assert.IsFalse(inputSystem.GazeProvider.GazePointer.IsInteractionEnabled, "Gaze cursor should not be visible when one articulated hand is up"); inputSimulationService.HandDataRight.Update(false, false, handOpenPose); yield return(null); // Say "select" to make gaze cursor active again // Really we need to tear down the scene and create it again but MRTK doesn't support that yet var gazeInputSource = inputSystem.DetectedInputSources.Where(x => x.SourceName.Equals("Gaze")).First(); inputSystem.RaiseSpeechCommandRecognized(gazeInputSource, RecognitionConfidenceLevel.High, new System.TimeSpan(), System.DateTime.Now, new SpeechCommands("select", KeyCode.Alpha1, MixedRealityInputAction.None)); yield return(null); Assert.IsTrue(inputSystem.GazeProvider.GazePointer.IsInteractionEnabled, "Gaze cursor should be visible after select command"); }
public IEnumerator TestToggleProfilerCommand() { // Confirm that the diagnostics system is enabled. IMixedRealityDiagnosticsSystem diagnosticsSystem = null; MixedRealityServiceRegistry.TryGetService <IMixedRealityDiagnosticsSystem>(out diagnosticsSystem); Assert.IsNotNull(diagnosticsSystem, "The diagnostics system is not enabled in the scene."); yield return(null); // This test uses the input system to simulate speech commands. IMixedRealityInputSystem inputSystem = null; MixedRealityServiceRegistry.TryGetService <IMixedRealityInputSystem>(out inputSystem); Assert.IsNotNull(inputSystem, "The input system is not enabled in the scene."); yield return(null); // Verify that the VisualProfiler is enabled. Assert.IsTrue(diagnosticsSystem.ShowProfiler, "The VisualProfiler is not active."); yield return(null); int frameDelay = 10; // Toggle the profiler visualization off. var gazeInputSource = inputSystem.DetectedInputSources.Where(x => x.SourceName.Equals("Gaze")).First(); inputSystem.RaiseSpeechCommandRecognized( gazeInputSource, RecognitionConfidenceLevel.High, new TimeSpan(), DateTime.Now, new SpeechCommands("toggle profiler", KeyCode.Alpha9, MixedRealityInputAction.None)); // It may take a few frames before the event is handled and the system responds to the state change. for (int i = 0; i < frameDelay; i++) { yield return(null); } // Verify that the VisualProfiler is disabled. Assert.IsFalse(diagnosticsSystem.ShowProfiler, "The VisualProfiler is active (should be inactive)."); yield return(null); }
/// <summary> /// Find the first detected hand controller of the given type with matching handedness. /// </summary> public static T FindHand <T>(Handedness handedness) where T : class, IMixedRealityHand { IMixedRealityInputSystem inputSystem = null; if (!MixedRealityServiceRegistry.TryGetService <IMixedRealityInputSystem>(out inputSystem)) { return(null); } foreach (var detectedController in inputSystem.DetectedControllers) { var hand = detectedController as T; if (hand != null) { if ((detectedController.ControllerHandedness & handedness) != 0) { return(hand); } } } return(null); }
public void TestUnregisterMixedRealityExtensionServicesByType() { TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(); // Add test ExtensionService MixedRealityToolkit.Instance.RegisterService <ITestExtensionService1>(new TestExtensionService1("Test ExtensionService 1", 10, null)); MixedRealityToolkit.Instance.RegisterService <ITestExtensionService2>(new TestExtensionService2("Test ExtensionService 2", 10, null)); // Retrieve all registered IMixedRealityExtensionServices var extensionServices = MixedRealityToolkit.Instance.GetServices <IMixedRealityExtensionService>(); var serviceCount = MixedRealityServiceRegistry.GetAllServices().Count; // Tests Assert.IsNotNull(MixedRealityToolkit.Instance.ActiveProfile); Assert.AreEqual(2, serviceCount); Assert.AreEqual(extensionServices.Count, serviceCount); // Retrieve services var extensionService1 = MixedRealityToolkit.Instance.GetService <ITestExtensionService1>(); var extensionService2 = MixedRealityToolkit.Instance.GetService <ITestExtensionService2>(); // Validate Assert.IsNotNull(extensionService1); Assert.IsNotNull(extensionService2); var success1 = MixedRealityToolkit.Instance.UnregisterService <ITestExtensionService1>(); var success2 = MixedRealityToolkit.Instance.UnregisterService <ITestExtensionService2>(); // Validate non-existent service var isService1Registered = MixedRealityToolkit.Instance.IsServiceRegistered <ITestExtensionService1>(); var isService2Registered = MixedRealityToolkit.Instance.IsServiceRegistered <ITestExtensionService2>(); // Tests Assert.IsTrue(success1); Assert.IsTrue(success2); Assert.IsFalse(isService1Registered); Assert.IsFalse(isService2Registered); Assert.IsEmpty(MixedRealityServiceRegistry.GetAllServices()); }
protected virtual bool DoesContextProhibitMenu() { bool contextProhibited = false; // See if we're close to the active surface if (FingerSurface.ActiveSurface != null) { float distToSurface = Vector3.Distance(FingerSurface.ActiveSurface.SurfacePosition, transform.position); if (distToSurface - FingerSurface.ActiveSurface.SurfaceRadius < disableDistance) { contextProhibited = true; } } // See if we're doing a transition ISceneTransitionService transitionService; if (MixedRealityServiceRegistry.TryGetService <ISceneTransitionService>(out transitionService) && transitionService.TransitionInProgress) { contextProhibited = true; } return(contextProhibited); }
public void TestUnregisterMixedRealityExtensionServiceByType() { TestUtilities.InitializeMixedRealityToolkitAndCreateScenes(); // Register ITestExtensionService1 MixedRealityToolkit.Instance.RegisterService <ITestExtensionService1>(new TestExtensionService1("Test ExtensionService 1", 10, null)); // Retrieve ITestExtensionService1 var extensionService1 = MixedRealityToolkit.Instance.GetService <ITestExtensionService1>(); // Tests Assert.IsNotNull(extensionService1); Assert.AreEqual(1, MixedRealityServiceRegistry.GetAllServices().Count); var success = MixedRealityToolkit.Instance.UnregisterService <ITestExtensionService1>(); // Validate non-existent service var isServiceRegistered = MixedRealityToolkit.Instance.IsServiceRegistered <ITestExtensionService1>(); // Tests Assert.IsTrue(success); Assert.IsFalse(isServiceRegistered); Assert.IsEmpty(MixedRealityServiceRegistry.GetAllServices()); }
private static void UpdateServiceFacades() { if (!MixedRealityToolkit.IsInitialized) { // Nothing to do here. return; } if (EditorApplication.isCompiling) { // Wait for compilation to complete before creating or destroying facades return; } if (Application.isPlaying && Time.frameCount == previousFrameCount) { // Only update once per frame (SceneGUI + Update may result in multiple calls) return; } previousFrameCount = Time.frameCount; if (previousActiveInstance != null && MixedRealityToolkit.Instance != previousActiveInstance) { // We've changed active instances. Destroy all children in the previous instance. DestroyAllChildren(previousActiveInstance); } if (MixedRealityToolkit.Instance.HasActiveProfile && !MixedRealityToolkit.Instance.ActiveProfile.UseServiceInspectors) { // If we're not using inspectors, destroy them all now DestroyAllChildren(MixedRealityToolkit.Instance); return; } servicesToSort.Clear(); servicesToSort.AddRange(MixedRealityServiceRegistry.GetAllServices()); IMixedRealityInputSystem inputSystem; MixedRealityServiceRegistry.TryGetService(out inputSystem); if (inputSystem != null) { servicesToSort.AddRange((inputSystem as IMixedRealityDataProviderAccess).GetDataProviders()); } servicesToSort.Sort( delegate(IMixedRealityService s1, IMixedRealityService s2) { string s1Name = s1.GetType().Name; string s2Name = s2.GetType().Name; if (s1Name == s2Name) { return(s1.Priority.CompareTo(s2.Priority)); } return(s1Name.CompareTo(s2Name)); }); for (int i = 0; i < servicesToSort.Count; i++) { CreateFacade(MixedRealityToolkit.Instance.transform, servicesToSort[i], i); } // Delete any stragglers childrenToDelete.Clear(); for (int i = servicesToSort.Count; i < MixedRealityToolkit.Instance.transform.childCount; i++) { childrenToDelete.Add(MixedRealityToolkit.Instance.transform.GetChild(i)); } foreach (Transform childToDelete in childrenToDelete) { if (Application.isPlaying) { GameObject.Destroy(childToDelete.gameObject); } else { GameObject.DestroyImmediate(childToDelete.gameObject); } } try { // Update all self-registered facades foreach (ServiceFacade facade in ServiceFacade.ActiveFacadeObjects) { if (facade == null) { continue; } facade.CheckIfStillValid(); } } catch (Exception) { Debug.LogWarning("Service Facades should remain parented under the MixedRealityToolkit instance."); } previousActiveInstance = MixedRealityToolkit.Instance; }
public async Task PlaceNewSurface() { await Task.Yield(); // Find our finger surface FingerSurface fingerSurface = GameObject.FindObjectOfType <FingerSurface>(); float fingerSurfaceRadius = fingerSurface.SurfaceRadius; // Use our camera to place the surface placementTransform.position = CameraCache.Main.transform.position; placementTransform.rotation = CameraCache.Main.transform.rotation; // Only rotate on y axis Vector3 eulerAngles = placementTransform.eulerAngles; eulerAngles.x = 0; eulerAngles.z = 0; placementTransform.eulerAngles = eulerAngles; Vector3 targetSurfacePosition = placementTransform.TransformPoint(defaultOffset); if (fingerSurface == null) { Debug.LogError("No surface found in surface placement."); return; } if (placedOnce) { // If we've placed it once already, the current placement might still be valid. if (Vector3.Distance(CameraCache.Main.transform.position, currentSurfacePosition) < maxRepositionDistance) { targetSurfacePosition = currentSurfacePosition; } } else if (useSpatialUnderstanding) { IMixedRealitySpatialAwarenessSystem spatial; if (!MixedRealityServiceRegistry.TryGetService <IMixedRealitySpatialAwarenessSystem>(out spatial)) { Debug.LogError("This component requires a IMixedRealitySpatialAwarenessSystem to be enabled."); return; } // Start the observers creating meshes again spatial.ResumeObservers(); // Wait until our spatial understanding has delivered some meshes timeStarted = Time.time; while (spatial.SpatialAwarenessObjectParent.transform.childCount == 0) { if ((Time.time - timeStarted > timeOut)) { break; } await Task.Yield(); } // While our placement sphere overlaps with spatial awareness objects, move it progressively closer to the user bool collidesWithWalls = true; timeStarted = Time.time; while (collidesWithWalls) { if (Time.time - timeStarted > timeOut) { break; } Collider[] colliders = Physics.OverlapSphere(targetSurfacePosition, fingerSurfaceRadius, spatialAwarenessMask); if (colliders.Length == 0) { collidesWithWalls = false; } else { targetSurfacePosition = Vector3.MoveTowards(targetSurfacePosition, CameraCache.Main.transform.position, moveIncrement); } await Task.Yield(); } // Suspeend observers now that we're all set spatial.SuspendObservers(); } currentSurfacePosition = targetSurfacePosition; placedOnce = true; // Tell the surface to initialize fingerSurface.Initialize(targetSurfacePosition); }
public override void Initialize(Vector3 surfacePosition) { base.Initialize(surfacePosition); ISceneTransitionService transitionService; if (MixedRealityServiceRegistry.TryGetService <ISceneTransitionService>(out transitionService)) { transitionService.OnTransitionStarted += OnTransitionStarted; } tileScale = 1f / numColumns; tileOffsets = new Vector2[numTiles]; int tileNum = 0; for (int row = 0; row < numRows; row++) { for (int column = 0; column < numColumns; column++) { Vector2 uv = Vector2.zero; uv.x = tileScale * column; uv.y = (tileScale * -row) - tileScale; tileOffsets[tileNum] = uv; tileNum++; if (tileNum >= numTiles) { break; } } if (tileNum >= numTiles) { break; } } noise = new FastSimplexNoise(); transitionColor = Color.black; forces = new Force[fingers.Length]; fingertips = new Fingertip[fingers.Length]; wisps = new Wisp[numWisps]; quads = new Quad[numWisps]; finalQuads = new Quad[numWisps]; renderOrder = new List <RenderOrder>(numWisps); for (int i = 0; i < numWisps; i++) { Wisp wisp = new Wisp(); wisp.TargetPoint = SurfacePosition + (Random.insideUnitSphere * SurfaceRadius); wisp.Point = wisp.TargetPoint; wisp.Velocity = Random.insideUnitSphere * initialVelocity; wisp.TargetRadius = Mathf.Lerp(wispSize.x, wispSize.y, (float)noise.Evaluate(wisp.Point.x, wisp.Point.y, wisp.Point.z)); wisp.Radius = wisp.TargetRadius; wisp.TileOffset = Random.Range(0, numTiles); wisps[i] = wisp; Quad quad = Quad.FromWisp(baseWispColor.Evaluate(Random.Range(0f, 1f)), wisp.Point, wisp.Radius, Vector3.up, Vector3.right, tileOffsets[wisp.TileOffset], tileScale); quad.Color = transitionColor; quads[i] = quad; finalQuads[i] = quads[i]; RenderOrder r = new RenderOrder(); renderOrder.Add(r); } for (int i = 0; i < fingers.Length; i++) { Transform finger = fingers[i]; Fingertip fingertip = fingertips[i]; fingertip.Block = new MaterialPropertyBlock(); fingertip.Trail = finger.GetComponentInChildren <TrailRenderer>(); fingertip.Mesh = finger.GetComponentInChildren <MeshRenderer>(); fingertip.PingAudio = finger.GetComponentInChildren <AudioSource>(); fingertips[i] = fingertip; } Camera.onPostRender += PostRender; updateWisps = true; Task task = UpdateWispsTask(); }
private static HashSet <IMixedRealityService> GetAllServices() { HashSet <IMixedRealityService> serviceList = new HashSet <IMixedRealityService>(MixedRealityServiceRegistry.GetAllServices()); // These are core systems that are likely out-of-box services and known to have register DataProviders // Search for any dataproviders that service facades can be created for var dataProviderManagers = new IMixedRealityService[] { CoreServices.InputSystem, CoreServices.SpatialAwarenessSystem }; foreach (var system in dataProviderManagers) { var dataProviderAccess = system as IMixedRealityDataProviderAccess; if (dataProviderAccess != null) { foreach (var dataProvider in dataProviderAccess.GetDataProviders()) { serviceList.Add(dataProvider); } } } return(serviceList); }
public IEnumerator TestHandlerBasedEventRegistration() { // Need to remove cursors and other global event handlers yield return(PlayModeTestUtilities.SetupMrtkWithoutGlobalInputHandlers()); IMixedRealityInputSystem iInputSystem = null; MixedRealityServiceRegistry.TryGetService(out iInputSystem); BaseEventSystem inputSystem = (BaseEventSystem)iInputSystem; var object1 = new GameObject("Object"); // These 2 handlers are independent // 1st is Pointer + Speech // 2nd is Speech only var handlerBasedListener1 = object1.AddComponent <TestInputGlobalListenerHandlerBasedAllHandlers>(); var handlerBasedListener2 = object1.AddComponent <TestInputGlobalListenerHandlerBasedSpeechHandler>(); yield return(null); // No event listener registration in this test CollectionAssert.IsEmpty(inputSystem.EventListeners, "Event listener for old event system API shouldn't be registered"); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealityPointerHandler), typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener1) }, inputSystem.EventHandlersByType[typeof(IMixedRealityPointerHandler)], "Input event system doesn't contain expected IMixedRealityPointerHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener1), new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener1), new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); // Disabling one component doesn't influence another one. handlerBasedListener1.enabled = false; CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener2) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); Object.Destroy(object1); yield return(null); }
public IEnumerator TestInputSystemGlobalHandlerListener() { // Need to remove cursors and other global event handlers yield return(PlayModeTestUtilities.SetupMrtkWithoutGlobalInputHandlers()); IMixedRealityInputSystem iInputSystem = null; MixedRealityServiceRegistry.TryGetService(out iInputSystem); BaseEventSystem inputSystem = (BaseEventSystem)iInputSystem; var object1 = new GameObject("Object"); var listener = object1.AddComponent <TestInputGlobalHandlerListener>(); yield return(null); // No event listener registration in this test CollectionAssert.IsEmpty(inputSystem.EventListeners, "Event listener for old event system API shouldn't be registered"); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealityHandJointHandler), typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler), typeof(IMixedRealityInputHandler <float>) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(listener) }, inputSystem.EventHandlersByType[typeof(IMixedRealityHandJointHandler)], "Input event system doesn't contain expected IMixedRealityHandJointHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(listener) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(listener) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(listener) }, inputSystem.EventHandlersByType[typeof(IMixedRealityInputHandler <float>)], "Input event system doesn't contain expected IMixedRealityInputHandler<float> handlers."); Object.Destroy(object1); yield return(null); }
public IEnumerator TestObjectBasedEventRegistration() { // Need to remove cursors and other global event handlers yield return(PlayModeTestUtilities.SetupMrtkWithoutGlobalInputHandlers()); IMixedRealityInputSystem iInputSystem = null; MixedRealityServiceRegistry.TryGetService(out iInputSystem); BaseEventSystem inputSystem = (BaseEventSystem)iInputSystem; var object1 = new GameObject("Object"); // Second handler weirdly depends on the first one due to event registration working on the entire object var objectBasedListener = object1.AddComponent <TestInputGlobalListenerObjectBased>(); var handlerBasedListener = object1.AddComponent <TestInputGlobalListenerHandlerBasedSpeechHandler>(); yield return(null); LogAssert.Expect(LogType.Error, new Regex("Detected simultaneous usage of IMixedRealityEventSystem.Register and IMixedRealityEventSystem.RegisterHandler")); // Event listener collection is filled for backward compatibility CollectionAssert.AreEquivalent( new List <GameObject> { objectBasedListener.gameObject }, inputSystem.EventListeners, "Event listener for old event system API hasn't been registered correctly."); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, true) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, true) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); // Make sure that disabling global listener doesn't remove the new API one. objectBasedListener.enabled = false; CollectionAssert.IsEmpty(inputSystem.EventListeners, "Event listener for old event system API shouldn't be registered"); CollectionAssert.AreEquivalent( new List <System.Type> { typeof(IMixedRealitySpeechHandler), typeof(IMixedRealityBaseInputHandler) }, inputSystem.EventHandlersByType.Keys, "Input event system doesn't contain expected event handler types."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, false) }, inputSystem.EventHandlersByType[typeof(IMixedRealitySpeechHandler)], "Input event system doesn't contain expected IMixedRealitySpeechHandler handlers."); CollectionAssert.AreEquivalent( new HandleList { new Handle(handlerBasedListener, false) }, inputSystem.EventHandlersByType[typeof(IMixedRealityBaseInputHandler)], "Input event system doesn't contain expected IMixedRealityBaseInputHandler handlers."); handlerBasedListener.enabled = false; CollectionAssert.IsEmpty(inputSystem.EventHandlersByType, "Input event system contains unexpected event handlers."); Object.Destroy(object1); yield return(null); }