Ejemplo n.º 1
0
        void UpdateVisibility()
        {
            if (_Canvas)
            {
                _Canvas.gameObject.SetActive(Singleton <HScene> .Instance);

                if (IsVisible)
                {
                    _Buttons.Clear();
                    foreach (var stopControl in FindObjectsOfType <SpriteGaugeStopCtrl>())
                    {
                        var button = new PlayButton();
                        var toggle = stopControl.GetComponent <Toggle>();
                        button.OnSelect.AddListener(delegate { toggle.OnPointerEnter(null); });
                        button.OnUnselect.AddListener(delegate { toggle.OnPointerExit(null); });
                        button.OnActivate.AddListener(delegate { toggle.isOn = !toggle.isOn; stopControl.OnChangeValueStopFeel(toggle.isOn); });
                        button.Degrees = 45;

                        if (stopControl.name.Contains("Female"))
                        {
                            button.StartAngle = 270 - 10 - button.Degrees;
                        }
                        else
                        {
                            button.StartAngle = 270 + 10;
                        }

                        _Buttons.Add(button);
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private PlayButton DetermineSelectedButton(Vector2 touchPosition)
        {
            PlayButton selectedButton = null;

            if (touchPosition.magnitude > 0.3f)
            {
                var normalized   = touchPosition.normalized;
                var currentPoint = Mathf.Atan2(normalized.y, normalized.x) * Mathf.Rad2Deg;
                while (currentPoint < 0)
                {
                    currentPoint += 360;
                }

                selectedButton = _Buttons.FirstOrDefault(button => button.StartAngle <= currentPoint && button.StartAngle + button.Degrees >= currentPoint);
                VRLog.Info("Angle: {0} of {1}", currentPoint, _Buttons.Count);
                if (selectedButton != null)
                {
                    VRLog.Info("Found a button: {0}", selectedButton.GetType().FullName);
                }
            }

            return(selectedButton);
        }
Ejemplo n.º 3
0
        protected override void OnUpdate()
        {
            base.OnUpdate();

            PlayButton selectedButton = null;

            if (IsTracking && IsVisible)
            {
                SynchronizeButtons();

                var device = this.Controller;

                var tPadPos      = device.GetAxis();
                var tPadTouch    = device.GetTouch(EVRButtonId.k_EButton_SteamVR_Touchpad);
                var tPadPress    = device.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad);
                var tPadRelease  = device.GetPressUp(EVRButtonId.k_EButton_SteamVR_Touchpad);
                var triggerState = device.GetAxis(EVRButtonId.k_EButton_Axis1).x;
                var currentVal   = _RiftMode ? tPadPos.x : tPadPos.y;

                if (device.GetTouchDown(EVRButtonId.k_EButton_Axis0))
                {
                    prevVal = currentVal;
                    val     = 0;
                }
                if (tPadTouch && !tPadRelease)
                {
                    LastTouch = Time.time;

                    // [PLAY TOOL ANIMATIONS] Ver 2
                    //var oldLockState = Cursor.lockState;
                    //Cursor.lockState = CursorLockMode.Locked;
                    //Cursor.lockState = oldLockState;

                    // Normalize
                    var magnitude = tPadPos.magnitude;
                    if (magnitude < 0.4f || (_RiftMode && Mathf.Abs(tPadPos.y) < 0.3f))
                    {
                        if (_RiftMode)
                        {
                            val += currentVal * Time.deltaTime * 10;
                        }
                        else
                        {
                            val += (currentVal - prevVal) * 5;
                        }
                        while (Mathf.Abs(val) >= 1)
                        {
                            Owner.StartRumble(new RumbleImpulse(200));
                            VR.Input.Mouse.VerticalScroll(val > 0 ? 1 : -1);
                            val = val > 0 ? (val - 1) : (val + 1);
                        }
                    }
                    if (magnitude > 0.6f || _RiftMode)
                    {
                        selectedButton = DetermineSelectedButton(tPadPos);
                    }

                    prevVal = currentVal;
                }

                if (tPadRelease)
                {
                    if (_SelectedButton != null)
                    {
                        _SelectedButton.OnActivate.Invoke();
                    }
                }
            }

            // Update selected button
            if (_SelectedButton != selectedButton)
            {
                if (_SelectedButton != null)
                {
                    _SelectedButton.OnUnselect.Invoke();
                }
                _SelectedButton = selectedButton;
                if (_SelectedButton != null)
                {
                    _SelectedButton.OnSelect.Invoke();
                }
            }
        }
Ejemplo n.º 4
0
        protected override void OnFixedUpdate()
        {
            PlayButton selectedButton = null;

            if (IsTracking && IsVisible)
            {
                var device = this.Controller;

                var tPadPos      = device.GetAxis();
                var tPadTouch    = device.GetTouch(EVRButtonId.k_EButton_SteamVR_Touchpad);
                var tPadPress    = device.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad);
                var tPadRelease  = device.GetPressUp(EVRButtonId.k_EButton_SteamVR_Touchpad);
                var triggerState = device.GetAxis(EVRButtonId.k_EButton_Axis1).x;

                if (device.GetTouchDown(EVRButtonId.k_EButton_Axis0))
                {
                    prevVal = tPadPos.y;
                    val     = 0;
                }
                if (tPadTouch && !tPadRelease)
                {
                    // Normalize
                    var magnitude = tPadPos.magnitude;
                    if (magnitude < 0.4f)
                    {
                        val += (tPadPos.y - prevVal) * 5;
                        while (Mathf.Abs(val) >= 1)
                        {
                            Owner.StartRumble(new RumbleImpulse(200));
                            VR.Input.Mouse.VerticalScroll(val > 0 ? 1 : -1);
                            val = val > 0 ? (val - 1) : (val + 1);
                        }
                    }
                    else if (magnitude > 0.6f)
                    {
                        selectedButton = DetermineSelectedButton(tPadPos);
                    }

                    prevVal = tPadPos.y;
                }

                if (tPadRelease)
                {
                    if (_SelectedButton != null)
                    {
                        _SelectedButton.OnActivate.Invoke();
                    }
                }
            }

            // Update selected button
            if (_SelectedButton != selectedButton)
            {
                if (_SelectedButton != null)
                {
                    _SelectedButton.OnUnselect.Invoke();
                }
                _SelectedButton = selectedButton;
                if (_SelectedButton != null)
                {
                    _SelectedButton.OnSelect.Invoke();
                }
            }
        }
Ejemplo n.º 5
0
        private void SynchronizeButtons()
        {
            if (Time.time - _LastSync < SYNC_INTERVAL)
            {
                return;
            }

            _LastSync = Time.time;
            if (_CurrentVisibleButtons != null && _CachedActiveButtons != null)
            {
                var activeButtons = new List <int>();

                foreach (int buttonIndex in _CurrentVisibleButtons)
                {
                    if (_Sprite.categoryFinish.lstButton[buttonIndex].IsActive())
                    {
                        activeButtons.Add(buttonIndex);
                    }
                }

                if (!activeButtons.SequenceEqual(_CachedActiveButtons))
                {
                    VRLog.Info("Something changed!");
                    _CachedActiveButtons = new List <int>(activeButtons);

                    // Get on clean grounds
                    foreach (var b in _Buttons.OfType <SpriteButton>().ToList())
                    {
                        _Buttons.Remove(b);
                        DestroyImmediate(b.Element.gameObject);

                        if (_SelectedButton == b)
                        {
                            _SelectedButton = null;
                        }
                    }

                    if (_CachedActiveButtons.Count > 0)
                    {
                        int range        = 180 / _CachedActiveButtons.Count;
                        int clampedRange = Math.Min(MAX_DEGREES_PER_BUTTON, range);
                        int i            = 0;
                        foreach (var buttonIndex in _CachedActiveButtons)
                        {
                            var clone = GameObject.Instantiate <GameObject>(_Sprite.categoryFinish.lstButton[buttonIndex].gameObject);

                            // Deactivate by default
                            clone.transform.SetParent(_Canvas.transform, false);

                            var realButton = new SpriteButton(i, clone.GetComponent <Button>());
                            var center     = range * i + (range / 2);
                            var halfRange  = Mathf.RoundToInt(clampedRange * 0.5f);

                            realButton.StartAngle = center - halfRange;
                            realButton.Degrees    = clampedRange;
                            VRLog.Info("Putting button #{0} to {1} (Count={2}, startAngle={3}, range={4})", realButton.Index, center, _CachedActiveButtons.Count, realButton.StartAngle, range);

                            realButton.Element.transform.localPosition = Quaternion.Euler(0, 0, center) * Vector3.right * 100;
                            realButton.Element.gameObject.SetActive(true);

                            _Buttons.Add(realButton);
                            i++;
                        }
                    }
                }
            }
            else
            {
                VRLog.Info("No values");
            }
        }