From 3791708a17d94af8712fa1992e6c6f875b3c2ed1 Mon Sep 17 00:00:00 2001 From: Savya Bikram Shah Date: Wed, 27 May 2026 10:36:39 +0545 Subject: [PATCH] Package and reeadme updates --- .DS_Store | Bin 10244 -> 10244 bytes Assets/Darkmatter/Scenes/GamePlay.unity | 256 ++++++++++++++++++ Assets/Settings.meta | 8 + Assets/Settings/Build Profiles.meta | 8 + Assets/Settings/Build Profiles/Android™.asset | 57 ++++ .../Build Profiles/Android™.asset.meta | 8 + Assets/Settings/Build Profiles/iOS.asset | 50 ++++ Assets/Settings/Build Profiles/iOS.asset.meta | 8 + Packages/manifest.json | 22 +- Packages/packages-lock.json | 7 + ProjectSettings/PackageManagerSettings.asset | 27 +- Readme.md | 155 +++++++++-- 12 files changed, 560 insertions(+), 46 deletions(-) create mode 100644 Assets/Settings.meta create mode 100644 Assets/Settings/Build Profiles.meta create mode 100644 Assets/Settings/Build Profiles/Android™.asset create mode 100644 Assets/Settings/Build Profiles/Android™.asset.meta create mode 100644 Assets/Settings/Build Profiles/iOS.asset create mode 100644 Assets/Settings/Build Profiles/iOS.asset.meta diff --git a/.DS_Store b/.DS_Store index 5860754ea2e3bd6a136f518c94898c48ce60c7e4..8eab6015966c223ded911ee9a749d1c98c890e8d 100644 GIT binary patch delta 179 zcmZn(XbG6$&nUeyU^hRb^kyD`gKWl}3_%R342cXW47osB4@jnX=Hw?Q<>V(ZFfa%( zFfcL#an64*0E#d$NKRG|7oGfA>=~ygLmoo`Ln%YaFGS+QgC4QfMGrPhu HDwzxb%X%|R delta 44 xcmZn(XbG6$&nUSuU^hRb CaptureAsync( - Camera artCamera, - Sprite paperBackground, - int width = 2048, - int height = 2048); + UniTask CaptureAsync(); } ``` +#### `IPaperRig` *(Core/Paper)* +Shared art rig. The single source of truth for everything that lives in the drawing world. +```csharp +public interface IPaperRig { + Camera ArtCamera { get; } // offscreen, targetTexture = Surface + RenderTexture Surface { get; } // 2048×2048 ARGB32 — the paper itself + Transform PaperRoot { get; } // parent of regions/pieces/paper bg + Vector2 DesignSize { get; } // world units, e.g. (20, 20) + Rect DesignRect { get; } // centered on origin +} +``` + +#### `IArtInputBridge` *(Core/Paper)* +Converts screen-space pointer coords to art-world coords inside the RT. +```csharp +public interface IArtInputBridge { + bool TryScreenToArtWorld(Vector2 screenPos, out Vector2 artWorldPos); +} +``` +Returns `false` when the pointer is outside the displayed RawImage rect (toddler tapped the HUD or backdrop). Every art-world raycast goes through this. + #### `IProgressionService` *(Core/Progression)* Tracks which templates the child has completed and what they last opened. ```csharp @@ -1412,6 +1437,77 @@ public sealed class ShapePieceFactory { --- +### 32.5b Feature — `Paper` + +The shared art rig — RT, offscreen camera, screen↔world bridge. Every other feature in the ColorBook scene resolves `IPaperRig` and `IArtInputBridge` from DI and never touches `Screen.*` or `Camera.*` directly. + +#### `PaperRig : MonoBehaviour, IPaperRig` *(Rig)* +Scene-bound component placed on a GameObject in `ColorBook.unity`. Owns the RT lifecycle. +```csharp +// inspector fields: +// Camera _artCamera (Orthographic, aspect=1, fixed ortho size) +// Transform _paperRoot (parent of regions/pieces) +// Vector2 _designSize = (20, 20) (world units; matches 2048×2048 at PPU=100) +// int _surfaceSize = 2048 (RT side length, square) + +public sealed class PaperRig : MonoBehaviour, IPaperRig { + public Camera ArtCamera => _artCamera; + public RenderTexture Surface => _surface; + public Transform PaperRoot => _paperRoot; + public Vector2 DesignSize => _designSize; + public Rect DesignRect => new(-_designSize / 2f, _designSize); +} +``` +- **Awake:** allocate `_surface = new RenderTexture(_surfaceSize, _surfaceSize, 0, ARGB32) { name = "PaperSurface" };` then `_surface.Create()` and `_artCamera.targetTexture = _surface; _artCamera.aspect = 1f; _artCamera.orthographicSize = _designSize.y / 2f;`. +- **OnDestroy:** `_surface.Release(); Object.Destroy(_surface);`. +- **No update logic** — the camera renders every frame automatically because `targetTexture` is set. +- **Important:** `_artCamera`'s `orthographicSize` and `aspect` are set once and never touched again. The RT contents are deterministic. + +#### `ArtInputBridge : MonoBehaviour, IArtInputBridge` *(Input)* +Lives on the same UI Canvas as the paper `RawImage`. +```csharp +// inspector fields: +// RawImage _paperImage (the on-screen paper) +// RectTransform _paperRect (== _paperImage.rectTransform) +// Camera _uiCamera (Canvas event camera) +// IPaperRig _rig (injected via VContainer + IInjectable, or resolved in Start) + +public bool TryScreenToArtWorld(Vector2 screenPos, out Vector2 artWorldPos) { + if (!RectTransformUtility.ScreenPointToLocalPointInRectangle( + _paperRect, screenPos, _uiCamera, out var local)) { + artWorldPos = default; return false; + } + var rect = _paperRect.rect; + var uv = new Vector2( + (local.x - rect.xMin) / rect.width, + (local.y - rect.yMin) / rect.height); + if (uv.x < 0 || uv.x > 1 || uv.y < 0 || uv.y > 1) { + artWorldPos = default; return false; + } + artWorldPos = _rig.ArtCamera.ViewportToWorldPoint(uv); + return true; +} +``` +- Returns `false` when the toddler tapped outside the RawImage (HUD button area, backdrop, off-screen). +- Used by every feature that does world-space picking — `Coloring`, `ShapeBuilder`, and any future feature like stickers. + +#### `PaperRigModule : MonoBehaviour, IServiceModule` *(Installers)* +Scene-scoped installer. Dragged onto `ColorBookLifetimeScope._installers[]`. +```csharp +// inspector fields: +// PaperRig _rig +// ArtInputBridge _bridge + +public void Register(IContainerBuilder builder) { + builder.RegisterInstance(_rig); + builder.RegisterInstance(_bridge); +} +``` +- Registers as `Instance` because both are MonoBehaviours already in the scene. +- Lifetime is implicitly tied to the scene (Unity destroys them on unload). + +--- + ### 32.6 Feature — `Coloring` #### `ColoringStateRepository` *(Repository)* @@ -1453,7 +1549,15 @@ public sealed class ColorRegionView : MonoBehaviour { ``` #### `ColoringInputBinder` *(Systems)* — `IStartable, IDisposable` -Subscribes to `IInputReader.PointerDown`, raycasts on the `Artwork` layer mask, calls `ColoringController.PaintRegion(view)` on hit. +Subscribes to `IInputReader.PointerDown`. On each tap: +1. `_bridge.TryScreenToArtWorld(screenPos, out var artPos)` — bail if outside the paper. +2. `Physics2D.OverlapPoint(artPos, _artworkMask)` against the `Artwork` layer. +3. If hit, `ColoringController.PaintRegion(hit.GetComponent())`. + +```csharp +// fields: IInputReader _input, IArtInputBridge _bridge, IColoringController _coloring, LayerMask _artworkMask +``` +Note: `_bridge` is the same instance the entire scene uses — no per-feature coordinate math. #### `PaintRegionCommand` *(Commands)* Source in section 23. Holds `view`, `fromColor`, `toColor`, `bus`. Symmetrical execute/undo. @@ -1503,14 +1607,16 @@ Wires controller `StateChanged` ↔ view enable/disable; view click events → c #### `CaptureController` *(Systems)* The orchestrator behind the "Capture" button. Stateless other than guarding against concurrent captures. ```csharp -// fields: ICaptureService _capture, IGalleryService _gallery, IEventBus _bus, ColorBookSceneRefs _refs +// fields: ICaptureService _capture, IGalleryService _gallery, IEventBus _bus public sealed class CaptureController { public bool IsCapturing { get; } - public UniTask CaptureCurrentAsync(string templateId, Sprite paperBg); + public UniTask CaptureCurrentAsync(string templateId); } // pub: ArtworkCapturedSignal (mid-flow), ArtworkSavedSignal (post-save) ``` +- **Flow:** `_capture.CaptureAsync()` → `_gallery.SaveAsync(bytes, templateId)` → publish signals. - **Concurrency:** sets `IsCapturing = true` on entry; UI binds button enabled to `!IsCapturing` to prevent double-tap. +- **No camera or sprite args** — capture reads `IPaperRig.Surface` directly inside the service. #### `CaptureButtonPresenter` *(UI)* Wires button click → `CaptureController.CaptureCurrentAsync`. Disables button while in progress. Shows toast on `ArtworkSavedSignal`. @@ -1641,8 +1747,11 @@ Implemented as `ScriptableObject` per feature so scopes can drag them in the ins | `ColoringController` | Feature | Region spawn + paint cmd | undo, state, factory, bus | | `ColorRegionView` | Feature | Region sprite MB | — | | `PaintRegionCommand` | Feature | Undoable paint | view, bus | +| `PaperRig` | Feature | RT + ArtCamera owner | — | +| `ArtInputBridge` | Feature | Screen→art-world picking | rig, raw image, ui cam | +| `PaperRigModule` | Feature | DI registration | rig, bridge | | `HistoryController` | Feature | Undo/redo facade | undo stack, bus | -| `CaptureController` | Feature | Capture+save orchestration | capture svc, gallery, bus, refs | +| `CaptureController` | Feature | Capture+save orchestration | capture svc, gallery, bus | | `ColorBookFlowController` | Feature | Scene FSM | bus, catalog, builder, coloring, capture, progression | | `GalleryPresenter` | Feature | Art book listing | gallery, share, view, bus | | `BoundedUndoStack` | Lib | Capped undo store | — | @@ -1650,7 +1759,7 @@ Implemented as `ScriptableObject` per feature so scopes can drag them in the ins | `Fsm` | Lib | Generic FSM | — | | `AddressableAssetProviderService` | Service | Addressables wrapper | — | | `FileGalleryService` | Service | Gallery file IO | paths, thumb gen, bus | -| `RenderTextureCaptureService` | Service | PNG render | — | +| `RenderTextureCaptureService` | Service | PNG render from rig.Surface | paper rig | | `JsonPersistenceService` | Service | Settings/progression IO | — | | `SceneService` | Service | Async scene loads | — | | `AudioService` | Service | SFX playback | assets |