Пример #1
0
        private void InitializeHeadPositioningIntro(IScene tutorialScene, int stageIndex)
        {
            var uiIntroNode = tutorialScene.EnumerateAllNodes().Single(x => x.Name == "Head Positioning");

            stageRoomIds[stageIndex] = uiIntroNode.Id;

            var playerSpawn = uiIntroNode.SearchComponent <IFocusNodeComponent>().DefaultViewpointMechanism.FixedCamera.GetProps().Frame;

            CreateRoomStartTrigger(playerSpawn.Eye.ToUnity(), VrInputDispatcherCapabilities.None, typeof(FixedTeleportVrNavigationMode));

            //Transition to next room
            var nextButtonPosition = playerSpawn.Eye.ToUnity() + new Vector3(0.0f, -1f, -0.7f);
            var nextButtonRotation = Quaternion.AngleAxis(180.0f, Vector3.up);
            var nextButtonText     = "Press Me!";
            var nextButtonObj      = CreateButton(nextButtonPosition, nextButtonRotation, nextButtonText, () =>
            {
                SteamVR_Fade.Start(Color.white, 0);
                navigationService.GoToSpecific(stageRoomIds[stageIndex + 1]);
                headPositionService.ResetHeadPosition();
                SteamVR_Fade.Start(Color.clear, 0.5f);
            });

            cleanUpList.Add(nextButtonObj);
        }
        private void HandleLaser()
        {
            var laserLocalPos = SteamVR_Actions.default_LaserPose.GetLocalPosition(SteamVR_Input_Sources.RightHand); // Relative to player
            var laserLocalRot = SteamVR_Actions.default_LaserPose.GetLocalRotation(SteamVR_Input_Sources.RightHand); // Relative to player
            var laserPos      = globalObjectService.VrPlayer.transform.TransformPoint(laserLocalPos);
            var laserRot      = globalObjectService.VrPlayer.transform.rotation * laserLocalRot;

            var laserDirection = laserRot * Vector3.forward;

            textAbove.text = "";

            var ray = new Ray(laserPos, laserDirection);

            if (!Physics.Raycast(ray, out var hitInfo))
            {
                var farMidPoint = laserPos + laserDirection * 50;
                laser.transform.position   = farMidPoint;
                laser.transform.rotation   = laserRot * Quaternion.Euler(90, 0, 0);
                laser.transform.localScale = new Vector3(0.005f, 50, 0.0005f);
                return;
            }

            var midPoint = (laserPos + hitInfo.point) / 2;

            laser.transform.position   = midPoint;
            laser.transform.rotation   = laserRot * Quaternion.Euler(90, 0, 0);
            laser.transform.localScale = new Vector3(0.005f, hitInfo.distance / 2, 0.005f);
            if (hitInfo.collider.gameObject != minimap)
            {
                return;
            }

            var hitTexCoord = hitInfo.textureCoord;
            var pixelPos    = new IntVector2(Mathf.RoundToInt(hitTexCoord.x * MinimapImageSize.Width),
                                             Mathf.RoundToInt(hitTexCoord.y * MinimapImageSize.Height));
            var hits     = rayHitIndex.CastRay(new RayHitInfo(viewports[0], viewports[0].View.Layers[0], pixelPos));
            var firstHit = hits.FirstOrNull();
            var cGizmo   = firstHit?.Node.SearchComponent <StoryFlowchartNodeGizmoComponent>();

            if (cGizmo == null)
            {
                return;
            }

            var storyNode = cGizmo.ReferencedNode;

            if (!storyService.GlobalGraph.Children[storyNode.Id].IsEmpty())
            {
                return;
            }

            textAbove.text = storyNode.Name;
            if (!SteamVR_Actions.default_InteractUI.GetStateDown(SteamVR_Input_Sources.RightHand))
            {
                return;
            }

            inputService.OnInputEvent(new MouseEventArgs
            {
                ComplexEventType = MouseEventType.DoubleClick,
                EventButtons     = MouseButtons.Left,
                Viewport         = viewports[0],
                State            = new MouseState
                {
                    Buttons            = MouseButtons.Left,
                    Position           = pixelPos,
                    HmgnPosition       = Hmgnize(pixelPos.ToVector()),
                    NormalizedPosition = Normalize(pixelPos.ToVector()),
                }
            });

            headPositionService.ResetHeadPosition();
        }