Skip to content

Commit

Permalink
Recommended changes from @ekcoh. Added more #if UNITY_6000_0_OR_NEWER.
Browse files Browse the repository at this point in the history
  • Loading branch information
benoitalain committed Jun 5, 2024
1 parent a9df122 commit 8bb47fd
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Assets/Tests/InputSystem/Plugins/UITests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1174,6 +1174,7 @@ public IEnumerator UI_CanReceivePointerExitsWhenChangingUIStateWithoutMovingPoin
);
}

#if UNITY_6000_0_OR_NEWER
[UnityTest]
[Category("UI")]
[TestCase(1.0f, ExpectedResult = -1)]
Expand Down Expand Up @@ -1209,6 +1210,7 @@ public IEnumerator UI_ReceivesNormalizedScrollWheelDelta(float scrollWheelDeltaP
)
);
}
#endif

[UnityTest]
[Category("UI")]
Expand Down
3 changes: 3 additions & 0 deletions Packages/com.unity.inputsystem/InputSystem/IInputRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,8 +174,11 @@ internal unsafe interface IInputRuntime

Vector2 screenSize { get; }
ScreenOrientation screenOrientation { get; }

#if UNITY_6000_0_OR_NEWER
bool normalizeScrollWheelDelta { get; set; }
float scrollWheelDeltaPerTick { get; }
#endif

// If analytics are enabled, the runtime receives analytics events from the input manager.
// See InputAnalytics.
Expand Down
2 changes: 2 additions & 0 deletions Packages/com.unity.inputsystem/InputSystem/InputManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,8 +170,10 @@ public InputSettings.ScrollDeltaBehavior scrollDeltaBehavior

m_ScrollDeltaBehavior = value;

#if UNITY_6000_0_OR_NEWER
InputRuntime.s_Instance.normalizeScrollWheelDelta =
m_ScrollDeltaBehavior == InputSettings.ScrollDeltaBehavior.UniformAcrossAllPlatforms;
#endif
}
}

Expand Down
2 changes: 2 additions & 0 deletions Packages/com.unity.inputsystem/InputSystem/InputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3423,7 +3423,9 @@ public static bool runInBackground
set => s_Manager.m_Runtime.runInBackground = value;
}

#if UNITY_6000_0_OR_NEWER
internal static float scrollWheelDeltaPerTick => InputRuntime.s_Instance.scrollWheelDeltaPerTick;
#endif

////REVIEW: restrict metrics to editor and development builds?
/// <summary>
Expand Down
12 changes: 3 additions & 9 deletions Packages/com.unity.inputsystem/InputSystem/NativeInputRuntime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -281,24 +281,18 @@ private void OnFocusChanged(bool focus)
public Vector2 screenSize => new Vector2(Screen.width, Screen.height);
public ScreenOrientation screenOrientation => Screen.orientation;

#if UNITY_6000_0_OR_NEWER
public bool normalizeScrollWheelDelta
{
#if UNITY_6000_0_OR_NEWER
get => NativeInputSystem.normalizeScrollWheelDelta;
set => NativeInputSystem.normalizeScrollWheelDelta = value;
#else
get; set;
#endif
}

public float scrollWheelDeltaPerTick
{
#if UNITY_6000_0_OR_NEWER
get { return NativeInputSystem.GetScrollWheelDeltaPerTick(); }
#else
get => 1.0f;
#endif
get => NativeInputSystem.GetScrollWheelDeltaPerTick();
}
#endif

public bool isInBatchMode => Application.isBatchMode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2072,9 +2072,11 @@ private void OnScrollCallback(InputAction.CallbackContext context)

state.scrollDelta = context.ReadValue<Vector2>();

#if UNITY_6000_0_OR_NEWER
// Need to scale as the UI system expects values in the [-1, 1] range.
// ISXB-704: convert input value to BaseInputModule convention.
state.scrollDelta *= (1.0f / InputSystem.scrollWheelDeltaPerTick);
#endif

#if UNITY_2022_3_OR_NEWER
state.eventData.displayIndex = GetDisplayIndexFor(context.control);
Expand Down

0 comments on commit 8bb47fd

Please sign in to comment.