Skip to content

fix: Mouse click and long-press coordinates now match the Game View's actual resolution#1662

Merged
hatayama merged 3 commits into
v3-betafrom
feat/mouse-coordinate-validation
Jul 9, 2026
Merged

fix: Mouse click and long-press coordinates now match the Game View's actual resolution#1662
hatayama merged 3 commits into
v3-betafrom
feat/mouse-coordinate-validation

Conversation

@hatayama

@hatayama hatayama commented Jul 9, 2026

Copy link
Copy Markdown
Owner

Summary

  • simulate-mouse-input's click/long-press coordinates now align with the Game View's target resolution instead of the runtime window's pixel size, so injected clicks land where a screenshot --capture-mode rendering image says they should.
  • The response now echoes the full coordinate conversion (Game View size, input position, injected position, formula) so callers can verify the math themselves.

User Impact

  • Before: when the Game View was resized or docked at a different pixel size than its target resolution, simulate-mouse-input could inject clicks at the wrong Y position relative to a screenshot taken with --capture-mode rendering.
  • After: both tools derive coordinates from the same Game View target resolution, so screenshot-driven coordinates and injected input stay consistent.

Changes

  • MouseInputPressActionExecutor: replaced the Screen.height-based Y-flip with GameViewCoordinateUtility.ConvertInputToUnity (the same utility already used by the raycast/screenshot tools).
  • SimulateMouseInputResponse: added coordinate-system/conversion metadata fields (Game View size, input position, injected Unity position, conversion formula).
  • MouseInputSimulationResponseFactory: added a success-result builder that populates the new metadata.
  • Wired InternalsVisibleTo/asmdef references so SimulateMouseInput.Editor and Tests.PlayMode can use the shared GameViewCoordinateUtility.
  • simulate-mouse-ui required no change — it already used Handles.GetMainGameViewSize().

Ported from origin/main's c81f6b0b (mouse-coordinate portion only; the raycast/screenshot portions of that commit were already ported as C1–C3).

Verification

  • uloop compile: 0 errors, 0 warnings
  • uloop run-tests (PlayMode, SimulateMouseInputTests|SimulateMouseUi.*Tests): 46/46 passed
  • uloop run-tests (EditMode, full suite): 1774/1774 passed, 7 pre-existing skips
  • uloop run-tests (PlayMode, full suite): 92/92 passed

Review in cubic

Ported from origin/main's c81f6b0. simulate-mouse-input previously
flipped the Y coordinate using Screen.height (the runtime window's
pixel size), which can diverge from the Game View's target
resolution when the view is resized or docked differently — silently
misaligning injected clicks with coordinates read from a
`screenshot --capture-mode rendering` image. Switches to
GameViewCoordinateUtility.ConvertInputToUnity (already used by
raycast/screenshot tools, ported during C1) and echoes the full
conversion (GameView size, input position, injected Unity position,
formula) in the response so callers can verify the math.

simulate-mouse-ui needed no change: its MouseUiCoordinateConverter
already used Handles.GetMainGameViewSize().
@coderabbitai

coderabbitai Bot commented Jul 9, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 23f846ae-f65f-4449-93c1-b11ed93cfe84

📥 Commits

Reviewing files that changed from the base of the PR and between 78b5554 and 9c0470c.

📒 Files selected for processing (3)
  • .agents/skills/uloop-simulate-mouse-input/SKILL.md
  • .claude/skills/uloop-simulate-mouse-input/SKILL.md
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/Skill/SKILL.md
✅ Files skipped from review due to trivial changes (2)
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/Skill/SKILL.md
  • .claude/skills/uloop-simulate-mouse-input/SKILL.md
🚧 Files skipped from review as they are similar to previous changes (1)
  • .agents/skills/uloop-simulate-mouse-input/SKILL.md

📝 Walkthrough

Walkthrough

This PR adds Game View coordinate metadata to simulate-mouse-input, updates click/long-press execution to use the new conversion, extends the response schema and tests, and revises skill docs and tool schema to document the coordinate sources and output fields.

