# kwan3854/twentyfiveslicer architecture

> Architecture diagram of the GitHub repository kwan3854/twentyfiveslicer, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-03-18). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kwan3854/twentyfiveslicer
- Repository: https://github.com/kwan3854/twentyfiveslicer

## Overview

##### Project Type and Purpose
- This is a specialized Unity package designed to enhance sprite slicing by dividing a sprite into a 5x5 grid—providing 25 distinct slices. It supports both UI use via a custom Image component (TwentyFiveSliceImage) and non-UI 2D scenes via a MeshRenderer-based component (TwentyFiveSliceSpriteRenderer).
- The package is meant to work within Unity’s 2D workflow, integrating with Unity’s editor for slice configuration and with runtime modules for sprite rendering.

##### File Structure
- There are two primary directories:
– "Editor": Contains scripts that define editor windows, custom inspectors, menus, and tooling (e.g., TwentyFiveSliceEditor, image menus, data cleaners). This separation indicates that the package extends Unity’s editor functionality.
– "Runtime": Contains the core logic (e.g., SliceDataManager, SerializedDictionary, and sprite/rendering classes) that is used when a game is running. This separation enforces the common Unity practice of isolating editor-only code from runtime code using assembly definitions.
- Additional files (like package.json, .gitignore, etc.) indicate that this is a distributable package (on OpenUPM) that integrates with Unity’s Package Manager.

##### Insights from the README
- The README provides detailed instructions on installation (via several methods), usage (creating Slice Data Maps and editing sprites), and the two distinct runtime approaches (UI-based and 2D Scene-based).
- It emphasizes key features including detailed control over stretching and scaling of specific sprite areas, making it clear that the system revolves around precise, data-driven sprite manipulation.

##### Main Components and Their Relationships
- Editor Module:
- TwentyFiveSliceEditor: The entry point for configuring slice data.
- Additional Editor scripts (DraggingInfo, TwentyFiveSliceImageComponentInspector, etc.) display different functionalities (handling drag states, presenting menus, inspector customizations, etc.).
- The Slice Data Cleaner tool ensures outdated or unused data can be removed.
- Runtime Module:
- SliceDataManager and SliceDataMap: Responsible for storing and managing slice configuration data.
- TwentyFiveSliceImage and TwentyFiveSliceSpriteRenderer: Handle sprite display/rendering in UI and non-UI contexts respectively, ensuring that the slice configuration is applied at runtime.
- SerializedDictionary: Utility to handle key-value pairs needed by the slice management system.
- External Integration:
- Unity’s UI system (UGUI Canvas, GameObject hierarchy) when working with TwentyFiveSliceImage.
- Unity’s 2D system (SpriteRenderer with sorting layers) for the 2D scene approach using TwentyFiveSliceSpriteRenderer.
- Package Manager (OpenUPM) for package distribution and dependency management.

