Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions .agents/skills/uloop-raycast/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: uloop-raycast
toolName: raycast
description: "Raycast from Camera.main through a Game View coordinate. Use when you need to check what a screenshot coordinate would hit in 3D physics before clicking or long-pressing with simulate-mouse-ui."
---

# uloop raycast

Check what a top-left Game View coordinate hits in 3D physics.

## Usage

```bash
uloop raycast --x <x> --y <y> [--layer-mask <mask>] [--max-distance <distance>]
```

## Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `--x` | number | `0` | Target X position in Game View pixels (origin: top-left). |
| `--y` | number | `0` | Target Y position in Game View pixels (origin: top-left). |
| `--layer-mask` | number | Unity default raycast layers | Physics layer mask used by the raycast. |
| `--max-distance` | number | `1000` | Maximum raycast distance in world units. |

## Coordinate System

- `--x` / `--y` use the same top-left Game View input coordinates as `simulate-mouse-ui`.
- Do not flip Y in the caller. The tool converts internally:

```text
unity_x = input_x
unity_y = gameViewHeight - input_y
```

## Examples

```bash
# Check what is under a screenshot coordinate
uloop raycast --x 960 --y 540

# Check only specific layers
uloop raycast --x 960 --y 540 --layer-mask 1
```

## Output

Returns JSON with:
- `Success`: Whether the command completed
- `Message`: Status message
- `Hit`: Whether physics hit anything
- `HitGameObjectName` / `HitGameObjectPath`: Hit object identity when `Hit` is true
- `HitLayer` / `HitLayerName`: Hit object layer when `Hit` is true
- `Distance`, `HitPointX/Y/Z`, `HitNormalX/Y/Z`: Hit details when `Hit` is true
- `InputCoordinateSystem`, `UnityCoordinateSystem`, `GameViewWidth/Height`, `InputPositionX/Y`, `InjectedUnityPositionX/Y`, `CoordinateConversionFormula`: Coordinate conversion details

## Notes

- Requires an active `Camera.main`.
- Uses Unity Physics raycasts, not UI EventSystem raycasts.
60 changes: 60 additions & 0 deletions .claude/skills/uloop-raycast/SKILL.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
---
name: uloop-raycast
toolName: raycast
description: "Raycast from Camera.main through a Game View coordinate. Use when you need to check what a screenshot coordinate would hit in 3D physics before clicking or long-pressing with simulate-mouse-ui."
---

# uloop raycast

Check what a top-left Game View coordinate hits in 3D physics.

## Usage

```bash
uloop raycast --x <x> --y <y> [--layer-mask <mask>] [--max-distance <distance>]
```

## Parameters

| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `--x` | number | `0` | Target X position in Game View pixels (origin: top-left). |
| `--y` | number | `0` | Target Y position in Game View pixels (origin: top-left). |
| `--layer-mask` | number | Unity default raycast layers | Physics layer mask used by the raycast. |
| `--max-distance` | number | `1000` | Maximum raycast distance in world units. |

## Coordinate System

- `--x` / `--y` use the same top-left Game View input coordinates as `simulate-mouse-ui`.
- Do not flip Y in the caller. The tool converts internally:

```text
unity_x = input_x
unity_y = gameViewHeight - input_y
```

## Examples

```bash
# Check what is under a screenshot coordinate
uloop raycast --x 960 --y 540

# Check only specific layers
uloop raycast --x 960 --y 540 --layer-mask 1
```

## Output

Returns JSON with:
- `Success`: Whether the command completed
- `Message`: Status message
- `Hit`: Whether physics hit anything
- `HitGameObjectName` / `HitGameObjectPath`: Hit object identity when `Hit` is true
- `HitLayer` / `HitLayerName`: Hit object layer when `Hit` is true
- `Distance`, `HitPointX/Y/Z`, `HitNormalX/Y/Z`: Hit details when `Hit` is true
- `InputCoordinateSystem`, `UnityCoordinateSystem`, `GameViewWidth/Height`, `InputPositionX/Y`, `InjectedUnityPositionX/Y`, `CoordinateConversionFormula`: Coordinate conversion details

## Notes

- Requires an active `Camera.main`.
- Uses Unity Physics raycasts, not UI EventSystem raycasts.
54 changes: 54 additions & 0 deletions Assets/Tests/Editor/GameViewCoordinateUtilityTests.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
using NUnit.Framework;
using UnityEngine;

using io.github.hatayama.UnityCliLoop.FirstPartyTools;

namespace io.github.hatayama.UnityCliLoop.Tests.Editor
{
/// <summary>
/// Test fixture that verifies Game View Coordinate Utility behavior.
/// </summary>
public class GameViewCoordinateUtilityTests
{
[Test]
public void ConvertInputToUnity_WhenInputIsNearTop_ShouldFlipYWithinGameView()
{
// Tests that a coordinate near the top-left origin flips to a high Unity Y within the Game View.
Vector2 gameViewSize = new Vector2(1920f, 1080f);
Vector2 inputPosition = new Vector2(0f, 100f);

GameViewCoordinateConversion conversion =
GameViewCoordinateUtility.ConvertInputToUnity(inputPosition, gameViewSize);

Assert.That(conversion.InputPosition, Is.EqualTo(inputPosition));
Assert.That(conversion.InjectedUnityPosition, Is.EqualTo(new Vector2(0f, 980f)));
Assert.That(conversion.GameViewSize, Is.EqualTo(gameViewSize));
}

[Test]
public void ConvertInputToUnity_WhenInputIsAtCenter_ShouldKeepCenterY()
{
// Tests that a coordinate at the Game View center converts to the same center Y in Unity space.
Vector2 gameViewSize = new Vector2(1920f, 1080f);
Vector2 inputPosition = new Vector2(960f, 540f);

GameViewCoordinateConversion conversion =
GameViewCoordinateUtility.ConvertInputToUnity(inputPosition, gameViewSize);

Assert.That(conversion.InjectedUnityPosition, Is.EqualTo(new Vector2(960f, 540f)));
}

[Test]
public void ConvertInputToUnity_WhenInputIsAtBottomRight_ShouldMapToBottomLeftOrigin()
{
// Tests that the top-left Game View bottom-right corner maps to Unity's bottom-left Y origin.
Vector2 gameViewSize = new Vector2(1920f, 1080f);
Vector2 inputPosition = new Vector2(1920f, 1080f);

GameViewCoordinateConversion conversion =
GameViewCoordinateUtility.ConvertInputToUnity(inputPosition, gameViewSize);

Assert.That(conversion.InjectedUnityPosition, Is.EqualTo(new Vector2(1920f, 0f)));
}
}
}
11 changes: 11 additions & 0 deletions Assets/Tests/Editor/GameViewCoordinateUtilityTests.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading
Loading