Skip to content

chore: simplify mouse UI drag orchestration#1638

Merged
hatayama merged 2 commits into
v3-betafrom
refactor/hatayama/extract-mouse-ui-incremental-drag
Jul 8, 2026
Merged

chore: simplify mouse UI drag orchestration#1638
hatayama merged 2 commits into
v3-betafrom
refactor/hatayama/extract-mouse-ui-incremental-drag

Conversation

@hatayama

@hatayama hatayama commented Jul 8, 2026

Copy link
Copy Markdown
Owner

Summary

  • Complete the final R2-33 extraction so mouse UI simulation remains easier to review and maintain.
  • Preserve all existing one-shot and incremental drag behavior while reducing the use case to a thin action dispatcher.

User Impact

  • There is no intended user-visible behavior change.
  • Drag target selection, response priority, animation timing, cancellation cleanup, and persistent drag state remain unchanged.

Changes

  • Add a shared drag target resolver for path/raycast resolution and IDragHandler lookup.
  • Reuse the resolver from one-shot drag and DragStart while preserving the observable failure order: start-target failure, drop-target failure, then no-handler fallback.
  • Move DragStart, DragMove, DragEnd, and active-drag validation into MouseUiIncrementalDragExecutor.
  • Keep MouseDragState ownership unchanged and pass the main-thread cleanup scheduler explicitly.
  • Reduce SimulateMouseUiUseCase from 434 lines to 137 lines.

Verification

  • Confirmed the resolver tests fail before implementation (0/3) and pass after implementation (3/3).
  • Passed the focused EditMode suites (141/141).
  • Passed the Simulate Mouse UI PlayMode suite before and after each extraction commit (32/32).
  • Compiled the Unity package with 0 errors and 0 warnings.
  • Compared the moved incremental drag block after normalizing static modifiers, scheduler arguments, and signatures; the only remaining difference was a trailing blank line.
  • Verified both cleanup lambdas still call FinalizeDrag before MouseDragState.Clear with the same captures and timing.

Compatibility

  • No IPC request or response shape changed, so the protocol version remains unchanged.
  • R2-40 and R2-41 remain separate follow-up tasks.

Review in cubic

hatayama added 2 commits July 9, 2026 06:40
Centralize path and raycast lookup through drag-handler resolution while preserving action-specific no-handler responses and one-shot failure precedence. Add synchronous coverage for bypass handlers, missing handlers, and path failures.
Move DragStart, DragMove, and DragEnd orchestration into a focused executor so SimulateMouseUiUseCase remains a thin action dispatcher. Keep drag state ownership, cleanup ordering, scheduler timing, and response behavior unchanged.
@coderabbitai

coderabbitai Bot commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

This PR extracts drag target resolution into a new MouseUiDragTargetResolver, used by both MouseUiOneShotDragExecutor and a new MouseUiIncrementalDragExecutor, which now hosts the drag start/move/end lifecycle previously implemented inline in SimulateMouseUiUseCase. Tests cover the new resolver.

Changes

Drag target resolution and executor refactor

Layer / File(s) Summary
MouseUiDragTargetResolver implementation and tests
Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiDragTargetResolver.cs, Assets/Tests/Editor/MouseUiDragTargetResolverTests.cs
New Resolve method computes starting raycast and drag target via bypass-path or UI raycast, resolving the nearest IDragHandler; tests cover handler-found, no-handler, and missing-path scenarios.
One-shot drag executor integration
Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiOneShotDragExecutor.cs
Replaces inline raycast/target-path resolution and IDragHandler lookup with a single call to MouseUiDragTargetResolver.Resolve, returning early on failure.
MouseUiIncrementalDragExecutor lifecycle
Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiIncrementalDragExecutor.cs
New static executor implements ExecuteDragStart/Move/End and ValidateDragStillActive, managing MouseDragState, overlay animation, interpolation, timeout handling, and cleanup.
SimulateMouseUiUseCase delegation
Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs
Removes local drag implementations and UnityEditor import; ExecuteMouseAction now delegates drag cases to MouseUiIncrementalDragExecutor.

Estimated code review effort: 4 (Complex) | ~60 minutes

Sequence Diagram(s)

