Пример #1
0
        private void UpdateLaser()
        {
            Laser.SetPosition(0, Laser.transform.position);
            Laser.SetPosition(1, Laser.transform.position + Laser.transform.forward);

            if (_Target && _Target.gameObject.activeInHierarchy)
            {
                if (IsWithinRange(_Target) && Raycast(_Target, out RaycastHit hit))
                {
                    Laser.SetPosition(1, hit.point);
                    if (!IsOtherWorkingOn(_Target))
                    {
                        var newPos = new Vector2(hit.textureCoord.x * VRGUI.Width, (1 - hit.textureCoord.y) * VRGUI.Height);
                        //VRLog.Debug("New Pos: {0}, textureCoord: {1}", newPos, hit.textureCoord);
                        if (!mouseDownPosition.HasValue || Vector2.Distance(mouseDownPosition.Value, newPos) > MOUSE_STABILIZER_THRESHOLD)
                        {
                            MouseOperations.SetClientCursorPosition((int)newPos.x, (int)newPos.y);
                            mouseDownPosition = null;
                        }
                    }
                }
                else
                {
                    // Out of view
                    LaserVisible = false;
                }
            }
            else
            {
                // May day, may day -- window is gone!
                LaserVisible = false;
            }
        }
Пример #2
0
 private void UpdateLaser()
 {
     Laser.SetPosition(0, Laser.transform.position);
     Laser.SetPosition(1, Laser.transform.position + Laser.transform.forward);
     if (_Target && _Target.gameObject.activeInHierarchy)
     {
         if (!IsWithinRange(_Target) || !Raycast(_Target, out RaycastHit raycastHit))
         {
             LaserVisible = false;
             return;
         }
         Laser.SetPosition(1, raycastHit.point);
         if (!IsOtherWorkingOn(_Target))
         {
             var vector = new Vector2(raycastHit.textureCoord.x * VRGUI.Width, (1f - raycastHit.textureCoord.y) * VRGUI.Height);
             if (mouseDownPosition == null || Vector2.Distance(mouseDownPosition.Value, vector) > 30f)
             {
                 MouseOperations.SetClientCursorPosition((int)vector.x, (int)vector.y);
                 mouseDownPosition = null;
                 return;
             }
         }
     }
     else
     {
         LaserVisible = false;
     }
 }
Пример #3
0
        protected override void OnUpdate()
        {
            base.OnUpdate();


            if (!_Current)
            {
                foreach (var quad in GUIQuadRegistry.Quads)
                {
                    var result = AnalyzeQuad(quad);
                    if (result.Position == RelativePosition.Hover)
                    {
                        _Current = quad;
                        EnterState(State.Hover);
                        break;
                    }
                }
            }
            else
            {
                var result = AnalyzeQuad(_Current);

                if (result.TextureCoords != Vector2.zero)
                {
                    var newPos = new Vector2(result.TextureCoords.x * VRGUI.Width, (1 - result.TextureCoords.y) * VRGUI.Height);
                    if (!mouseDownPosition.HasValue || Vector2.Distance(mouseDownPosition.Value, newPos) > MOUSE_STABILIZER_THRESHOLD)
                    {
                        MouseOperations.SetClientCursorPosition((int)newPos.x, (int)newPos.y);
                        mouseDownPosition = null;
                    }
                }

                // Update state
                if (_CurrentState == State.Press)
                {
                    if (result.Position == RelativePosition.Out)
                    {
                        EnterState(State.None);
                    }
                    else if (result.Position == RelativePosition.Hover)
                    {
                        EnterState(State.Hover);
                    }
                }
                else if (_CurrentState == State.Hover)
                {
                    if (result.Position == RelativePosition.Behind)
                    {
                        EnterState(State.Press);
                    }
                    else if (result.Position == RelativePosition.Out)
                    {
                        EnterState(State.None);
                    }
                }
            }
        }