keijiro/unity-skills/unity-sprite-segment-3x3grid
Claude Code and agent skill by keijiro/unity-skills
- community
Checking that the SKILL.md file is still in the repository.
Segments a Sprite texture into a 3x3 grid and outputs a pattern of cells matching the center cell's color. Use when asked to analyze, compare, or document a sprite's structure or color distribution.
Install
npx vskill@latest install keijiro/unity-skills/unity-sprite-segment-3x3gridSKILL.md
Sprite Color Grid Analysis
Segment a sprite's texture into a 3x3 grid and output a text pattern showing which cells match the center cell's majority color.
Important
- Use the unity cli (
unity command --format json) and theunity-cliandunity-pipelineskills for each step. - Don't use
usingdirectives or unqualified types in thesnippetforeval. The compiler reads usingUnityEngineand a bare AssetDatabase, Volume, or Object causes errors (CS0246 / CS0103 / CS0104).returnwhat you want to read; it arrives atdata.result.result. - Create a restore point you can roll back to if your changes fail.
- Do only what's asked. Don't change unrelated assets or files.
- Never leave verification code in the user's script. Never build logging or detection they didn't ask for. See Final step.
- Avoid long explanations.
- This skill reads a sprite and reports a pattern, so don't edit the user's files unless they ask. If they do, create the restore point just before the first edit.
Step 1
Before you go forward with a workflow or diagnosis:
- Open and read the documentation page(s) that cover the specific subject related to what you intend to do or fix and check if you've missed anything.
- Name the file(s) you read in your response.
This is because your training knowledge about Unity might be out of date, incorrect, or for the wrong Unity version.
Full topic map
If the Editor install folder has a Data/Documentation folder (eg ...Unity/Hub/Editor/6000.6.0b2/Editor/Data/Documentation), read the html files from the en/Manual folder.
Otherwise the docs pages are online at https://docs.unity.com/en-us/engine/<VERSION>/manual/. Prefer fetching the page directly (for example WebFetch) over searching (for example WebSearch) — faster and lands on the exact reference. Only fetch what you need, and only search if you don't have the exact URL. Replace <VERSION> with the following before fetching:
- docs.unity3d.com: The Unity version, eg
6000.6 - Package on docs.unity3d.com: The package version, eg
@6.6or@2.0. Check the package version if unsure. - Engine on docs.unity.com: The Unity version, eg
6000.3 - docs.unity.com: The product version, eg
7000.0
For these Engine pages, <VERSION> is the Unity major.minor from ProjectSettings/ProjectVersion.txt, for example 6000.0 from 6000.0.58f1, because the full build number gives a 404.
Before fetching, check that <VERSION> is listed as a ## Version heading in https://docs.unity.com/en-us/engine/llms.txt. If it isn't, use the docs.unity3d.com Manual instead. The two sites use different page names, so don't reuse the paths below. Instead, find each page by its title in https://docs.unity3d.com/<VERSION>/Documentation/Manual/docdata/toc.js, then fetch https://docs.unity3d.com/<VERSION>/Documentation/Manual/<link>.html, where <link> is the link value next to the title.
- Import a sprite or spritesheet texture — local
sprite/import-images-sprites/import-images-sprites-landing.html: setting a texture's type to Sprite (2D and UI). - Cut out sprites from a texture — local
sprite/unity-sprite-editor/use-editor.html: how the Sprite Editor defines each sprite's rectangle. - Sprite asset reference — local
class-Sprite.html: the properties of a sprite asset in the Inspector. - Sprite (2D and UI) texture Import Settings window reference — local
texture-type-sprite.html: sprite texture import settings, including Read/Write access.
API reference
The API is UnityEngine.Sprite (rect, texture) and UnityEngine.Texture2D (GetPixel), part of the Unity Engine. It is versioned by Unity version, so check the project's Unity version before relying on a specific class or method.
- Use the
unity-cliskill to check the project's Unity version. - If the Editor install folder has a
Data/Documentationfolder (e.g..../Unity/Hub/Editor/6000.6.0b2/Editor/Data/Documentation), grep the html files in theen/ScriptReferencefolder inside, and skip the remaining steps. - Otherwise, fetch and cache
https://docs.unity3d.com/<VERSION>/Documentation/ScriptReference/xrefmap.yml(replace<VERSION>with the Unity version, e.g.6000.3). This file lists every public API member's fully qualified name as auid(e.g.uid: 'UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3)'). - Grep the yml file locally for a class or method instead of refetching per lookup. The file is large (about 6 MB), so don't read the whole file.
- Convert the
uidto a markdown page: remove the parameters in brackets, lowercase it, replace.with/, and add.md. Then fetchhttps://docs.unity.com/en-us/engine/<VERSION>/script-reference/<converted uid>. For example,UnityEngine.Rigidbody.AddForce(UnityEngine.Vector3)=>https://docs.unity.com/en-us/engine/<VERSION>/script-reference/unityengine/rigidbody/addforce.md. All overloads are on the same page.
- Constructors use
ctor(e.g.unityengine/vector3/ctor.md), and indexers useitem(e.g.unityengine/vector3/item.md). - For operators, fetch the class page (e.g.
unityengine/vector3.md) and follow its link. - Links inside the pages start with
/engine/. Addhttps://docs.unity.com/en-usbefore them. - If the page doesn't exist for that Unity version, use the
hrefin thexrefmap.ymlentry instead (e.g.href: 'Rigidbody.AddForce.html'=>https://docs.unity3d.com/<VERSION>/Documentation/ScriptReference/Rigidbody.AddForce.html).
On Unity versions earlier than 6000.0, which have no xrefmap.yml, skip steps 3 to 5 and fetch the class or member page directly, for example https://docs.unity3d.com/<VERSION>/Documentation/ScriptReference/Sprite-rect.html.
Always use the docs for the project's Unity version rather than relying on training knowledge, since APIs are frequently marked obsolete between versions.
Step 2. Procedure
- Get the Unity version from
ProjectSettings/ProjectVersion.txt, the sprite to analyze, and the match threshold. If there's no project or no version, assume Unity 6000.0, say so in your answer, and carry on. If the user gives no threshold, use the default from Match Threshold. If the user names no sprite, ask for it. - Read the documentation pages for what you're about to do.
- Run the Algorithm on the sprite, following the Implementation Guidance. Use scripts/SpriteGridAnalysis.cs as the code template. If you can't read the sprite's pixels (for example, there's no project), say so, explain how you'd calculate each cell, and carry on to the report.
- Check the result against the Output Format: one line, three groups of three symbols separated by
/, with*in the center. If it doesn't match, reread the documentation pages and the Algorithm, and run the analysis again. - If you changed the project or ran code in the Editor, run the checks in the Final step.
- Report the result as described in the Final report.
Parameters
Match Threshold
The match threshold determines what percentage of pixels in a non-center cell must match the center's majority color for you to mark that cell as a match (.).
| Threshold | Description | Use Case | |
|---|---|---|---|
| 50% | At least half the cell's pixels match center color | Lenient matching for sprites with mixed regions | |
| 75% | At least three-quarters match center color | Moderate matching for mostly solid regions | |
| 90% | Nearly all pixels must match center color | Strict matching for very uniform sprites |
Default: 75%
Algorithm
- Segment the Sprite: Divide the Sprite's texture region into a 3x3 grid (9 cells total)
- Identify Center Color: Calculate the majority (most frequent) color in the center cell (position [1,1])
- Compare Each Cell: For each of the 8 surrounding cells, calculate what percentage of pixels match the center's majority color. If the percentage meets or exceeds the match threshold, the cell is a match (
.); otherwise it is not (X) - Generate Output: Create a text representation using the legend below
Output Legend
| Symbol | Meaning | |
|---|---|---|
X | Cell does NOT meet the match threshold (insufficient pixels match center color) | |
. | Cell MEETS the match threshold (enough pixels match center color) | |
* | The center cell itself (always position [1,1] in the grid) |
Output Format
Output a single line with three groups of three characters, separated by / . Each group represents one row of the grid.
Order: Top to Bottom rows, Left to Right within each row.
Format: [TopRow] / [MiddleRow] / [BottomRow]
Each row contains 3 characters separated by spaces: [Left] [Center] [Right]
Grid Position Mapping
Examples
Example 1: Center matches top-left and bottom-right only
Grid interpretation:
Example 2: Center matches all surrounding cells
Example 3: Center matches none of the surrounding cells
Example 4: Center matches bottom row only
Implementation Guidance
Calculating Center's Majority Color
For the center cell:
- Sample all pixels within the cell's bounds
- Group pixels by color (consider using a color tolerance threshold for similar colors)
- The majority color is the color with the highest pixel count
- For tie-breaking, use the first color encountered
Matching Non-Center Cells
For each of the 8 surrounding cells:
- Count the total number of pixels in the cell
- Count how many pixels match the center's majority color (using color tolerance)
- Calculate the match percentage:
matchingPixels / totalPixels - If match percentage >= threshold, cell is a match (
.); otherwise (X)
Color Tolerance
When comparing pixel colors:
- Consider using a tolerance threshold (e.g., RGB distance < 10) for "matching"
- Alternatively, for sprites with limited palettes, exact matching may be appropriate
- Account for alpha channel if relevant to the use case
Sprite Bounds
Use the Sprite's rect property to determine the pixel region to analyze:
sprite.rect.x,sprite.rect.yfor the originsprite.rect.width,sprite.rect.heightfor dimensions- Divide width and height by 3 to get cell dimensions
Notes
- This analysis works best with sprites that have distinct color regions
- For sprites with gradients or many colors, consider increasing color tolerance
- Flip the y-axis from Unity's texture coordinates so the output runs top to bottom
- Treat transparent pixels as a distinct "color", or ignore them, depending on the use case
Final step
Do the following checks:
- Check the project has zero console errors. Use
console_statusfor counts. - Stop there unless the user asked you to prove it works or you suspect a specific fault.
If a check fails, go back and reread the docs pages to find out what you missed.
Final report
This is the start of the file. Read the full SKILL.md on GitHub.
Security
- Security scanPassed, 90 of 100Pattern checks on the skill's files.
- Model reviewPassed
Quality evaluation
- Task evaluationNot runNo evaluation yet. Run one in Skill Studio.
Source
- SKILL.md in the repositoryCheckingskills/unity-sprite-segment-3x3grid/SKILL.md
Popularity
- 7-day trend score
- 0
Not refreshed yet.
Works with
Any agent vskill installs to: 56 targets in all. These 39 have a page on this site.
- Claude Code
- Cursor
- GitHub Copilot
- Windsurf
- Codex
- Gemini CLI
- Cline
- Amp
- Roo Code
- Goose
- Continue
- Kilo Code
- Junie
- Trae
- OpenHands
- Qwen Code
- AI Agent
- Tabnine Chat
- Sourcegraph Cody
- Amazon Q
- Firebase Genkit
- Sweep
- Devin
- Phind
- Mentat
- Claude Desktop
- Aider
- GPT Pilot
- Plandex
- bolt.new
- v0
- Replit Agent
- Anse
- TypingMind
- BetterChatGPT
- LibreChat
- Warp AI
- Pieces
- Fig AI
Embed badge
[](https://verified-skill.com/skills/keijiro/unity-skills/unity-sprite-segment-3x3grid)