com.xmobitea.changx.mini-texturecrop
v1.5.2
Published
XmobiTea Unity Toolkit packages
Readme
XmobiTea TextureCrop
Editor-only texture cropping window for opening an image file, adjusting board/offset/scale, and saving the baked result.
AI Quick Contract
- This package is
Editor-only - Main window:
TextureCropWindowsEditor - Main menus:
XmobiTea Tools/Texture Crop/Show WindowsAssets/Texture Crop/Show Windows
- Works with selected
Texture2DorSprite Applyoverwrites the currently opened file on diskSave Aswrites a new file and reopens it- The tool edits raw image bytes, not Unity importer metadata
- Current
9-Slicemode is pixel-cropping logic, not Unity sprite border authoring - Save implementation only handles
.pngand.jpg, even though the dialog also offers.jpegand.jpe
What This Package Provides
- fixed-size editor utility window for image cropping
- manual board size and scaling controls
- trim and power-of-two helpers
- undo/redo state stacks
- corner-only
9-Slicecrop mode
Exact Editor Behavior
Opening The Tool
Menus:
XmobiTea Tools/Texture Crop/Show Windows
Assets/Texture Crop/Show WindowsAssets/Texture Crop/Show Windows is only valid when the current selection is:
Texture2DSprite
The asset-path flow opens the selected file from disk and loads it into a temporary Texture2D.
Board Size And Canvas Behavior
Initial/default board size is:
512 x 512Allowed board-size range is clamped to:
4 .. 8192The tool keeps separate concepts for:
- source texture pixels
- board width/height
- offset around the board
- scale applied before baking the final texture
Apply
Apply:
- bakes the current board result through
TextureCropUtility.GetLastTexture(...) - overwrites the currently opened file path on disk
- reloads the baked texture into the editor window
This is a destructive in-place save for the opened file.
Save As
Save As:
- opens a file dialog
- bakes the current board result
- writes the new file
- reopens that file in the editor window
Important quirk:
the save dialog offers png,jpg,jpeg,jpe, but actual save code only writes bytes for .png and .jpg.
Practical consequence:
choosing .jpeg or .jpe is not a safe documented workflow.
Trim()
Trim() scans for non-transparent bounds and crops the texture to that rectangle.
Important quirk: the code compares pixels against the exact color:
new Color(1, 1, 1, 0)So this is not a generic "alpha == 0" trim rule. It is an exact transparent-color comparison.
POT()
POT():
- calls
Trim() - expands board width and height to the next power of two
- keeps a minimum dimension of
4
9-Slice
Current 9-Slice mode:
- enters selection mode
- captures four corner regions using left/right/top/bottom ratios
- merges those corners into a new texture
- runs
Trim() - runs
POT()
Important consequence: this does not write Unity sprite border metadata. It only creates a new pixel texture based on the four corners.
Undo / Redo
Undo and redo are in-memory stacks of cloned Texture2D states.
Practical consequence: large textures can increase memory use while the window stays open.
Required Setup
No runtime or scene setup is required.
This package is editor-only.
Do / Don't
Do
- Do treat this as raw image-file editing.
- Do expect
Applyto overwrite the current file. - Do prefer
.pngor.jpgwhen saving. - Do describe
9-Sliceas texture processing, not sprite import configuration. - Do use the asset-context menu for selected sprites or textures.
Don't
- Don't generate runtime code around this package.
- Don't claim that the tool edits Unity sprite border metadata.
- Don't present
.jpegand.jpeas safe save targets. - Don't describe
Trim()as a generic alpha-only trim without noting the exact transparent-color comparison.
Common Mistakes
Mistake 1: Treating Apply as non-destructive preview
Apply writes back to the current file path.
Mistake 2: Treating 9-Slice as importer border setup
The tool only manipulates pixels.
Mistake 3: Assuming all save extensions from the dialog are implemented
Current save code only handles .png and .jpg.
Mistake 4: Assuming trim checks only alpha
The code compares against exact transparent white (1, 1, 1, 0).
Namespace
using XmobiTea.TextureCrop.Editor;Package Metadata
- Package name:
com.xmobitea.changx.mini-texturecrop - Unity version:
2022.3+ - License:
Apache-2.0
