Made the popup system a lot more generic

This commit is contained in:
Sebastian Bularca
2026-04-06 20:38:58 +02:00
parent fa7659d905
commit cfe202da44
21 changed files with 840 additions and 682 deletions

View File

@@ -4,16 +4,18 @@
### Prefabs
Reference prefabs for the popup system. Copy these into your project as a starting point.
Reference prefabs for the popup system. Copy these into your project as a starting point. After copying, add entries to your `PopupSettings` asset's Element Prefabs list mapping `PopupElementType` values to these prefabs.
| Prefab | Description |
|---|---|
| `PopupReferencePrefab` | Main popup container with Canvas, CanvasGroup, Background, and Content |
| `PopupHeader` | Header text element (TMP_Text, bold, larger font) |
| `PopupText` | Body text element (TMP_Text, regular) |
| `PopupStat` | Stat row element (HorizontalLayoutGroup with label + value TMP_Text) |
| `PopupIcon` | Image element for icons or artwork |
| `PopupSeparator` | Horizontal divider line (Image, thin) |
| Prefab | PopupElementType | Description |
|---|---|---|
| `PopupReferencePrefab` | N/A | Main popup container with Canvas, CanvasGroup, Background, and Content |
| `PopupHeader` | `Header` ("header") | Header text element (TMP_Text, bold, larger font) |
| `PopupText` | `Text` ("text") | Body text element (TMP_Text, regular) |
| `PopupStat` | `LabelValueText` ("label_value_text") | Label + value row (HorizontalLayoutGroup with two TMP_Text children) |
| `PopupIcon` | `Image` ("image") | Image element for icons or artwork |
| `PopupSeparator` | `Separator` ("separator") | Horizontal divider line (Image, thin) |
To add variants, duplicate a prefab, style it differently, and register it with a variant type. Use `PopupElementType.Header.Variant("gold")` in code, and set the type to "header_gold" in the PopupSettings Inspector.
### Settings
@@ -25,13 +27,32 @@ Reference prefabs for the popup system. Copy these into your project as a starti
| Script | Description |
|---|---|
| `PopupSystemExample` | Basic setup with auto-scanned triggers, GetTrigger by name, and GetTriggers by category |
| `DynamicTriggersExample` | Setting up triggers on dynamically instantiated UI using InitializeTriggersInChildren |
| `CodeOnlyPopupExample` | Showing popups from code without PopupTrigger (anchored, fixed position, follow mouse) |
| `PopupSystemExample` | Basic setup with auto-scanned triggers, `GetTriggerHandler` by name, and `GetTriggerHandlers` by category |
| `DynamicTriggersExample` | Setting up triggers on dynamically instantiated UI using `InitializeTriggersInChildren` with (trigger, view) callback |
| `CodeOnlyPopupExample` | Showing popups from code (anchored, fixed position, follow mouse), `PopupElementType` variants, and generic `Add()` for custom types |
### Architecture Overview
```
PopupTrigger (MonoBehaviour) -- reference holder, forwards pointer events
|
PopupTriggerView (C# class) -- behavior: calls IPopupSystem.Show/Hide
|
IPopupSystem / PopupSystem -- manages categories, delays, priority, triggers
|
PopupView (C# class) -- behavior: generic element cache, positioning
|
PopupReference (MonoBehaviour) -- reference holder: content, canvasGroup, background
|
PopupSettings (ScriptableObject) -- configuration + element prefab registry (PopupElementType -> prefab)
|
PopupElementType (struct) -- type-safe element identifier (Header, Text, LabelValueText, Image, Separator + custom)
```
## How to use
1. Import the samples via the Unity Package Manager (select the package, expand Samples, click Import)
2. Copy the prefabs into your project's Prefabs folder
3. Create a PopupSettings asset or use the provided one
4. Reference the example scripts for integration patterns
4. Add Element Prefab entries to PopupSettings using the dropdown (Header, Text, LabelValueText, Image, Separator) mapped to the copied prefabs
5. Reference the example scripts for integration patterns