Fix: wheel over UI scrolls the list instead of zooming the camera
The orbit rig read the wheel unfiltered for zoom, so scrolling a paint-mode scroll list also zoomed the camera. Gate the zoom behind a shared InputUtil.PointerOverUi() helper (EventSystem raycast); MeshPainter's private IsPointerOverUi() now delegates to the same helper (DRY). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
1 parent
a4604328d2
commit
50efc7e8b3
3 files changed
+18
-11
No files matched your search
@@ -238,11 +238,13 @@ public class ThirdPersonOrbitInput : MonoBehaviour
|
|||||||
|
|
||||||
float scale = CurrentScale();
|
float scale = CurrentScale();
|
||||||
|
|
||||||
// Shift/Ctrl+wheel is reserved for the paint brush resize (MeshPainter) - but only in paint
|
// The wheel belongs to the UI when the pointer is over an interactive element (e.g. a scroll
|
||||||
// mode (PanEnabled), where the resize actually claims the wheel. Outside paint mode Shift is
|
// list), so it scrolls the UI instead of zooming. Shift/Ctrl+wheel is likewise reserved for the
|
||||||
// the sprint key, so the wheel must still zoom.
|
// paint brush resize (MeshPainter) - but only in paint mode (PanEnabled), where the resize
|
||||||
bool brushResizeClaimsWheel = PanEnabled && (InputUtil.ShiftHeld() || InputUtil.CtrlHeld());
|
// actually claims the wheel; outside paint mode Shift is the sprint key, so the wheel must zoom.
|
||||||
float scroll = brushResizeClaimsWheel ? 0f : InputUtil.ReadScroll();
|
bool wheelClaimed = InputUtil.PointerOverUi()
|
||||||
|
|| (PanEnabled && (InputUtil.ShiftHeld() || InputUtil.CtrlHeld()));
|
||||||
|
float scroll = wheelClaimed ? 0f : InputUtil.ReadScroll();
|
||||||
if (!Mathf.Approximately(scroll, 0f))
|
if (!Mathf.Approximately(scroll, 0f))
|
||||||
{
|
{
|
||||||
// One wheel notch = one zoom step (sign only, platform-independent). The step scales with
|
// One wheel notch = one zoom step (sign only, platform-independent). The step scales with
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.EventSystems;
|
|
||||||
#if ENABLE_INPUT_SYSTEM
|
#if ENABLE_INPUT_SYSTEM
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
#endif
|
#endif
|
||||||
@@ -1123,11 +1122,7 @@ public partial class MeshPainter : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// <summary>True if the pointer is currently over an interactive UI element (raycast target).</summary>
|
/// <summary>True if the pointer is currently over an interactive UI element (raycast target).</summary>
|
||||||
private static bool IsPointerOverUi()
|
private static bool IsPointerOverUi() => InputUtil.PointerOverUi();
|
||||||
{
|
|
||||||
var es = EventSystem.current;
|
|
||||||
return es && es.IsPointerOverGameObject();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void OnDestroy()
|
private void OnDestroy()
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
#if ENABLE_INPUT_SYSTEM
|
#if ENABLE_INPUT_SYSTEM
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
#endif
|
#endif
|
||||||
@@ -40,6 +41,15 @@ public static class InputUtil
|
|||||||
Cursor.visible = !locked;
|
Cursor.visible = !locked;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>True while the pointer is over an interactive UI element (a raycast target), so the
|
||||||
|
/// wheel/click belongs to the UI (e.g. a scroll list) and must not also zoom the camera or paint
|
||||||
|
/// the mesh behind it. False when no EventSystem exists.</summary>
|
||||||
|
public static bool PointerOverUi()
|
||||||
|
{
|
||||||
|
var es = EventSystem.current;
|
||||||
|
return es && es.IsPointerOverGameObject();
|
||||||
|
}
|
||||||
|
|
||||||
public static bool ShiftHeld()
|
public static bool ShiftHeld()
|
||||||
{
|
{
|
||||||
#if ENABLE_INPUT_SYSTEM
|
#if ENABLE_INPUT_SYSTEM
|
||||||
|
|||||||
Reference in new issue
Block a user