コード例 #1
0
        void SetupBrushUI()
        {
            m_AnnotationPointer = ObjectUtils.CreateGameObjectWithComponent <AnnotationPointer>(rayOrigin, false);
            m_OriginalAnnotationPointerLocalScale = m_AnnotationPointer.transform.localScale;
            var brushSize = m_Preferences.brushSize;

            m_AnnotationPointer.Resize(brushSize);

            var brushSizeUi = this.InstantiateUI(m_BrushSizePrefab, rayOrigin: rayOrigin);

            m_BrushSizeUI = brushSizeUi.GetComponent <BrushSizeUI>();

            var transform = brushSizeUi.transform;
            var scale     = transform.localScale;

            transform.SetParent(alternateMenuOrigin, false);
            transform.localPosition = Vector3.zero;
            transform.localRotation = Quaternion.Euler(-90, 0, 0);
            transform.localScale    = scale;

            m_BrushSizeUI.onValueChanged = value =>
            {
                var sliderValue = Mathf.Lerp(MinBrushSize, MaxBrushSize, value);
                m_Preferences.brushSize = sliderValue;
                m_AnnotationPointer.Resize(sliderValue);
            };
            m_BrushSizeChanged = m_BrushSizeUI.ChangeSliderValue;
        }
コード例 #2
0
        void HandleBrushSize(float value)
        {
            if (m_AnnotationPointer != null)
            {
                var brushSize = m_Preferences.brushSize;
                if (this.GetDeviceType() == DeviceType.Vive) // For vive controllers, use 1:1 touchpad setting.
                {
                    brushSize = Mathf.Lerp(MinBrushSize, MaxBrushSize, (value + 1) / 2f);
                }
                else // For touch and hydra, let the thumbstick gradually modify the width.
                {
                    brushSize += value * Time.unscaledDeltaTime * .1f;
                    brushSize  = Mathf.Clamp(brushSize, MinBrushSize, MaxBrushSize);
                }

                if (m_BrushSizeUI && m_BrushSizeChanged != null)
                {
                    var ratio = Mathf.InverseLerp(MinBrushSize, MaxBrushSize, brushSize);
                    m_BrushSizeChanged(ratio);
                }

                m_AnnotationPointer.Resize(brushSize);
                m_Preferences.brushSize = brushSize;
            }
        }
コード例 #3
0
ファイル: AnnotationTool.cs プロジェクト: LeksayProjects/VRAR
        public void ProcessInput(ActionMapInput input, ConsumeControlDelegate consumeControl)
        {
            if (m_Preferences == null)
            {
                return;
            }

            var annotationInput = (AnnotationInput)input;

            var draw = annotationInput.draw;

            var isOverUI = this.IsHoveringOverUI(rayOrigin);

            var isHeld = false;

            var rawInput = draw.rawValue;

            m_SmoothInput.Update(rawInput, Time.smoothDeltaTime);

            // We can only start drawing if we're not over UI
            if (!isOverUI || m_WasDrawing)
            {
                if (m_Preferences.pressureSensitive)
                {
                    var drawInput = Mathf.Lerp(rawInput, m_SmoothInput.predictedValue, m_Preferences.pressureSmoothing);
                    isHeld = drawInput > k_MinDrawStrength;

                    m_DrawStrength = (drawInput - k_MinDrawStrength) * k_DrawPressureScale;
                }
                else
                {
                    isHeld         = draw.isHeld;
                    m_DrawStrength = 1.0f;
                }
            }

            var isPressed  = !m_WasDrawing && isHeld;
            var isReleased = m_WasDrawing && !isHeld;

            m_WasDrawing = isHeld;

            if (primary)
            {
                if (!Mathf.Approximately(annotationInput.changeBrushSize.value, 0))
                {
                    HandleBrushSize(annotationInput.changeBrushSize.value);
                    consumeControl(annotationInput.changeBrushSize);
                    consumeControl(annotationInput.vertical);
                }

                if (isPressed)
                {
                    SetupAnnotation();
                    consumeControl(draw);
                }

                if (isHeld)
                {
                    UpdateAnnotation();
                    consumeControl(draw);
                }

                if (isReleased)
                {
                    FinalizeMesh();
                    consumeControl(draw);
                }

                var brushSize = m_Preferences.brushSize;
                if (isHeld)
                {
                    brushSize *= m_DrawStrength;
                }

                // ProcessInput is called once before Start, so m_AnnotationPointer will be null
                if (m_AnnotationPointer != null)
                {
                    m_AnnotationPointer.Resize(brushSize);
                }
            }

            if (isHeld)
            {
                return;
            }

            if (isOverUI != m_WasOverUI)
            {
                m_WasOverUI = isOverUI;
                this.RestartCoroutine(ref m_AnnotationPointerVisibilityCoroutine, SetAnnotationPointerVisibility(!isOverUI));
                if (isOverUI)
                {
                    this.RemoveRayVisibilitySettings(rayOrigin, this);
                }
                else
                {
                    this.AddRayVisibilitySettings(rayOrigin, this, false, false);
                }
            }
        }