Home

Awesome

Twenty Five Slicer

openupm

Twenty Five Slicer is a Unity package designed for more advanced sprite slicing, enabling a "25-slice" approach. It divides a sprite into a 5x5 grid, allowing precise scaling and manipulation of individual regions while preserving key areas.


9-slice vs 25-slice

<p align="center"> <img src="Documentation~/Images/9slice_vs_25slice.gif" alt="9-slice vs 25-slice" width="350" /> <img src="Documentation~/Images/9slice_vs_25slice_2.gif" alt="9-slice vs 25-slice 2" width="350" /> </p>

Key Concept

<p align="center"> <img src="Documentation~/Images/25slice_debugging_view.gif" alt="25-slice Debugging View" width="700" /> </p>

This allows for far more detailed slicing. Where traditional 9-slice images often require stacking multiple image layers to achieve complex UI shapes (e.g., speech bubbles, boxes with icons or separators at the center), a 25-slice configuration can often handle these scenarios with just a single image.


Installing the Package

1. Install via OpenUPM

1.1. Install via Package Manager

Please follow the instructions:

  1. Open Edit → Project Settings → Package Manager
  2. Add a new Scoped Registry (or edit the existing OpenUPM entry)
  1. Click Save or Apply
  2. Open Window → Package Manager
  3. Click the + button
  4. Select Add package by name... (or Add package from git URL...)
  5. Paste com.kwanjoong.twentyfiveslicer into Name
  6. Paste a version (e.g., 1.1.0) into Version
  7. Click Add

1.2. Alternatively, merge the snippet into Packages/manifest.json

{
  "scopedRegistries": [
    {
      "name": "package.openupm.com",
      "url": "https://package.openupm.com",
      "scopes": []
    }
  ],
  "dependencies": {
    "com.kwanjoong.twentyfiveslicer": "1.1.0"
  }
}

1.3. Install via command-line interface

openupm add com.kwanjoong.twentyfiveslicer

2. Install via Git URL

  1. Open the Unity Package Manager.
  2. Select Add package from Git URL.
  3. Enter: https://github.com/kwan3854/twentyfiveslicer.git
  4. To install a specific version, append a version tag, for example:
    https://github.com/kwan3854/twentyfiveslicer.git#v1.0.0

How to Use

Create Slice Data Map (First-time Setup)

  1. Navigate to the Assets/Resources folder. (Create it if it doesn’t exist.)
  2. Right-click → Create → TwentyFiveSlicer → SliceDataMap
<p align="center"> <img src="Documentation~/Images/how_to_add_25slice_datamap.png" alt="How to Add 25-slice DataMap" width="550" style="display:inline-block; margin-right:20px;" /> <img src="Documentation~/Images/sliceDataMap.png" alt="SliceDataMap Example" width="200" style="display:inline-block;" /> </p>

Editing a Sprite

  1. Open the 25-Slice Editor
<p align="center"> <img src="Documentation~/Images/how_to_open_editor.png" alt="How to Open 25-Slice Editor" width="700" /> </p>
  1. Load Your Sprite
  1. Adjust the Slices
<p align="center"> <img src="Documentation~/Images/editor.png" alt="25-Slice Editor" width="700" /> </p>
  1. Save the Configuration

Using the 25-Sliced Sprite

1. Using with UI (TwentyFiveSliceImage)

This is the UI approach, similar to UnityEngine.UI.Image:

  1. Create a TwentyFiveSliceImage GameObject or add TwentyFiveSliceImage to an existing UI element in a Canvas.
  2. Assign your 25-sliced sprite to the TwentyFiveSliceImage.
  3. Adjust the RectTransform size to see how each slice region scales or remains fixed.
<p align="center"> <img src="Documentation~/Images/how_to_add_25slice_gameobject.png" alt="How to Add 25-Slice GameObject" width="700" /> </p> <p align="center"> <img src="Documentation~/Images/image_component.png" alt="How to Add 25-Slice GameObject" width="700" /> </p>

2. Using with 2D Scenes (TwentyFiveSliceSpriteRenderer)

This is the MeshRenderer-based approach, similar to SpriteRenderer:

  1. You can create a 25-Sliced Sprite in the Hierarchy:
  1. In the Inspector, assign your 25-sliced sprite to its Sprite field.
  2. Adjust the Size property in the Inspector (instead of using transform.localScale) to properly stretch or preserve corners/edges as needed.
  3. Sorting Layer and Order in Layer are also available, just like a normal SpriteRenderer.
<p align="center"> <img src="Documentation~/Images/sprite_renderer_menu.png" alt="How to Add 25-Slice GameObject" width="700" /> </p> <p align="center"> <img src="Documentation~/Images/sprite_renderer_component.png" alt="How to Add 25-Slice GameObject" width="700" /> </p>

Key Features


Delete Unused Data

You can remove slice data that is no longer needed: Tools → Twenty Five Slicer Tools → Slice Data Cleaner


For more information or contributions, visit the repository.