Beispiel #1
0
        public void Hide()
        {
            gameObject.SetActive(false);

            ActiveHand     = null;
            SelectedButton = null;
        }
Beispiel #2
0
        public void ClearButtons()
        {
            foreach (var button in _buttons)
            {
                Destroy(button.gameObject);
            }

            _buttons.Clear();

            SelectedButton = null;
        }
Beispiel #3
0
        public void Show(Hand hand, SteamVR_Action_Boolean openAction)
        {
            ActiveHand = hand;
            OpenAction = openAction;

            var forward = hand.transform.position - Player.instance.hmdTransform.position;

            forward.Normalize();

            transform.position = hand.transform.position + forward * 0.2f;
            transform.rotation = Quaternion.LookRotation(forward, Vector3.up);

            SelectedButton    = null;
            Label.text        = "";
            LabelBack.enabled = false;

            UpdateButtonPositions();
            gameObject.SetActive(true);
        }
Beispiel #4
0
        private void Update()
        {
            if (_buttonsInvalid)
            {
                UpdateButtonPositions();
            }

            if (ActiveHand == null || OpenAction == null || !ActiveHand.isActive || ActiveHand.mainRenderModel == null)
            {
                Hide();
                return;
            }

            if (OpenAction.GetStateUp(ActiveHand.handType))
            {
                if (SelectedButton != null)
                {
                    SelectedButton.OnClicked.Invoke();
                }

                Hide();
                return;
            }

            if (!ActiveHand.TryGetPointerPosition(out var handPos))
            {
                Hide();
                return;
            }

            var closest     = SelectedButton;
            var closestDist = float.MaxValue;

            foreach (var button in _buttons)
            {
                var dist = (button.transform.position - handPos).magnitude;

                if (dist < closestDist)
                {
                    closest     = button;
                    closestDist = dist;
                }
            }

            if (closest != SelectedButton)
            {
                SelectedButton = closest;
                Label.text     = closest.LabelText;

                var width = Label.preferredWidth + 32f;

                var min = LabelBack.transform.offsetMin;
                var max = LabelBack.transform.offsetMax;

                min.x = width * -0.5f;
                max.x = width * 0.5f;

                LabelBack.transform.offsetMin = min;
                LabelBack.transform.offsetMax = max;
                LabelBack.enabled             = true;
            }
        }