예제 #1
0
        public override void Update()
        {
            base.Update();

            if (controller == null)
            {
                NRInput.LaserVisualActive   = false;
                NRInput.ReticleVisualActive = false;
                var inputSystem = Service as IMixedRealityInputSystem;
                var handedness  = NRInput.DomainHand == ControllerHandEnum.Left ? Handedness.Left : Handedness.Right;
                var pointers    = RequestPointers(SupportedControllerType.ArticulatedHand, handedness);
                var inputSource = inputSystem?.RequestNewGenericInputSource($"Nreal Light Controller", pointers, InputSourceType.Controller);
                controller = new NrealLightController(Microsoft.MixedReality.Toolkit.TrackingState.NotTracked, handedness, inputSource);
                controller.SetupConfiguration(typeof(NrealLightController));
                for (int i = 0; i < controller.InputSource?.Pointers?.Length; i++)
                {
                    controller.InputSource.Pointers[i].Controller = controller;
                }
                inputSystem.RaiseSourceDetected(controller.InputSource, controller);
            }
            controller.UpdateController();

            // Change RaycastMode
            if (NRInput.GetButtonUp(ControllerButton.HOME))
            {
                var inputSystem = Service as IMixedRealityInputSystem;
                inputSystem.RaiseSourceLost(controller.InputSource, controller);
                controller          = null;
                NRInput.RaycastMode = NRInput.RaycastMode == RaycastModeEnum.Laser ? RaycastModeEnum.Gaze : RaycastModeEnum.Laser;
            }
        }
        public override void Update()
        {
            base.Update();

            if (controller == null)
            {
                NRInput.LaserVisualActive   = false;
                NRInput.ReticleVisualActive = false;

                var inputSystem = Service as IMixedRealityInputSystem;
                var handedness  = NRInput.DomainHand == ControllerHandEnum.Left ? Handedness.Left : Handedness.Right;
                var pointers    = RequestPointers(SupportedControllerType.ArticulatedHand, handedness);
                var inputSource = inputSystem?.RequestNewGenericInputSource($"Nreal Light Controller", pointers, InputSourceType.Hand);
                controller = new NrealLightController(Microsoft.MixedReality.Toolkit.TrackingState.NotTracked, handedness, inputSource);
                controller.SetupConfiguration(typeof(NrealLightController));
                for (int i = 0; i < controller.InputSource?.Pointers?.Length; i++)
                {
                    controller.InputSource.Pointers[i].Controller = controller;
                }
                inputSystem.RaiseSourceDetected(controller.InputSource, controller);
            }
            controller.UpdateController();

            // Change RaycastMode
            if (NRInput.GetButtonUp(ControllerButton.APP))
            {
                var inputSystem = Service as IMixedRealityInputSystem;
                inputSystem.RaiseSourceLost(controller.InputSource, controller);
                inputSystem.RaiseSourceDetected(controller.InputSource, controller);
                NRInput.RaycastMode = NRInput.RaycastMode == RaycastModeEnum.Laser ? RaycastModeEnum.Gaze : RaycastModeEnum.Laser;
            }

            // Set MixedRealityInputSystem
            if (homeMenu == null)
            {
                homeMenu = GameObject.FindObjectOfType <NRKernal.NRExamples.NRHomeMenu>();
                var canvas = homeMenu?.GetComponentInChildren <Canvas>();
                if (canvas != null)
                {
                    if (canvas.gameObject.GetComponent <GraphicRaycaster>() == null)
                    {
                        canvas.gameObject.AddComponent <GraphicRaycaster>();
                    }
                    if (canvas.gameObject.GetComponent <CanvasUtility>() == null)
                    {
                        canvas.gameObject.AddComponent <CanvasUtility>();
                    }
                }
            }
        }