refactor: extract mouse UI pointer target resolution - #1634
Conversation
Expose the existing resolver entries at their final internal visibility and pin path lookup, drop handling, bypass hierarchy, pointer state, and no-hit behavior with synchronous EditMode tests before moving the implementation.
Move pointer data construction, hierarchy and path lookup, drop target validation, and their result DTOs into a stateless resolver. Keep the existing out-parameter contract for move-only review, while removing the redundant RaycastUI wrapper in favor of direct UiRaycastHelper calls.
📝 WalkthroughWalkthroughExtracts pointer/drop target resolution logic from ChangesMouse UI Pointer Target Resolver Extraction
Estimated code review effort: 3 (Moderate) | ~30 minutes Sequence Diagram(s)sequenceDiagram
participant UseCase as SimulateMouseUiUseCase
participant Resolver as MouseUiPointerTargetResolver
participant Hierarchy as GameObject Hierarchy
participant Raycast as UiRaycastHelper
UseCase->>Resolver: CreatePointerPressData(button, position)
UseCase->>Raycast: RaycastUI(position) [if not bypass]
Raycast-->>UseCase: RaycastResult
UseCase->>Resolver: ResolvePressablePointerTargets(command, raycastResult)
alt BypassRaycast enabled
Resolver->>Hierarchy: FindActiveGameObjectByPath(TargetPath)
Hierarchy-->>Resolver: matched GameObject or ambiguous/not-found
Resolver->>Resolver: CreateDirectRaycastResult(target)
else Raycast hit
Resolver->>Resolver: ResolveRaycastPressablePointerTargets(hitResult)
end
Resolver->>Resolver: CreateResolvedPressablePointerTargets(target)
Resolver-->>UseCase: ResolvedPointerTargets
UseCase->>Resolver: TryResolveDropTargetPath(dropPath) [drag flows]
Resolver->>Hierarchy: FindActiveGameObjectByPath(dropPath)
Resolver-->>UseCase: drop target or failure response
Possibly related PRs
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
No issues found across 7 files
You’re at about 95% 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.
|
@coderabbitai review |
✅ Action performedReview finished.
|
There was a problem hiding this comment.
🧹 Nitpick comments (1)
Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiPointerTargetResolver.cs (1)
190-219: 🚀 Performance & Scalability | 🔵 TrivialConsider caching or narrowing
FindObjectsByType<GameObject>for path resolution.
FindObjectsByType<GameObject>allocates an array of every GameObject in the scene on each call. InExecuteDragOneShot, this can be invoked twice per request (target path + drop target path). This is pre-existing behavior from the extraction, but as the resolver is now a centralized hot path, a future optimization could cache results per-frame or use a dictionary keyed by path.🤖 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/SimulateMouseUi/MouseUiPointerTargetResolver.cs` around lines 190 - 219, The hot-path lookup in FindActiveGameObjectByPath still scans all GameObjects via FindObjectsByType<GameObject> on every call, which is expensive when ExecuteDragOneShot resolves both target and drop target paths. Narrow the search or cache path-to-GameObject results for the duration of a frame/request, and reuse that cache from MouseUiPointerTargetResolver instead of rebuilding the full array each time.
🤖 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
`@Packages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiPointerTargetResolver.cs`:
- Around line 190-219: The hot-path lookup in FindActiveGameObjectByPath still
scans all GameObjects via FindObjectsByType<GameObject> on every call, which is
expensive when ExecuteDragOneShot resolves both target and drop target paths.
Narrow the search or cache path-to-GameObject results for the duration of a
frame/request, and reuse that cache from MouseUiPointerTargetResolver instead of
rebuilding the full array each time.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: e4926826-513f-4a7f-926b-7245ed196a10
⛔ Files ignored due to path filters (3)
Assets/Tests/Editor/MouseUiPointerTargetResolverTests.cs.metais excluded by none and included by nonePackages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiPointerTargetResolver.cs.metais excluded by none and included by nonePackages/src/Editor/FirstPartyTools/SimulateMouseUi/ResolvedPointerTargets.cs.metais excluded by none and included by none
📒 Files selected for processing (4)
Assets/Tests/Editor/MouseUiPointerTargetResolverTests.csPackages/src/Editor/FirstPartyTools/SimulateMouseUi/MouseUiPointerTargetResolver.csPackages/src/Editor/FirstPartyTools/SimulateMouseUi/ResolvedPointerTargets.csPackages/src/Editor/FirstPartyTools/SimulateMouseUi/SimulateMouseUiUseCase.cs
|
Reviewed the CodeRabbit caching nit. The full-scene scan is pre-existing and occurs only on explicit CLI bypass/drop path resolution; there is no measured performance problem. Adding a cache would introduce request lifetime, scene-mutation invalidation, and duplicate-path semantics beyond this move-only refactor. Under YAGNI, no code change or follow-up is warranted unless profiling demonstrates a real bottleneck. fable5 independently reviewed and agreed with this decision. |
Summary
MouseUiPointerTargetResolverResolvedPointerTargetsDTOSimulateMouseUiUseCasefrom 1,305 to 1,032 linesScope Notes
ResolvedPointerTargetsfrom private to their required final internal visibility. The final implementation retains the existing signatures and nullability.RaycastUIwrapper. Its resolver and executor callers now invokeUiRaycastHelper.RaycastUIdirectly, matching the existing drag-finalization caller.out-parameter contracts remain byte-equivalent for move-only review. Their conversion to an explicit result DTO is recorded separately as R2-41.Verification
dist/darwin-arm64/uloop compile(0 errors, 0 warnings)MouseUiPointerTargetResolverTestsbefore and after the move (10 passed)SimulateMouseUiTests(32 passed)MouseUiSimulationResponseFactoryTests(12 passed)SimulateMouseUiActionValidationTests(1 passed)PlayModeToolPreflightServiceTests(8 passed)StaticFacadeStateGuardTests(20 passed)OnionAssemblyDependencyTests(83 passed)RaycastUIdirect-call adaptation remains after visibility normalization)RaycastUIwrapper references (0)git diff --check origin/v3-beta...HEAD