sequenceDiagram
  participant SimulateMouseUiUseCase
  participant MouseUiIncrementalDragExecutor
  participant MouseUiDragTargetResolver
  participant MouseDragState
  participant MouseUiOverlayState

  SimulateMouseUiUseCase->>MouseUiIncrementalDragExecutor: ExecuteDragStart()
  MouseUiIncrementalDragExecutor->>MouseUiDragTargetResolver: Resolve(bypass or raycast)
  MouseUiDragTargetResolver-->>MouseUiIncrementalDragExecutor: startRaycast, target, failure
  MouseUiIncrementalDragExecutor->>MouseDragState: set Target/PointerData
  MouseUiIncrementalDragExecutor->>MouseUiOverlayState: update start overlay

  SimulateMouseUiUseCase->>MouseUiIncrementalDragExecutor: ExecuteDragMove()
  MouseUiIncrementalDragExecutor->>MouseDragState: ValidateDragStillActive()
  MouseUiIncrementalDragExecutor->>MouseUiOverlayState: update move overlay

  SimulateMouseUiUseCase->>MouseUiIncrementalDragExecutor: ExecuteDragEnd()
  MouseUiIncrementalDragExecutor->>MouseDragState: FinalizeDrag / clear
  MouseUiIncrementalDragExecutor->>MouseUiOverlayState: dissipate overlay
Loading

Possibly related PRs

  • hatayama/unity-cli-loop#996: Prior implementation of bypass-raycast/target-path drag resolution logic now centralized into MouseUiDragTargetResolver.
  • hatayama/unity-cli-loop#1333: Overlaps with the same drag lifecycle area in SimulateMouseUiUseCase/drag executors regarding timeout-aware drag handling.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately summarizes the refactor to mouse UI drag orchestration.
Description check ✅ Passed The description is clearly aligned with the refactor and its stated no-behavior-change goal.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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 docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch refactor/hatayama/extract-mouse-ui-incremental-drag

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.

@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.

🧹 Nitpick comments (1)
Assets/Tests/Editor/MouseUiDragTargetResolverTests.cs (1)

38-117: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Consider adding a test for the non-bypass (raycast) resolution path.

All three tests use BypassRaycast = true, leaving the raycast branch (resolver lines 45-49) uncovered at the unit level. A test that sets up a Canvas with a raycast-target Graphic and calls Resolve with BypassRaycast = false would verify the UiRaycastHelper.RaycastUIExecuteEvents.GetEventHandler<IDragHandler> flow directly through the new resolver API.

🤖 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 `@Assets/Tests/Editor/MouseUiDragTargetResolverTests.cs` around lines 38 - 117,
Add a unit test that covers the non-bypass raycast path in
MouseUiDragTargetResolver.Resolve, since the current tests only exercise the
bypass flow via BypassRaycast = true. Create a Canvas with a raycast-target
Graphic, call Resolve with BypassRaycast = false, and assert the raycast result
and handler resolution from UiRaycastHelper.RaycastUI through
ExecuteEvents.GetEventHandler<IDragHandler>. Use
MouseUiDragTargetResolver.Resolve and the existing test helpers as the entry
points to keep the new test aligned with the current suite.
🤖 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.

Nitpick comments:
In `@Assets/Tests/Editor/MouseUiDragTargetResolverTests.cs`:
- Around line 38-117: Add a unit test that covers the non-bypass raycast path in
MouseUiDragTargetResolver.Resolve, since the current tests only exercise the
bypass flow via BypassRaycast = true. Create a Canvas with a raycast-target
Graphic, call Resolve with BypassRaycast = false, and assert the raycast result
and handler resolution from UiRaycastHelper.RaycastUI through
ExecuteEvents.GetEventHandler<IDragHandler>. Use
MouseUiDragTargetResolver.Resolve and the existing test helpers as the entry
points to keep the new test aligned with the current suite.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 2f44ae6d-d0b3-45f9-ac8e-53e6122b5fdc

📥 Commits

Reviewing files that changed from the base of the PR and between 9da9360 and a9366ec.

⛔ Files ignored due to path filters (3)
  • Assets/Tests/Editor/MouseUiDragTargetResolverTests.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiDragTargetResolver.cs.meta is excluded by none and included by none
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiIncrementalDragExecutor.cs.meta is excluded by none and included by none
📒 Files selected for processing (5)
  • Assets/Tests/Editor/MouseUiDragTargetResolverTests.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiDragTargetResolver.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiIncrementalDragExecutor.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiOneShotDragExecutor.cs
  • Packages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No issues found across 8 files

You’re at about 98% of the monthly reviewed-line limit. You may want to disable incremental reviews to conserve quota. Reviews will continue until that limit is exceeded. If you need help avoiding interruptions, please contact contact@cubic.dev.

Re-trigger cubic

@hatayama
hatayama merged commit 37b9f5d into v3-beta Jul 8, 2026
10 checks passed
@hatayama
hatayama deleted the refactor/hatayama/extract-mouse-ui-incremental-drag branch July 8, 2026 21:58
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