##### Architectural Patterns and Concepts
- Clear separation of concerns between Editor tooling and runtime functionality (using separate Unity assembly definitions).
- Data persistence and serialization provided by the SerializedDictionary module.
- Visual editor integration that invokes runtime functionality upon saving configuration (i.e., the slice data configured in the editor is used directly by runtime components).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Editor Components
    subgraph "Editor Components"
        TSE["TwentyFiveSliceEditor"]:::editor
        DI["DraggingInfo"]:::editor
        DS["DraggingState"]:::editor
        TSDC["TwentyFiveSliceDataCleaner"]:::editor
        TSICI["TwentyFiveSliceImageComponentInspector"]:::editor
        TSIM["TwentyFiveSliceImageMenu"]:::editor
        TSSRE["TwentyFiveSliceSpriteRendererEditor"]:::editor
        TSSRM["TwentyFiveSliceSpriteRendererMenu"]:::editor
    end

    %% Runtime Components
    subgraph "Runtime Components"
        SDM["SliceDataManager"]:::runtime
        SDMap["SliceDataMap"]:::runtime
        TSData["TwentyFiveSliceData"]:::runtime
        SerDict["SerializedDictionary"]:::runtime
        SerKVP["SerializableKeyValuePair"]:::runtime
        TSImage["TwentyFiveSliceImage"]:::runtime
        TSSprite["TwentyFiveSliceSpriteRenderer"]:::runtime
    end

    %% External Integration
    subgraph "Unity Integration"
        UPM["Unity Package Manager"]:::external
        UUIS["Unity UI System"]:::external
        U2DES["Unity 2D Engine"]:::external
    end

    %% Connections within Editor Components (internal relationships)
    TSE -->|"triggers"| DI
    DI -->|"updates"| DS
    TSE -->|"invokes"| TSDC
    TSE -->|"configures"| TSICI
    TSE -->|"opens"| TSIM
    TSE -->|"manages"| TSSRE
    TSSRE -->|"links to"| TSSRM

    %% Editor to Runtime interaction
    TSE ---|"savesConfiguration"| SDM

    %% Runtime internal flows
    SDM -->|"createsMap"| SDMap
    SDM -->|"persistsData"| TSData
    SDM -->|"utilizes"| SerDict
    SerDict -->|"maps"| SerKVP
    SDMap -->|"appliesToUI"| TSImage
    SDMap -->|"appliesTo2D"| TSSprite

    %% External integrations with Runtime Components
    UUIS ---|"rendersVia"| TSImage
    U2DES ---|"rendersVia"| TSSprite

    %% External integration with Editor Components
    UPM ---|"managesPackage"| TSE

    %% Styling Classes
    classDef editor fill:#AEDFF7,stroke:#333,stroke-width:2px;
    classDef runtime fill:#C7F7C4,stroke:#333,stroke-width:2px;
    classDef external fill:#F7E4AD,stroke:#333,stroke-width:2px;

    %% Click Events for Editor Components
    click TSE "https://github.com/kwan3854/twentyfiveslicer/blob/main/Editor/TwentyFiveSliceEditor.cs"
    click DI "https://github.com/kwan3854/twentyfiveslicer/blob/main/Editor/DraggingInfo.cs"
    click DS "https://github.com/kwan3854/twentyfiveslicer/blob/main/Editor/DraggingState.cs"
    click TSDC "https://github.com/kwan3854/twentyfiveslicer/blob/main/Editor/TwentyFiveSliceDataCleaner.cs"
    click TSICI "https://github.com/kwan3854/twentyfiveslicer/blob/main/Editor/TwentyFiveSliceImageComponentInspector.cs"
    click TSIM "https://github.com/kwan3854/twentyfiveslicer/blob/main/Editor/TwentyFiveSliceImageMenu.cs"
    click TSSRE "https://github.com/kwan3854/twentyfiveslicer/blob/main/Editor/TwentyFiveSliceSpriteRendererEditor.cs"
    click TSSRM "https://github.com/kwan3854/twentyfiveslicer/blob/main/Editor/TwentyFiveSliceSpriteRendererMenu.cs"

    %% Click Events for Runtime Components
    click SDM "https://github.com/kwan3854/twentyfiveslicer/blob/main/Runtime/SliceDataManager.cs"
    click SDMap "https://github.com/kwan3854/twentyfiveslicer/blob/main/Runtime/SliceDataMap.cs"
    click TSData "https://github.com/kwan3854/twentyfiveslicer/blob/main/Runtime/TwentyFiveSliceData.cs"
    click SerDict "https://github.com/kwan3854/twentyfiveslicer/blob/main/Runtime/SerializedDictionary/SerializedDictionary.cs"
    click SerKVP "https://github.com/kwan3854/twentyfiveslicer/blob/main/Runtime/SerializedDictionary/SerializableKeyValuePair.cs"
    click TSImage "https://github.com/kwan3854/twentyfiveslicer/blob/main/Runtime/TwentyFiveSliceImage.cs"
    click TSSprite "https://github.com/kwan3854/twentyfiveslicer/blob/main/Runtime/TwentyFiveSliceSpriteRenderer.cs"
```