Changes

Coordinate Conversion Metadata

Layer / File(s) Summary
Response schema and factory for coordinate metadata
Packages/src/Editor/FirstPartyTools/SimulateMouseInput/SimulateMouseInputResponse.cs, Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputSimulationResponseFactory.cs, Packages/src/Editor/FirstPartyTools/Common/GameView/AssemblyInfo.cs
Adds coordinate system, dimension, and position fields to the response, a new SuccessButtonResult factory method, and an InternalsVisibleTo entry for the SimulateMouseInput editor assembly.
Executor uses coordinate conversion for click and long-press
Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputPressActionExecutor.cs
ExecuteClick and ExecuteLongPress compute GameViewCoordinateConversion, inject positions via InjectedUnityPosition, and build success responses through the new factory method.
Tests verify injected coordinate metadata
Assets/Tests/PlayMode/SimulateMouseInputTests.cs
Adds a helper asserting coordinate-system identifiers, conversion formula, and derived positions, used by click and long-press success tests.
Skill docs and tool schema updated for coordinate guidance
.agents/skills/uloop-simulate-mouse-input/SKILL.md, .claude/skills/uloop-simulate-mouse-input/SKILL.md, Packages/src/Editor/FirstPartyTools/SimulateMouseInput/Skill/SKILL.md, cli/common/tools/default-tools.json
Documents top-left Game View coordinate sources, Y-axis conversion formula, and the expanded output field set for --x and --y.

Estimated code review effort: 3 (Moderate) | ~25 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Executor as MouseInputPressActionExecutor
  participant Conversion as GameViewCoordinateConversion
  participant InputSystem as Unity Input System
  participant Factory as MouseInputSimulationResponseFactory

  Executor->>Conversion: ConvertInputToUnity(inputPos)
  Conversion-->>Executor: InjectedUnityPosition
  Executor->>InputSystem: SetPositionState(InjectedUnityPosition)
  Executor->>Factory: SuccessButtonResult(action, message, button, inputPos, conversion)
  Factory-->>Executor: SimulateMouseInputResponse with coordinate metadata
Loading

Possibly related PRs

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: mouse input coordinates now match the Game View resolution.
Description check ✅ Passed The description is directly related to the coordinate-conversion and response-metadata changes in this pull request.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/mouse-coordinate-validation

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

The previous commit switched the tool's X/Y coordinate basis from
Screen.height to the Game View's target resolution, but this
project's docs still said "screen pixels" and didn't mention the new
response metadata fields, actively misleading callers about how to
source coordinates. Updated the X/Y schema description in
default-tools.json and the skill source (workflow step 2, parameter
table, examples, new Coordinate System section, Output field list),
then regenerated the .claude/.agents copies via
`uloop skills install --claude --agents`.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputSimulationResponseFactory.cs (1)

45-55: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider including conversion metadata in InterruptedButtonResult.

When the executor hits a pause point, the mouse position was already set via conversion.InjectedUnityPosition and the button was pressed, yet the interrupted response omits all coordinate-conversion fields. Callers can't verify what was actually injected. The conversion is available at both call sites in MouseInputPressActionExecutor (lines 120 and 239) but can't be passed because the method signature doesn't accept it.

