public virtual void HandleMouseInput()
    {
        bool justCanceledControlMode = false;

        if (Input.GetMouseButtonUp(0) && !controllingWithJoystick)
        {
            inControlMode           = false;
            justCanceledControlMode = true;
        }
        foreach (_Selectable selectable in selectables)
        {
            if (IsMousedOverSelectable(selectable))
            {
                if (justCanceledControlMode || currentSelected != selectable)
                {
                    ChangeSelected(selectable);
                    return;
                }
            }
        }
        if (Input.GetMouseButton(0))
        {
            _Slider slider = currentSelected.GetComponent <_Slider>();
            if (slider != null)
            {
                Vector2 closestPointToMouseCanvasNormalized = new Vector2();
                if (currentSelected.canvas.renderMode == RenderMode.ScreenSpaceOverlay)
                {
                    if (selectable != null)
                    {
                        closestPointToMouseCanvasNormalized = slider.slidingArea.GetRectInCanvasNormalized(selectable.canvasRectTrs).ClosestPoint(slider.canvasRectTrs.GetRectInWorld().ToNormalizedPosition(Input.mousePosition));
                    }
                }
                else
                {
                    if (selectable != null)
                    {
                        closestPointToMouseCanvasNormalized = slider.slidingArea.GetRectInCanvasNormalized(selectable.canvasRectTrs).ClosestPoint(slider.canvasRectTrs.GetRectInWorld().ToNormalizedPosition(Camera.main.ScreenToWorldPoint(Input.mousePosition)));
                    }
                }
                float normalizedValue = slider.slidingArea.GetRectInCanvasNormalized(slider.canvasRectTrs).ToNormalizedPosition(closestPointToMouseCanvasNormalized).x;
                slider.slider.value = Mathf.Lerp(slider.slider.minValue, slider.slider.maxValue, normalizedValue);
                if (slider.snapValues.Length > 0)
                {
                    slider.slider.value = MathfExtensions.GetClosestNumber(slider.slider.value, slider.snapValues);
                }
            }
        }
    }
Esempio n. 2
0
 public virtual void HandleMouseInput()
 {
     if (InputManager.UsingGamepad)
     {
         return;
     }
     if (!leftClickInput && previousLeftClickInput && !controllingWithJoystick)
     {
         inControlMode = false;
     }
     foreach (_Selectable selectable in selectables)
     {
         if (currentSelected != selectable && IsMousedOverSelectable(selectable) && CanSelectSelectable(selectable))
         {
             ChangeSelected(selectable);
             return;
         }
     }
     if (leftClickInput)
     {
         if (currentInputField != null)
         {
             currentInputField.readOnly = true;
         }
         _Slider slider = currentSelected.GetComponent <_Slider>();
         if (slider != null)
         {
             Vector2 closestPointToMouseCanvasNormalized = new Vector2();
             if (currentSelected.canvas.renderMode == RenderMode.ScreenSpaceOverlay)
             {
                 if (selectable != null)
                 {
                     closestPointToMouseCanvasNormalized = slider.slidingArea.GetRectInCanvasNormalized(selectable.canvasRectTrs).ClosestPoint(slider.canvasRectTrs.GetWorldRect().ToNormalizedPosition(InputManager.MousePosition));
                 }
             }
             else if (selectable != null)
             {
                 closestPointToMouseCanvasNormalized = slider.slidingArea.GetRectInCanvasNormalized(selectable.canvasRectTrs).ClosestPoint(slider.canvasRectTrs.GetWorldRect().ToNormalizedPosition(selectable.canvas.worldCamera.ScreenToWorldPoint(InputManager.MousePosition)));
             }
             float normalizedValue = slider.slidingArea.GetRectInCanvasNormalized(slider.canvasRectTrs).ToNormalizedPosition(closestPointToMouseCanvasNormalized).x;
             slider.slider.value = Mathf.Lerp(slider.slider.minValue, slider.slider.maxValue, normalizedValue);
             if (slider.snapValues.Length > 0)
             {
                 slider.slider.value = MathfExtensions.GetClosestNumber(slider.slider.value, slider.snapValues);
             }
         }
         else
         {
             InputField inputField = currentSelected.GetComponent <InputField>();
             if (inputField != null)
             {
                 currentInputField          = inputField;
                 currentInputField.readOnly = false;
             }
         }
     }
 }