Compare commits
2 Commits
ecc2dd3dff
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
| 5189257935 | |||
|
|
e167af11fd |
@@ -8,7 +8,10 @@ namespace Darkmatter.Core.Contracts.Features.DrawingCatalog
|
|||||||
{
|
{
|
||||||
UniTask FetchAsync();
|
UniTask FetchAsync();
|
||||||
IReadOnlyList<string> AllTemplateIds { get; }
|
IReadOnlyList<string> AllTemplateIds { get; }
|
||||||
UniTask<Sprite> GetThumbnailAsync(string id);
|
// owned = true when the sprite (and its texture) were created for this call from a
|
||||||
|
// saved thumbnail on disk — the caller must Destroy() both when done. owned = false
|
||||||
|
// means the template's default thumbnail asset, which must NOT be destroyed.
|
||||||
|
UniTask<(Sprite sprite, bool owned)> GetThumbnailAsync(string id);
|
||||||
UniTask<IDrawingTemplate> LoadAsync(string id);
|
UniTask<IDrawingTemplate> LoadAsync(string id);
|
||||||
void ReleaseAll();
|
void ReleaseAll();
|
||||||
string GetNextTemplate(string currentId);
|
string GetNextTemplate(string currentId);
|
||||||
|
|||||||
@@ -6,7 +6,8 @@
|
|||||||
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
|
"GUID:c1c03c0e5b2f4412b9f2be1c20d6a9b1",
|
||||||
"GUID:b4c9f7fbf1e144933a1797dc208ece5f",
|
"GUID:b4c9f7fbf1e144933a1797dc208ece5f",
|
||||||
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
"GUID:b0214a6008ed146ff8f122a6a9c2f6cc",
|
||||||
"GUID:f51ebe6a0ceec4240a699833d6309b23"
|
"GUID:f51ebe6a0ceec4240a699833d6309b23",
|
||||||
|
"GUID:75469ad4d38634e559750d17036d5f7c"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
using UnityEngine.Rendering;
|
||||||
|
using VContainer.Unity;
|
||||||
|
|
||||||
|
namespace Darkmatter.Features.AppBoot.Flow
|
||||||
|
{
|
||||||
|
// A coloring page is static most of the time; re-rendering it at a locked 60 fps only
|
||||||
|
// turns battery into heat. Keep the player loop at 60 Hz (input still sampled every
|
||||||
|
// frame, so the first touch never lands on a skipped frame) but render every other
|
||||||
|
// frame while nothing has been touched for a few seconds.
|
||||||
|
public sealed class AdaptiveFrameRate : ITickable
|
||||||
|
{
|
||||||
|
private const float FullRateHoldSeconds = 3f;
|
||||||
|
private const int IdleRenderInterval = 2; // 60 Hz loop -> 30 fps rendering when idle
|
||||||
|
|
||||||
|
private float _lastInteractionTime;
|
||||||
|
|
||||||
|
public AdaptiveFrameRate()
|
||||||
|
{
|
||||||
|
// Treat boot as an interaction so the intro video starts at full rate.
|
||||||
|
_lastInteractionTime = Time.unscaledTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Tick()
|
||||||
|
{
|
||||||
|
if (IsPointerPressed())
|
||||||
|
_lastInteractionTime = Time.unscaledTime;
|
||||||
|
|
||||||
|
var desired = Time.unscaledTime - _lastInteractionTime < FullRateHoldSeconds
|
||||||
|
? 1
|
||||||
|
: IdleRenderInterval;
|
||||||
|
|
||||||
|
if (OnDemandRendering.renderFrameInterval != desired)
|
||||||
|
OnDemandRendering.renderFrameInterval = desired;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool IsPointerPressed()
|
||||||
|
{
|
||||||
|
var touchscreen = Touchscreen.current;
|
||||||
|
if (touchscreen != null && touchscreen.primaryTouch.press.isPressed)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
var mouse = Mouse.current;
|
||||||
|
return mouse != null && mouse.leftButton.isPressed;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,2 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: ee0bbb69e2ec44637a7f5fb6f18a2518
|
||||||
@@ -16,6 +16,7 @@ namespace Darkmatter.Features.AppBoot.Installers
|
|||||||
if (sceneRefs != null)
|
if (sceneRefs != null)
|
||||||
builder.RegisterComponent(sceneRefs);
|
builder.RegisterComponent(sceneRefs);
|
||||||
builder.RegisterEntryPoint<AppBootFlow>();
|
builder.RegisterEntryPoint<AppBootFlow>();
|
||||||
|
builder.RegisterEntryPoint<AdaptiveFrameRate>();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
using System;
|
using System;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
using UnityEngine.EventSystems;
|
||||||
using UnityEngine.InputSystem;
|
using UnityEngine.InputSystem;
|
||||||
|
|
||||||
namespace Darkmatter.Features.Coloring.Systems
|
namespace Darkmatter.Features.Coloring.Systems
|
||||||
@@ -8,6 +9,7 @@ namespace Darkmatter.Features.Coloring.Systems
|
|||||||
public sealed class ColoringPinchZoomController : MonoBehaviour
|
public sealed class ColoringPinchZoomController : MonoBehaviour
|
||||||
{
|
{
|
||||||
private const float MinimumPinchDistance = 8f;
|
private const float MinimumPinchDistance = 8f;
|
||||||
|
private const float PanZoomEpsilon = 0.0001f;
|
||||||
|
|
||||||
[SerializeField] private float minZoom = 1f;
|
[SerializeField] private float minZoom = 1f;
|
||||||
[SerializeField] private float maxZoom = 3f;
|
[SerializeField] private float maxZoom = 3f;
|
||||||
@@ -22,6 +24,7 @@ namespace Darkmatter.Features.Coloring.Systems
|
|||||||
private float _currentZoom = 1f;
|
private float _currentZoom = 1f;
|
||||||
private Vector3 _baseScale = Vector3.one;
|
private Vector3 _baseScale = Vector3.one;
|
||||||
private Vector2 _baseAnchoredPosition;
|
private Vector2 _baseAnchoredPosition;
|
||||||
|
private PanDragRelay _panRelay;
|
||||||
|
|
||||||
public void SetTarget(RectTransform target)
|
public void SetTarget(RectTransform target)
|
||||||
{
|
{
|
||||||
@@ -34,6 +37,26 @@ namespace Darkmatter.Features.Coloring.Systems
|
|||||||
_baseAnchoredPosition = target != null ? target.anchoredPosition : Vector2.zero;
|
_baseAnchoredPosition = target != null ? target.anchoredPosition : Vector2.zero;
|
||||||
_currentZoom = 1f;
|
_currentZoom = 1f;
|
||||||
enabled = _target != null && _parent != null;
|
enabled = _target != null && _parent != null;
|
||||||
|
|
||||||
|
_panRelay = null;
|
||||||
|
if (_target != null)
|
||||||
|
{
|
||||||
|
_panRelay = _target.gameObject.GetComponent<PanDragRelay>();
|
||||||
|
if (_panRelay == null)
|
||||||
|
_panRelay = _target.gameObject.AddComponent<PanDragRelay>();
|
||||||
|
_panRelay.Controller = this;
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdatePanRelayState();
|
||||||
|
}
|
||||||
|
|
||||||
|
// While not zoomed the relay is disabled so the event system never resolves it as a
|
||||||
|
// drag target — sloppy kid taps keep registering as clicks (paints) exactly as before.
|
||||||
|
// Zoomed in, drags become pans and are suppressed as clicks by uGUI.
|
||||||
|
private void UpdatePanRelayState()
|
||||||
|
{
|
||||||
|
if (_panRelay != null)
|
||||||
|
_panRelay.enabled = _currentZoom > 1f + PanZoomEpsilon;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetZoom()
|
public void ResetZoom()
|
||||||
@@ -46,6 +69,7 @@ namespace Darkmatter.Features.Coloring.Systems
|
|||||||
|
|
||||||
_currentZoom = 1f;
|
_currentZoom = 1f;
|
||||||
_isPinching = false;
|
_isPinching = false;
|
||||||
|
UpdatePanRelayState();
|
||||||
}
|
}
|
||||||
|
|
||||||
public IDisposable UseNonZoomedView()
|
public IDisposable UseNonZoomedView()
|
||||||
@@ -78,6 +102,7 @@ namespace Darkmatter.Features.Coloring.Systems
|
|||||||
|
|
||||||
_isPinching = false;
|
_isPinching = false;
|
||||||
TryApplyScrollZoom();
|
TryApplyScrollZoom();
|
||||||
|
TryApplyMousePan();
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryApplyPinchZoom()
|
private bool TryApplyPinchZoom()
|
||||||
@@ -111,8 +136,16 @@ namespace Darkmatter.Features.Coloring.Systems
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Anchor the content point that was under the previous midpoint to the current
|
||||||
|
// midpoint: distance change zooms, midpoint movement pans — one gesture does both.
|
||||||
|
Vector2 previousMidpoint = (firstTouch.PreviousPosition + secondTouch.PreviousPosition) * 0.5f;
|
||||||
|
if (!TryGetParentLocalPoint(previousMidpoint, out Vector2 previousMidpointLocal))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
float targetZoom = Mathf.Clamp(_currentZoom * (distance / previousDistance), minZoom, maxZoom);
|
float targetZoom = Mathf.Clamp(_currentZoom * (distance / previousDistance), minZoom, maxZoom);
|
||||||
ZoomTowards(midpointLocal, targetZoom);
|
ApplyZoomPan(previousMidpointLocal, midpointLocal, targetZoom);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,12 +185,123 @@ namespace Darkmatter.Features.Coloring.Systems
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Vector2 contentPoint = (parentLocalPoint - _target.anchoredPosition) / _currentZoom;
|
ApplyZoomPan(parentLocalPoint, parentLocalPoint, targetZoom);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void ApplyZoomPan(Vector2 previousLocalPoint, Vector2 currentLocalPoint, float targetZoom)
|
||||||
|
{
|
||||||
|
Vector2 contentPoint = (previousLocalPoint - _target.anchoredPosition) / _currentZoom;
|
||||||
_currentZoom = targetZoom;
|
_currentZoom = targetZoom;
|
||||||
_target.localScale = _baseScale * _currentZoom;
|
_target.localScale = _baseScale * _currentZoom;
|
||||||
_target.anchoredPosition = Mathf.Approximately(_currentZoom, minZoom)
|
_target.anchoredPosition = ClampPan(currentLocalPoint - contentPoint * _currentZoom);
|
||||||
? _baseAnchoredPosition
|
UpdatePanRelayState();
|
||||||
: parentLocalPoint - contentPoint * _currentZoom;
|
}
|
||||||
|
|
||||||
|
// Editor/desktop convenience: drag with the right or middle mouse button to pan while zoomed.
|
||||||
|
private void TryApplyMousePan()
|
||||||
|
{
|
||||||
|
Mouse mouse = Mouse.current;
|
||||||
|
if (mouse == null || (!mouse.rightButton.isPressed && !mouse.middleButton.isPressed))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_currentZoom <= 1f + PanZoomEpsilon)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 delta = mouse.delta.ReadValue();
|
||||||
|
if (delta == Vector2.zero)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 screenPosition = mouse.position.ReadValue();
|
||||||
|
if (!IsInputPointAllowed(screenPosition))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryGetParentLocalPoint(screenPosition, out Vector2 currentLocal) ||
|
||||||
|
!TryGetParentLocalPoint(screenPosition - delta, out Vector2 previousLocal))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_target.anchoredPosition = ClampPan(_target.anchoredPosition + (currentLocal - previousLocal));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Single-finger (or left-mouse) drag pan, fed by PanDragRelay on the paper root.
|
||||||
|
// Going through uGUI's drag pipeline matters: once the drag threshold is crossed the
|
||||||
|
// event system cancels the pending click, so a pan can never paint the region the
|
||||||
|
// finger ends on — a plain tap still paints.
|
||||||
|
private void OnPanDrag(PointerEventData eventData, Transform source)
|
||||||
|
{
|
||||||
|
if (_target == null || source != _target.transform)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_isPinching || HasMultiTouch())
|
||||||
|
{
|
||||||
|
return; // two-finger gesture owns the view
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_currentZoom <= 1f + PanZoomEpsilon)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!TryGetParentLocalPoint(eventData.position, out Vector2 currentLocal) ||
|
||||||
|
!TryGetParentLocalPoint(eventData.position - eventData.delta, out Vector2 previousLocal))
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
_target.anchoredPosition = ClampPan(_target.anchoredPosition + (currentLocal - previousLocal));
|
||||||
|
}
|
||||||
|
|
||||||
|
private static bool HasMultiTouch()
|
||||||
|
{
|
||||||
|
Touchscreen touchscreen = Touchscreen.current;
|
||||||
|
if (touchscreen == null)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
int count = 0;
|
||||||
|
foreach (var touchControl in touchscreen.touches)
|
||||||
|
{
|
||||||
|
if (touchControl.press.isPressed && ++count > 1)
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// The scaled paper must keep covering its zoom-1 footprint: panning can never expose
|
||||||
|
// background inside the area the drawing occupies when not zoomed.
|
||||||
|
private Vector2 ClampPan(Vector2 anchoredPosition)
|
||||||
|
{
|
||||||
|
if (_currentZoom <= 1f + PanZoomEpsilon)
|
||||||
|
{
|
||||||
|
return _baseAnchoredPosition;
|
||||||
|
}
|
||||||
|
|
||||||
|
Rect rect = _target.rect;
|
||||||
|
float growth = 1f - _currentZoom; // negative while zoomed in
|
||||||
|
|
||||||
|
float minX = _baseAnchoredPosition.x + rect.xMax * _baseScale.x * growth;
|
||||||
|
float maxX = _baseAnchoredPosition.x + rect.xMin * _baseScale.x * growth;
|
||||||
|
float minY = _baseAnchoredPosition.y + rect.yMax * _baseScale.y * growth;
|
||||||
|
float maxY = _baseAnchoredPosition.y + rect.yMin * _baseScale.y * growth;
|
||||||
|
|
||||||
|
return new Vector2(
|
||||||
|
Mathf.Clamp(anchoredPosition.x, minX, maxX),
|
||||||
|
Mathf.Clamp(anchoredPosition.y, minY, maxY));
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool TryGetParentLocalPoint(Vector2 screenPoint, out Vector2 localPoint)
|
private bool TryGetParentLocalPoint(Vector2 screenPoint, out Vector2 localPoint)
|
||||||
@@ -233,6 +377,7 @@ namespace Darkmatter.Features.Coloring.Systems
|
|||||||
_target.anchoredPosition = state.AnchoredPosition;
|
_target.anchoredPosition = state.AnchoredPosition;
|
||||||
_currentZoom = state.CurrentZoom;
|
_currentZoom = state.CurrentZoom;
|
||||||
_isPinching = false;
|
_isPinching = false;
|
||||||
|
UpdatePanRelayState();
|
||||||
}
|
}
|
||||||
|
|
||||||
private readonly struct ViewState
|
private readonly struct ViewState
|
||||||
@@ -285,5 +430,25 @@ namespace Darkmatter.Features.Coloring.Systems
|
|||||||
Delta = delta;
|
Delta = delta;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Runtime-attached to the paper root (SetTarget); regions are its children, so drags
|
||||||
|
// that start on a region bubble up here while taps stay clicks. Implementing the uGUI
|
||||||
|
// drag interfaces is what makes the event system suppress the region click on drag.
|
||||||
|
private sealed class PanDragRelay : MonoBehaviour, IBeginDragHandler, IDragHandler
|
||||||
|
{
|
||||||
|
internal ColoringPinchZoomController Controller;
|
||||||
|
|
||||||
|
public void OnBeginDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnDrag(PointerEventData eventData)
|
||||||
|
{
|
||||||
|
if (Controller != null)
|
||||||
|
{
|
||||||
|
Controller.OnPanDrag(eventData, transform);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ namespace Darkmatter.Features.DrawingCatalog
|
|||||||
private readonly CancellationTokenSource _cts = new();
|
private readonly CancellationTokenSource _cts = new();
|
||||||
private IDisposable _openSubscription;
|
private IDisposable _openSubscription;
|
||||||
|
|
||||||
|
// Sprites/textures decoded from saved thumbnails are created fresh on every refresh
|
||||||
|
// and are owned by this presenter — without destroying the previous batch each
|
||||||
|
// Colorbook visit leaks several MB per painted drawing until the OS kills the app.
|
||||||
|
private readonly List<Sprite> _ownedSprites = new();
|
||||||
|
private readonly List<Texture2D> _ownedTextures = new();
|
||||||
|
|
||||||
public DrawingCatalogPresenter(DrawingCatalogView view, IDrawingCatalogController controller,
|
public DrawingCatalogPresenter(DrawingCatalogView view, IDrawingCatalogController controller,
|
||||||
IDrawingTemplateCatalog catalog, IEventBus eventBus)
|
IDrawingTemplateCatalog catalog, IEventBus eventBus)
|
||||||
{
|
{
|
||||||
@@ -109,29 +115,73 @@ namespace Darkmatter.Features.DrawingCatalog
|
|||||||
|
|
||||||
private async UniTask RefreshAsync(CancellationToken ct)
|
private async UniTask RefreshAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
var ids = ToFixedRowGridOrder(_controller.VisibleIds);
|
var newSprites = new List<Sprite>();
|
||||||
var vms = new List<CatalogItemVM>(ids.Count);
|
var newTextures = new List<Texture2D>();
|
||||||
|
var applied = false;
|
||||||
|
|
||||||
_totalPages = (int)Math.Ceiling(ids.Count / (float)ItemPerPage);
|
try
|
||||||
_currentPage = 0;
|
|
||||||
|
|
||||||
foreach (var id in ids)
|
|
||||||
{
|
{
|
||||||
|
var ids = ToFixedRowGridOrder(_controller.VisibleIds);
|
||||||
|
var vms = new List<CatalogItemVM>(ids.Count);
|
||||||
|
|
||||||
|
_totalPages = (int)Math.Ceiling(ids.Count / (float)ItemPerPage);
|
||||||
|
_currentPage = 0;
|
||||||
|
|
||||||
|
foreach (var id in ids)
|
||||||
|
{
|
||||||
|
if (ct.IsCancellationRequested) return;
|
||||||
|
var (thumb, owned) = await _catalog.GetThumbnailAsync(id);
|
||||||
|
if (owned)
|
||||||
|
{
|
||||||
|
newSprites.Add(thumb);
|
||||||
|
newTextures.Add(thumb.texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
vms.Add(new CatalogItemVM(id, thumb));
|
||||||
|
}
|
||||||
|
|
||||||
if (ct.IsCancellationRequested) return;
|
if (ct.IsCancellationRequested) return;
|
||||||
var thumb = await _catalog.GetThumbnailAsync(id);
|
_view.ResetScrollPosition();
|
||||||
vms.Add(new CatalogItemVM(id, thumb));
|
_view.SetItems(vms);
|
||||||
|
_view.SetPagination(_currentPage, _totalPages);
|
||||||
|
|
||||||
|
// Buttons now reference the new batch; the previous one can go.
|
||||||
|
DestroyOwnedThumbnails();
|
||||||
|
_ownedSprites.AddRange(newSprites);
|
||||||
|
_ownedTextures.AddRange(newTextures);
|
||||||
|
applied = true;
|
||||||
|
|
||||||
|
// Unblock InitializeAsync: items are now on screen, so the loading screen can hide.
|
||||||
|
_controller.NotifyPopulated();
|
||||||
|
|
||||||
|
// Cue the first-run tutorial that the catalog grid is on screen and tappable.
|
||||||
|
_eventBus.Publish(new DrawingCatalogReadySignal());
|
||||||
}
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError($"[DrawingCatalog] Failed to refresh catalog: {e}");
|
||||||
|
}
|
||||||
|
finally
|
||||||
|
{
|
||||||
|
// Aborted refresh (cancelled or threw): don't strand the freshly decoded batch.
|
||||||
|
if (!applied)
|
||||||
|
{
|
||||||
|
foreach (var s in newSprites) UnityEngine.Object.Destroy(s);
|
||||||
|
foreach (var t in newTextures) UnityEngine.Object.Destroy(t);
|
||||||
|
}
|
||||||
|
|
||||||
if (ct.IsCancellationRequested) return;
|
// Idempotent — always unblock the flow; a stuck loading screen is worse than
|
||||||
_view.ResetScrollPosition();
|
// an empty catalog.
|
||||||
_view.SetItems(vms);
|
_controller.NotifyPopulated();
|
||||||
_view.SetPagination(_currentPage, _totalPages);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Unblock InitializeAsync: items are now on screen, so the loading screen can hide.
|
private void DestroyOwnedThumbnails()
|
||||||
_controller.NotifyPopulated();
|
{
|
||||||
|
foreach (var s in _ownedSprites) UnityEngine.Object.Destroy(s);
|
||||||
// Cue the first-run tutorial that the catalog grid is on screen and tappable.
|
foreach (var t in _ownedTextures) UnityEngine.Object.Destroy(t);
|
||||||
_eventBus.Publish(new DrawingCatalogReadySignal());
|
_ownedSprites.Clear();
|
||||||
|
_ownedTextures.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static List<string> ToFixedRowGridOrder(IReadOnlyList<string> ids)
|
private static List<string> ToFixedRowGridOrder(IReadOnlyList<string> ids)
|
||||||
@@ -160,6 +210,7 @@ namespace Darkmatter.Features.DrawingCatalog
|
|||||||
_openSubscription?.Dispose();
|
_openSubscription?.Dispose();
|
||||||
_cts.Cancel();
|
_cts.Cancel();
|
||||||
_cts.Dispose();
|
_cts.Dispose();
|
||||||
|
DestroyOwnedThumbnails();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -53,7 +53,7 @@ namespace Darkmatter.Features.DrawingTemplates.Systems
|
|||||||
_initialized = true;
|
_initialized = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async UniTask<Sprite> GetThumbnailAsync(string id)
|
public async UniTask<(Sprite sprite, bool owned)> GetThumbnailAsync(string id)
|
||||||
{
|
{
|
||||||
if (!_byId.TryGetValue(id, out var t))
|
if (!_byId.TryGetValue(id, out var t))
|
||||||
throw new KeyNotFoundException($"Template '{id}' not in catalog. Did InitializeAsync run?");
|
throw new KeyNotFoundException($"Template '{id}' not in catalog. Did InitializeAsync run?");
|
||||||
@@ -62,9 +62,9 @@ namespace Darkmatter.Features.DrawingTemplates.Systems
|
|||||||
if (savedTex != null)
|
if (savedTex != null)
|
||||||
{
|
{
|
||||||
var rect = new Rect(0, 0, savedTex.width, savedTex.height);
|
var rect = new Rect(0, 0, savedTex.width, savedTex.height);
|
||||||
return Sprite.Create(savedTex, rect, new Vector2(0.5f, 0.5f));
|
return (Sprite.Create(savedTex, rect, new Vector2(0.5f, 0.5f)), true);
|
||||||
}
|
}
|
||||||
return t.DefaultThumbnail;
|
return (t.DefaultThumbnail, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UniTask<IDrawingTemplate> LoadAsync(string id)
|
public UniTask<IDrawingTemplate> LoadAsync(string id)
|
||||||
|
|||||||
@@ -80,6 +80,27 @@ namespace Darkmatter.Features.GameplayFlow.Systems
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async UniTask StartAsync(CancellationToken cancellation)
|
public async UniTask StartAsync(CancellationToken cancellation)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
await StartCoreAsync(cancellation);
|
||||||
|
}
|
||||||
|
catch (OperationCanceledException)
|
||||||
|
{
|
||||||
|
// Scene torn down mid-init; nothing to recover.
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
// Any throw here (missing template id, failed Addressables load, region init)
|
||||||
|
// would otherwise skip _loadingScreen.Hide() and strand the kid on a frozen
|
||||||
|
// loader forever. Log it and route back to the Colorbook, whose flow hides the
|
||||||
|
// loading screen once its catalog is populated.
|
||||||
|
Debug.LogError($"[GameplayFlow] Failed to start gameplay, returning to Colorbook: {e}");
|
||||||
|
await RecoverToColorbookAsync();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private async UniTask StartCoreAsync(CancellationToken cancellation)
|
||||||
{
|
{
|
||||||
_scopeCts = CancellationTokenSource.CreateLinkedTokenSource(cancellation);
|
_scopeCts = CancellationTokenSource.CreateLinkedTokenSource(cancellation);
|
||||||
var ct = _scopeCts.Token;
|
var ct = _scopeCts.Token;
|
||||||
@@ -127,6 +148,22 @@ namespace Darkmatter.Features.GameplayFlow.Systems
|
|||||||
_loadingScreen.Hide();
|
_loadingScreen.Hide();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private async UniTask RecoverToColorbookAsync()
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
_shapeBuilder.Clear();
|
||||||
|
_coloring.Clear();
|
||||||
|
await _scenes.LoadSceneAsync(nameof(GameScene.Colorbook), progress: null, cancellationToken: default);
|
||||||
|
await _scenes.UnloadSceneAsync(nameof(GameScene.Gameplay), progress: null, cancellationToken: default);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogError($"[GameplayFlow] Recovery to Colorbook failed: {e}");
|
||||||
|
_loadingScreen.Hide();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public async UniTask BackAsync(CancellationToken ct)
|
public async UniTask BackAsync(CancellationToken ct)
|
||||||
{
|
{
|
||||||
await SaveCurrentAsync(CancellationToken.None);
|
await SaveCurrentAsync(CancellationToken.None);
|
||||||
|
|||||||
@@ -13,6 +13,7 @@ namespace Darkmatter.Features.Mainmenu
|
|||||||
private readonly IEventBus _eventBus;
|
private readonly IEventBus _eventBus;
|
||||||
private readonly MainMenuView _view;
|
private readonly MainMenuView _view;
|
||||||
private readonly ISfxPlayer _sfxPlayer;
|
private readonly ISfxPlayer _sfxPlayer;
|
||||||
|
private IDisposable _introSubscription;
|
||||||
|
|
||||||
|
|
||||||
public MainMenuPresenter(MainMenuView view, IEventBus eventBus, ISfxPlayer sfxPlayer)
|
public MainMenuPresenter(MainMenuView view, IEventBus eventBus, ISfxPlayer sfxPlayer)
|
||||||
@@ -26,7 +27,7 @@ namespace Darkmatter.Features.Mainmenu
|
|||||||
{
|
{
|
||||||
_view.OnPlayBtnPressedEvent += OnPlayBtnPressed;
|
_view.OnPlayBtnPressedEvent += OnPlayBtnPressed;
|
||||||
_view.OnPlayBtnClickedEvent += OnPlayBtnClicked;
|
_view.OnPlayBtnClickedEvent += OnPlayBtnClicked;
|
||||||
_eventBus.Subscribe<IntroCompletedSignal>(OnIntroComplete);
|
_introSubscription = _eventBus.Subscribe<IntroCompletedSignal>(OnIntroComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void OnIntroComplete(IntroCompletedSignal signal)
|
private void OnIntroComplete(IntroCompletedSignal signal)
|
||||||
@@ -48,6 +49,7 @@ namespace Darkmatter.Features.Mainmenu
|
|||||||
{
|
{
|
||||||
_view.OnPlayBtnPressedEvent -= OnPlayBtnPressed;
|
_view.OnPlayBtnPressedEvent -= OnPlayBtnPressed;
|
||||||
_view.OnPlayBtnClickedEvent -= OnPlayBtnClicked;
|
_view.OnPlayBtnClickedEvent -= OnPlayBtnClicked;
|
||||||
|
_introSubscription?.Dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -86,16 +86,27 @@ public sealed class ProgressionRepository
|
|||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(templateId) || png == null || png.Length == 0) return;
|
if (string.IsNullOrEmpty(templateId) || png == null || png.Length == 0) return;
|
||||||
|
|
||||||
Directory.CreateDirectory(ThumbnailDirectory());
|
// Never let thumbnail IO (disk full, permission churn) throw into the save path:
|
||||||
var path = ThumbnailPath(templateId);
|
// saves run before every Back/Next navigation, and an unhandled IOException there
|
||||||
var tmp = path + ".tmp";
|
// aborts the scene transition and traps the user in gameplay. Losing a thumbnail
|
||||||
|
// is fine — the colors themselves persist via PlayerPrefs.
|
||||||
await UniTask.RunOnThreadPool(() =>
|
try
|
||||||
{
|
{
|
||||||
File.WriteAllBytes(tmp, png);
|
Directory.CreateDirectory(ThumbnailDirectory());
|
||||||
if (File.Exists(path)) File.Delete(path);
|
var path = ThumbnailPath(templateId);
|
||||||
File.Move(tmp, path);
|
var tmp = path + ".tmp";
|
||||||
});
|
|
||||||
|
await UniTask.RunOnThreadPool(() =>
|
||||||
|
{
|
||||||
|
File.WriteAllBytes(tmp, png);
|
||||||
|
if (File.Exists(path)) File.Delete(path);
|
||||||
|
File.Move(tmp, path);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Debug.LogWarning($"[Progression] Failed writing thumbnail '{templateId}': {e.Message}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async UniTask<Texture2D> LoadThumbnailAsync(string templateId)
|
public async UniTask<Texture2D> LoadThumbnailAsync(string templateId)
|
||||||
|
|||||||
@@ -15,7 +15,23 @@ namespace Darkmatter.Libs.Observer
|
|||||||
if (_map.TryGetValue(typeof(T), out var handlerObj))
|
if (_map.TryGetValue(typeof(T), out var handlerObj))
|
||||||
{
|
{
|
||||||
var action = (Action<T>)handlerObj;
|
var action = (Action<T>)handlerObj;
|
||||||
action?.Invoke(evt);
|
if (action == null) return;
|
||||||
|
|
||||||
|
// Invoke handlers one by one: a multicast invoke would let one throwing
|
||||||
|
// subscriber silently starve every later subscriber and rethrow into the
|
||||||
|
// publisher (paint / scene-transition code), turning a local bug into a
|
||||||
|
// stuck flow.
|
||||||
|
foreach (var handler in action.GetInvocationList())
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
((Action<T>)handler).Invoke(evt);
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
UnityEngine.Debug.LogException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -350,7 +350,9 @@ namespace Darkmatter.Services.Audio
|
|||||||
if (!source.gameObject.activeInHierarchy) source.gameObject.SetActive(true);
|
if (!source.gameObject.activeInHierarchy) source.gameObject.SetActive(true);
|
||||||
|
|
||||||
source.Play();
|
source.Play();
|
||||||
|
#if UNITY_EDITOR || DEVELOPMENT_BUILD
|
||||||
Debug.Log($"[AudioService] Play clip='{(request.Clip != null ? request.Clip.name : "null")}' ch={request.Channel} vol={source.volume:F2} mixer={(source.outputAudioMixerGroup != null ? source.outputAudioMixerGroup.name : "none")} listener={(AudioListener.volume)} muted={AudioListener.pause} isPlaying={source.isPlaying}");
|
Debug.Log($"[AudioService] Play clip='{(request.Clip != null ? request.Clip.name : "null")}' ch={request.Channel} vol={source.volume:F2} mixer={(source.outputAudioMixerGroup != null ? source.outputAudioMixerGroup.name : "none")} listener={(AudioListener.volume)} muted={AudioListener.pause} isPlaying={source.isPlaying}");
|
||||||
|
#endif
|
||||||
if (IsChannelPaused(request.Channel))
|
if (IsChannelPaused(request.Channel))
|
||||||
{
|
{
|
||||||
source.Pause();
|
source.Pause();
|
||||||
|
|||||||
@@ -72,14 +72,14 @@ namespace Darkmatter.Services.Capture
|
|||||||
// GetPixels/SetPixels cropping allocated a managed Color[] at 16 bytes/pixel (tens of MB)
|
// GetPixels/SetPixels cropping allocated a managed Color[] at 16 bytes/pixel (tens of MB)
|
||||||
// on every capture — autosave runs this after each paint, OOM-killing low-RAM devices.
|
// on every capture — autosave runs this after each paint, OOM-killing low-RAM devices.
|
||||||
var cropped = new Texture2D(cropW, cropH, TextureFormat.RGBA32, mipChain: false);
|
var cropped = new Texture2D(cropW, cropH, TextureFormat.RGBA32, mipChain: false);
|
||||||
cropped.ReadPixels(new Rect(crop.x, crop.y, cropW, cropH), 0, 0);
|
|
||||||
cropped.Apply();
|
|
||||||
RenderTexture.active = prevActive;
|
|
||||||
captureViewScope?.Dispose();
|
|
||||||
captureViewScope = null;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
cropped.ReadPixels(new Rect(crop.x, crop.y, cropW, cropH), 0, 0);
|
||||||
|
cropped.Apply();
|
||||||
|
RenderTexture.active = prevActive;
|
||||||
|
captureViewScope?.Dispose();
|
||||||
|
captureViewScope = null;
|
||||||
|
|
||||||
int targetW = Mathf.Max(1, Mathf.RoundToInt(cropW * scale));
|
int targetW = Mathf.Max(1, Mathf.RoundToInt(cropW * scale));
|
||||||
int targetH = Mathf.Max(1, Mathf.RoundToInt(cropH * scale));
|
int targetH = Mathf.Max(1, Mathf.RoundToInt(cropH * scale));
|
||||||
Texture2D output = cropped;
|
Texture2D output = cropped;
|
||||||
@@ -97,17 +97,29 @@ namespace Darkmatter.Services.Capture
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
RenderTexture.active = prevActive;
|
||||||
Object.Destroy(cropped);
|
Object.Destroy(cropped);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
paperCanvas.renderMode = prevMode;
|
// The awaits above give scene teardown (autosave racing an unload) a chance to
|
||||||
paperCanvas.worldCamera = prevWorldCam;
|
// destroy the canvas or camera; touching them then would throw from finally and
|
||||||
paperCanvas.planeDistance = prevPlaneDist;
|
// skip the rest of the restore.
|
||||||
cam.targetTexture = prevTarget;
|
if (paperCanvas != null)
|
||||||
cam.clearFlags = prevFlags;
|
{
|
||||||
cam.backgroundColor = prevBg;
|
paperCanvas.renderMode = prevMode;
|
||||||
|
paperCanvas.worldCamera = prevWorldCam;
|
||||||
|
paperCanvas.planeDistance = prevPlaneDist;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (cam != null)
|
||||||
|
{
|
||||||
|
cam.targetTexture = prevTarget;
|
||||||
|
cam.clearFlags = prevFlags;
|
||||||
|
cam.backgroundColor = prevBg;
|
||||||
|
}
|
||||||
|
|
||||||
RenderTexture.ReleaseTemporary(rt);
|
RenderTexture.ReleaseTemporary(rt);
|
||||||
if (disabledGraphics != null)
|
if (disabledGraphics != null)
|
||||||
foreach (var g in disabledGraphics)
|
foreach (var g in disabledGraphics)
|
||||||
|
|||||||
@@ -118,8 +118,17 @@ namespace Darkmatter.Services.Gallery
|
|||||||
GL.PopMatrix();
|
GL.PopMatrix();
|
||||||
|
|
||||||
var output = new Texture2D(bgW, bgH, TextureFormat.RGBA32, mipChain: false);
|
var output = new Texture2D(bgW, bgH, TextureFormat.RGBA32, mipChain: false);
|
||||||
output.ReadPixels(new Rect(0, 0, bgW, bgH), 0, 0);
|
try
|
||||||
output.Apply();
|
{
|
||||||
|
output.ReadPixels(new Rect(0, 0, bgW, bgH), 0, 0);
|
||||||
|
output.Apply();
|
||||||
|
}
|
||||||
|
catch
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(output);
|
||||||
|
throw;
|
||||||
|
}
|
||||||
|
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -23,7 +23,7 @@ MonoBehaviour:
|
|||||||
m_RequireOpaqueTexture: 0
|
m_RequireOpaqueTexture: 0
|
||||||
m_OpaqueDownsampling: 1
|
m_OpaqueDownsampling: 1
|
||||||
m_SupportsTerrainHoles: 1
|
m_SupportsTerrainHoles: 1
|
||||||
m_SupportsHDR: 1
|
m_SupportsHDR: 0
|
||||||
m_HDRColorBufferPrecision: 0
|
m_HDRColorBufferPrecision: 0
|
||||||
m_MSAA: 1
|
m_MSAA: 1
|
||||||
m_RenderScale: 1
|
m_RenderScale: 1
|
||||||
@@ -42,7 +42,7 @@ MonoBehaviour:
|
|||||||
m_SupportProbeVolumeScenarioBlending: 0
|
m_SupportProbeVolumeScenarioBlending: 0
|
||||||
m_ProbeVolumeSHBands: 1
|
m_ProbeVolumeSHBands: 1
|
||||||
m_MainLightRenderingMode: 1
|
m_MainLightRenderingMode: 1
|
||||||
m_MainLightShadowsSupported: 1
|
m_MainLightShadowsSupported: 0
|
||||||
m_MainLightShadowmapResolution: 2048
|
m_MainLightShadowmapResolution: 2048
|
||||||
m_AdditionalLightsRenderingMode: 1
|
m_AdditionalLightsRenderingMode: 1
|
||||||
m_AdditionalLightsPerObjectLimit: 4
|
m_AdditionalLightsPerObjectLimit: 4
|
||||||
|
|||||||
@@ -1 +1 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?><resources><string name="com.crashlytics.android.build_id" translatable="false">8fc48ed6-41de-4dcf-a980-9aa3316fad11</string></resources>
|
<?xml version="1.0" encoding="utf-8"?><resources><string name="com.crashlytics.android.build_id" translatable="false">b468c378-10c7-4fe5-a4e9-6ae4bf5078cd</string></resources>
|
||||||
|
|||||||
@@ -13,4 +13,4 @@ MonoBehaviour:
|
|||||||
m_Name: SmartlookSettings
|
m_Name: SmartlookSettings
|
||||||
m_EditorClassIdentifier:
|
m_EditorClassIdentifier:
|
||||||
ProjectKey: 3bcfb098c5c4f6f1f48d8bbef4c0c94d7c2f9bc9
|
ProjectKey: 3bcfb098c5c4f6f1f48d8bbef4c0c94d7c2f9bc9
|
||||||
FPS: 30
|
FPS: 2
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ PlayerSettings:
|
|||||||
defaultScreenOrientation: 4
|
defaultScreenOrientation: 4
|
||||||
targetDevice: 2
|
targetDevice: 2
|
||||||
useOnDemandResources: 0
|
useOnDemandResources: 0
|
||||||
accelerometerFrequency: 60
|
accelerometerFrequency: 0
|
||||||
companyName: Darkmatter Game Production
|
companyName: Darkmatter Game Production
|
||||||
productName: Kidsage Colorbook
|
productName: Kidsage Colorbook
|
||||||
defaultCursor: {fileID: 0}
|
defaultCursor: {fileID: 0}
|
||||||
@@ -148,7 +148,7 @@ PlayerSettings:
|
|||||||
loadStoreDebugModeEnabled: 0
|
loadStoreDebugModeEnabled: 0
|
||||||
visionOSBundleVersion: 1.0
|
visionOSBundleVersion: 1.0
|
||||||
tvOSBundleVersion: 1.0
|
tvOSBundleVersion: 1.0
|
||||||
bundleVersion: 2.0
|
bundleVersion: 2.1
|
||||||
preloadedAssets:
|
preloadedAssets:
|
||||||
- {fileID: 11400000, guid: cc969dbecb228fa49b16da9273753a8f, type: 2}
|
- {fileID: 11400000, guid: cc969dbecb228fa49b16da9273753a8f, type: 2}
|
||||||
- {fileID: -944628639613478452, guid: 2bcd2660ca9b64942af0de543d8d7100, type: 3}
|
- {fileID: -944628639613478452, guid: 2bcd2660ca9b64942af0de543d8d7100, type: 3}
|
||||||
@@ -180,7 +180,7 @@ PlayerSettings:
|
|||||||
iPhone: 1
|
iPhone: 1
|
||||||
tvOS: 0
|
tvOS: 0
|
||||||
overrideDefaultApplicationIdentifier: 1
|
overrideDefaultApplicationIdentifier: 1
|
||||||
AndroidBundleVersionCode: 9
|
AndroidBundleVersionCode: 11
|
||||||
AndroidMinSdkVersion: 26
|
AndroidMinSdkVersion: 26
|
||||||
AndroidTargetSdkVersion: 0
|
AndroidTargetSdkVersion: 0
|
||||||
AndroidPreferredInstallLocation: 1
|
AndroidPreferredInstallLocation: 1
|
||||||
|
|||||||
Reference in New Issue
Block a user