♻️ Suggested refactor
 internal static SimulateMouseInputResponse InterruptedButtonResult(
     UnityCliLoopMouseInputAction action,
     string buttonName,
-    Vector2 inputPos)
+    Vector2 inputPos,
+    GameViewCoordinateConversion conversion)
 {
     SimulateMouseInputResponse result = InterruptedActionResult(action);
     result.Button = buttonName;
     result.PositionX = inputPos.x;
     result.PositionY = inputPos.y;
+    result.InputCoordinateSystem = UnityCliLoopConstants.COORDINATE_SYSTEM_TOP_LEFT_GAME_VIEW;
+    result.UnityCoordinateSystem = UnityCliLoopConstants.COORDINATE_SYSTEM_BOTTOM_LEFT_GAME_VIEW;
+    result.GameViewWidth = conversion.GameViewSize.x;
+    result.GameViewHeight = conversion.GameViewSize.y;
+    result.InputPositionX = conversion.InputPosition.x;
+    result.InputPositionY = conversion.InputPosition.y;
+    result.InjectedUnityPositionX = conversion.InjectedUnityPosition.x;
+    result.InjectedUnityPositionY = conversion.InjectedUnityPosition.y;
+    result.CoordinateConversionFormula = UnityCliLoopConstants.COORDINATE_CONVERSION_FORMULA_GAME_VIEW_INPUT_TO_UNITY;
     return result;
 }

Then update both call sites in MouseInputPressActionExecutor.cs to pass conversion:

 return MouseInputSimulationResponseFactory.InterruptedButtonResult(
     UnityCliLoopMouseInputAction.Click,
     buttonName,
-    inputPos);
+    inputPos,
+    conversion);
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputSimulationResponseFactory.cs`
around lines 45 - 55, Interrupted mouse button responses are missing the
coordinate-conversion metadata that is already available at the pause points.
Update MouseInputSimulationResponseFactory.InterruptedButtonResult to accept the
conversion object and populate the same conversion fields used elsewhere in the
response, then update both MouseInputPressActionExecutor call sites to pass the
existing conversion value so callers can see what was injected.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@Packages/src/Editor/FirstPartyTools/SimulateMouseInput/Skill/SKILL.md`:
- Line 80: The example in SKILL.md hardcodes “center” as if it always maps to
400x300, which is misleading for other Game View sizes. Update the sample label
around the SimulateMouseInput guidance to use a neutral description or derive
the click position from the current Game View dimensions so the example stays
accurate across sizes.

---

Nitpick comments:
In
`@Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputSimulationResponseFactory.cs`:
- Around line 45-55: Interrupted mouse button responses are missing the
coordinate-conversion metadata that is already available at the pause points.
Update MouseInputSimulationResponseFactory.InterruptedButtonResult to accept the
conversion object and populate the same conversion fields used elsewhere in the
response, then update both MouseInputPressActionExecutor call sites to pass the
existing conversion value so callers can see what was injected.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4078d4a1-5083-4120-9f3f-334b658d820c

📥 Commits

Reviewing files that changed from the base of the PR and between c5d2fd0 and 78b5554.

⛔ Files ignored due to path filters (2)
  • Assets/Tests/PlayMode/UnityCLILoop.Tests.PlayMode.asmdef is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/UnityCLILoop.FirstPartyTools.SimulateMouseInput.Editor.asmdef is excluded by none and included by none
📒 Files selected for processing (9)
  • .agents/skills/uloop-simulate-mouse-input/SKILL.md
  • .claude/skills/uloop-simulate-mouse-input/SKILL.md
  • Assets/Tests/PlayMode/SimulateMouseInputTests.cs
  • Packages/src/Editor/FirstPartyTools/Common/GameView/AssemblyInfo.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputPressActionExecutor.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/MouseInputSimulationResponseFactory.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/SimulateMouseInputResponse.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseInput/Skill/SKILL.md
  • cli/common/tools/default-tools.json

Comment thread Packages/src/Editor/FirstPartyTools/SimulateMouseInput/Skill/SKILL.md Outdated
CodeRabbit flagged that the example comment's "Game View center"
wording implies (400, 300) is universally the center, but that only
holds for one specific Game View resolution. Reworded to "a
representative Game View point" and regenerated the .claude/.agents
skill copies to match.
@hatayama
hatayama merged commit f6574dd into v3-beta Jul 9, 2026
10 checks passed
@hatayama
hatayama deleted the feat/mouse-coordinate-validation branch July 9, 2026 12:10
@github-actions github-actions Bot mentioned this pull request Jul 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant