Add docs, cleanup structure
This commit is contained in:
@@ -2,27 +2,73 @@
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Minigames.StatueDressup.Data;
|
||||
using UnityEngine;
|
||||
using UnityEngine.ResourceManagement.AsyncOperations;
|
||||
using Utils;
|
||||
|
||||
namespace Minigames.StatueDressup.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Singleton manager for decoration data loading and caching.
|
||||
/// Loads all DecorationData assets once via Addressables and provides shared access.
|
||||
/// Singleton manager for statue dressup data loading and caching.
|
||||
/// Loads settings first, then decoration data via Addressables and provides shared access.
|
||||
/// Used by both minigame and town map to avoid duplicate loading.
|
||||
/// </summary>
|
||||
public class DecorationDataManager : ManagedBehaviour
|
||||
public class DecorationDataManager : ManagedBehaviour, IReadyNotifier
|
||||
{
|
||||
public static DecorationDataManager Instance { get; private set; }
|
||||
|
||||
// Static callback queue for when instance doesn't exist yet
|
||||
private static readonly List<System.Action> PendingCallbacks = new List<System.Action>();
|
||||
private AppleHills.Core.Settings.IStatueDressupSettings settings;
|
||||
private Dictionary<string, DecorationData> decorationDataDict;
|
||||
private AsyncOperationHandle<System.Collections.Generic.IList<DecorationData>> decorationDataHandle;
|
||||
private bool isLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// Check if data is loaded and ready
|
||||
/// Get the settings instance
|
||||
/// </summary>
|
||||
public AppleHills.Core.Settings.IStatueDressupSettings Settings => settings;
|
||||
|
||||
/// <summary>
|
||||
/// Check if data is loaded and ready (implements IReadyNotifier)
|
||||
/// </summary>
|
||||
public bool IsReady => isLoaded;
|
||||
|
||||
/// <summary>
|
||||
/// Event invoked when data is loaded and ready (implements IReadyNotifier)
|
||||
/// </summary>
|
||||
public event System.Action OnReady;
|
||||
|
||||
/// <summary>
|
||||
/// Static method to register callbacks that will execute when manager is ready.
|
||||
/// Can be called before instance exists - callbacks will be queued and executed when ready.
|
||||
/// Handles null instance gracefully by queuing callbacks until instance is created and ready.
|
||||
/// </summary>
|
||||
public static void WhenReady(System.Action callback)
|
||||
{
|
||||
if (callback == null) return;
|
||||
|
||||
// If instance exists and is ready, execute immediately
|
||||
if (Instance != null && Instance.IsReady)
|
||||
{
|
||||
callback.Invoke();
|
||||
return;
|
||||
}
|
||||
|
||||
// If instance exists but not ready, use instance method
|
||||
if (Instance != null)
|
||||
{
|
||||
(Instance as IReadyNotifier).WhenReady(callback);
|
||||
return;
|
||||
}
|
||||
|
||||
// Instance doesn't exist yet - queue callback
|
||||
PendingCallbacks.Add(callback);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Legacy property - use IsReady instead
|
||||
/// </summary>
|
||||
[System.Obsolete("Use IsReady instead")]
|
||||
public bool IsLoaded => isLoaded;
|
||||
|
||||
/// <summary>
|
||||
@@ -32,8 +78,6 @@ namespace Minigames.StatueDressup.Controllers
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Singleton pattern
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
@@ -44,12 +88,32 @@ namespace Minigames.StatueDressup.Controllers
|
||||
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
internal override async void OnManagedStart()
|
||||
|
||||
internal override void OnManagedStart()
|
||||
{
|
||||
base.OnManagedStart();
|
||||
StartCoroutine(LoadSettingsAndData());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Load settings first, then decoration data
|
||||
/// </summary>
|
||||
private System.Collections.IEnumerator LoadSettingsAndData()
|
||||
{
|
||||
Logging.Debug("[DecorationDataManager] Waiting for GameManager to be accessible...");
|
||||
|
||||
await LoadAllDecorationData();
|
||||
// Wait until GameManager is accessible and settings can be retrieved
|
||||
settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IStatueDressupSettings>();
|
||||
|
||||
Logging.Debug("[DecorationDataManager] Settings loaded successfully");
|
||||
|
||||
// Now load decoration data
|
||||
var loadTask = LoadAllDecorationData();
|
||||
yield return new WaitUntil(() => loadTask.IsCompleted);
|
||||
|
||||
if (loadTask.IsFaulted)
|
||||
{
|
||||
Logging.Error($"[DecorationDataManager] Failed to load decoration data: {loadTask.Exception}");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -63,7 +127,6 @@ namespace Minigames.StatueDressup.Controllers
|
||||
return;
|
||||
}
|
||||
|
||||
var settings = StatueDressupSettings.Instance?.Settings;
|
||||
string label = settings?.DecorationDataLabel;
|
||||
|
||||
if (string.IsNullOrEmpty(label))
|
||||
@@ -85,6 +148,20 @@ namespace Minigames.StatueDressup.Controllers
|
||||
isLoaded = true;
|
||||
|
||||
Logging.Debug($"[DecorationDataManager] Loaded {decorationDataDict.Count} DecorationData assets");
|
||||
|
||||
// Subscribe all pending callbacks to OnReady event before invoking
|
||||
if (PendingCallbacks.Count > 0)
|
||||
{
|
||||
Logging.Debug($"[DecorationDataManager] Subscribing {PendingCallbacks.Count} pending callbacks to OnReady");
|
||||
foreach (var callback in PendingCallbacks)
|
||||
{
|
||||
OnReady += callback;
|
||||
}
|
||||
PendingCallbacks.Clear();
|
||||
}
|
||||
|
||||
// Mark as ready and notify listeners (including pending callbacks)
|
||||
OnReady?.Invoke();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -122,10 +199,8 @@ namespace Minigames.StatueDressup.Controllers
|
||||
return decorationDataDict.TryGetValue(decorationId, out data);
|
||||
}
|
||||
|
||||
internal override void OnManagedDestroy()
|
||||
private void OnDestroy()
|
||||
{
|
||||
base.OnManagedDestroy();
|
||||
|
||||
// Release Addressables handle
|
||||
AddressablesUtility.ReleaseHandle(decorationDataHandle);
|
||||
|
||||
|
||||
@@ -35,9 +35,6 @@ namespace Minigames.StatueDressup.Controllers
|
||||
public int CurrentPage => currentPage;
|
||||
public int TotalPages => totalPages;
|
||||
|
||||
/// <summary>
|
||||
/// Early initialization - singleton setup
|
||||
/// </summary>
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
@@ -66,7 +63,19 @@ namespace Minigames.StatueDressup.Controllers
|
||||
{
|
||||
base.OnManagedStart();
|
||||
|
||||
var settings = StatueDressupSettings.Instance?.Settings;
|
||||
// Wait for data manager to be ready before initializing
|
||||
DecorationDataManager.WhenReady(() =>
|
||||
{
|
||||
InitializeMenu();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize menu once data manager is ready
|
||||
/// </summary>
|
||||
private void InitializeMenu()
|
||||
{
|
||||
var settings = DecorationDataManager.Instance?.Settings;
|
||||
|
||||
if (settings == null)
|
||||
{
|
||||
@@ -75,7 +84,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
}
|
||||
|
||||
var allDecorations = settings.AllDecorations;
|
||||
int itemsPerPage = settings.ItemsPerPage;
|
||||
int itemsPerPage = settings?.ItemsPerPage ?? StatueDressupConstants.DefaultMenuItemsPerPage;
|
||||
|
||||
Logging.Debug($"[DecorationMenuController] Initializing with {allDecorations?.Count ?? 0} decorations");
|
||||
|
||||
@@ -114,7 +123,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
/// </summary>
|
||||
private void PopulateCurrentPage()
|
||||
{
|
||||
var settings = StatueDressupSettings.Instance?.Settings;
|
||||
var settings = DecorationDataManager.Instance?.Settings;
|
||||
if (settings == null) return;
|
||||
|
||||
var allDecorations = settings.AllDecorations;
|
||||
@@ -196,7 +205,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
outlineRect,
|
||||
StatueDecorationController.Instance.StatueParent,
|
||||
StatueDecorationController.Instance,
|
||||
StatueDressupSettings.Instance.Settings,
|
||||
DecorationDataManager.Instance.Settings,
|
||||
OnDraggableFinished,
|
||||
ShowStatueOutline,
|
||||
HideStatueOutline
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
@@ -44,9 +44,6 @@ namespace Minigames.StatueDressup.Controllers
|
||||
public Transform StatueParent => statueParent;
|
||||
public RectTransform StatueArea => statueArea;
|
||||
|
||||
/// <summary>
|
||||
/// Early initialization - singleton setup
|
||||
/// </summary>
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
@@ -71,30 +68,12 @@ namespace Minigames.StatueDressup.Controllers
|
||||
|
||||
Logging.Debug("[StatueDecorationController] Initializing minigame");
|
||||
|
||||
// DecorationDataManager exists (initialized in OnManagedAwake) but data loads async in OnManagedStart
|
||||
// Wait for data to finish loading before initializing
|
||||
if (!DecorationDataManager.Instance.IsLoaded)
|
||||
// Wait for decoration data to be ready before initializing
|
||||
DecorationDataManager.WhenReady(() =>
|
||||
{
|
||||
Logging.Debug("[StatueDecorationController] Waiting for DecorationData to load...");
|
||||
StartCoroutine(WaitForDataAndInitialize());
|
||||
return;
|
||||
}
|
||||
|
||||
InitializeMinigame();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for data manager to finish loading data before initializing
|
||||
/// </summary>
|
||||
private System.Collections.IEnumerator WaitForDataAndInitialize()
|
||||
{
|
||||
while (!DecorationDataManager.Instance.IsLoaded)
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
Logging.Debug("[StatueDecorationController] DecorationData loaded, initializing minigame");
|
||||
InitializeMinigame();
|
||||
Logging.Debug("[StatueDecorationController] DecorationData ready, initializing minigame");
|
||||
InitializeMinigame();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -342,7 +321,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
/// </summary>
|
||||
private void SaveStatueState()
|
||||
{
|
||||
var settings = StatueDressupSettings.Instance?.Settings;
|
||||
var settings = DecorationDataManager.Instance?.Settings;
|
||||
|
||||
// Check if persistence is enabled
|
||||
if (settings == null || !settings.EnableStatePersistence)
|
||||
@@ -363,7 +342,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
/// </summary>
|
||||
private void LoadStatueState()
|
||||
{
|
||||
var settings = StatueDressupSettings.Instance?.Settings;
|
||||
var settings = DecorationDataManager.Instance?.Settings;
|
||||
|
||||
// Check if persistence is enabled
|
||||
if (settings == null || !settings.EnableStatePersistence)
|
||||
@@ -435,7 +414,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
var context = DecorationDragContext.CreateForPlaced(
|
||||
decorationData,
|
||||
this,
|
||||
StatueDressupSettings.Instance.Settings,
|
||||
DecorationDataManager.Instance.Settings,
|
||||
statueArea,
|
||||
canvasParent,
|
||||
showOutlineCallback,
|
||||
@@ -512,3 +491,4 @@ namespace Minigames.StatueDressup.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,59 +0,0 @@
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
|
||||
namespace Minigames.StatueDressup.Controllers
|
||||
{
|
||||
/// <summary>
|
||||
/// Singleton manager for StatueDressup settings access.
|
||||
/// Loads settings once and provides global access point.
|
||||
/// </summary>
|
||||
public class StatueDressupSettings : ManagedBehaviour
|
||||
{
|
||||
public static StatueDressupSettings Instance { get; private set; }
|
||||
|
||||
private AppleHills.Core.Settings.IStatueDressupSettings settings;
|
||||
|
||||
/// <summary>
|
||||
/// Get the settings instance
|
||||
/// </summary>
|
||||
public AppleHills.Core.Settings.IStatueDressupSettings Settings => settings;
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Singleton pattern
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Logging.Warning("[StatueDressupSettings] Duplicate instance detected. Destroying duplicate.");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
|
||||
// Load settings once
|
||||
settings = GameManager.GetSettingsObject<AppleHills.Core.Settings.IStatueDressupSettings>();
|
||||
|
||||
if (settings == null)
|
||||
{
|
||||
Logging.Error("[StatueDressupSettings] Failed to load StatueDressupSettings!");
|
||||
}
|
||||
else
|
||||
{
|
||||
Logging.Debug("[StatueDressupSettings] Settings loaded successfully");
|
||||
}
|
||||
}
|
||||
|
||||
internal override void OnManagedDestroy()
|
||||
{
|
||||
base.OnManagedDestroy();
|
||||
|
||||
if (Instance == this)
|
||||
{
|
||||
Instance = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: acf5624b19664ce5900f1a7c1328edbc
|
||||
timeCreated: 1764240158
|
||||
@@ -1,4 +1,4 @@
|
||||
using System.Collections;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
@@ -40,9 +40,9 @@ namespace Minigames.StatueDressup.Controllers
|
||||
private bool isLoadingPage;
|
||||
private PhotoEnlargeController enlargeController;
|
||||
|
||||
internal override void OnManagedStart()
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedStart();
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Singleton pattern
|
||||
if (Instance != null && Instance != this)
|
||||
@@ -53,11 +53,29 @@ namespace Minigames.StatueDressup.Controllers
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
}
|
||||
|
||||
internal override void OnManagedStart()
|
||||
{
|
||||
base.OnManagedStart();
|
||||
|
||||
var settings = StatueDressupSettings.Instance?.Settings;
|
||||
// Wait for data manager to be ready before initializing
|
||||
DecorationDataManager.WhenReady(() =>
|
||||
{
|
||||
InitializeGallery();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Initialize gallery once data manager is ready
|
||||
/// </summary>
|
||||
private void InitializeGallery()
|
||||
{
|
||||
var settings = DecorationDataManager.Instance?.Settings;
|
||||
|
||||
// Initialize enlarge controller
|
||||
enlargeController = new PhotoEnlargeController(backdrop, enlargedContainer, settings?.GalleryAnimationDuration ?? 0.3f);
|
||||
enlargeController = new PhotoEnlargeController(backdrop, enlargedContainer,
|
||||
settings?.GalleryAnimationDuration ?? StatueDressupConstants.DefaultAnimationDuration);
|
||||
|
||||
// Setup page navigation buttons
|
||||
if (previousPageButton != null)
|
||||
@@ -108,7 +126,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
ClearGrid();
|
||||
|
||||
// Get photos for current page
|
||||
int itemsPerPage = StatueDressupSettings.Instance?.Settings?.GalleryItemsPerPage ?? 20;
|
||||
int itemsPerPage = DecorationDataManager.Instance?.Settings?.GalleryItemsPerPage ?? StatueDressupConstants.DefaultGalleryItemsPerPage;
|
||||
List<string> pagePhotoIds = PhotoManager.GetPhotoIdsPage(CaptureType.StatueMinigame, currentPage, itemsPerPage);
|
||||
|
||||
Logging.Debug($"[StatuePhotoGalleryController] Displaying page {currentPage + 1}: {pagePhotoIds.Count} items");
|
||||
@@ -134,7 +152,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
/// </summary>
|
||||
private void UpdatePageButtons()
|
||||
{
|
||||
int itemsPerPage = StatueDressupSettings.Instance?.Settings?.GalleryItemsPerPage ?? 20;
|
||||
int itemsPerPage = DecorationDataManager.Instance?.Settings?.GalleryItemsPerPage ?? StatueDressupConstants.DefaultGalleryItemsPerPage;
|
||||
int totalPages = Mathf.CeilToInt((float)allPhotoIds.Count / itemsPerPage);
|
||||
|
||||
// Enable/disable previous button
|
||||
@@ -168,7 +186,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
/// </summary>
|
||||
private void OnNextPageClicked()
|
||||
{
|
||||
int itemsPerPage = StatueDressupSettings.Instance?.Settings?.GalleryItemsPerPage ?? 20;
|
||||
int itemsPerPage = DecorationDataManager.Instance?.Settings?.GalleryItemsPerPage ?? StatueDressupConstants.DefaultGalleryItemsPerPage;
|
||||
int totalPages = Mathf.CeilToInt((float)allPhotoIds.Count / itemsPerPage);
|
||||
|
||||
if (currentPage < totalPages - 1)
|
||||
@@ -224,7 +242,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
}
|
||||
|
||||
// Create thumbnail
|
||||
int thumbSize = StatueDressupSettings.Instance?.Settings?.GalleryThumbnailSize ?? 256;
|
||||
int thumbSize = DecorationDataManager.Instance?.Settings?.GalleryThumbnailSize ?? StatueDressupConstants.DefaultThumbnailSize;
|
||||
Texture2D thumbnail = PhotoManager.CreateThumbnail(fullPhoto, thumbSize);
|
||||
|
||||
// Destroy full photo immediately (we only need thumbnail)
|
||||
@@ -250,7 +268,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
thumbnailCacheOrder.Enqueue(photoId);
|
||||
|
||||
// Evict oldest if over limit
|
||||
int maxCached = StatueDressupSettings.Instance?.Settings?.GalleryMaxCachedThumbnails ?? 50;
|
||||
int maxCached = DecorationDataManager.Instance?.Settings?.GalleryMaxCachedThumbnails ?? StatueDressupConstants.DefaultMaxCachedThumbnails;
|
||||
while (thumbnailCache.Count > maxCached && thumbnailCacheOrder.Count > 0)
|
||||
{
|
||||
string oldestId = thumbnailCacheOrder.Dequeue();
|
||||
@@ -284,7 +302,7 @@ namespace Minigames.StatueDressup.Controllers
|
||||
|
||||
Logging.Debug($"[StatuePhotoGalleryController] Enlarging photo: {photoId}");
|
||||
|
||||
float enlargedScale = StatueDressupSettings.Instance?.Settings?.GalleryEnlargedScale ?? 2.5f;
|
||||
float enlargedScale = DecorationDataManager.Instance?.Settings?.GalleryEnlargedScale ?? StatueDressupConstants.DefaultEnlargedScale;
|
||||
|
||||
// Check cache first
|
||||
if (fullPhotoCache.TryGetValue(photoId, out Texture2D fullPhoto))
|
||||
@@ -404,3 +422,4 @@ namespace Minigames.StatueDressup.Controllers
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,39 @@
|
||||
using UnityEngine;
|
||||
|
||||
namespace Minigames.StatueDressup.Data
|
||||
{
|
||||
/// <summary>
|
||||
/// Event data passed with decoration events for VFX/SFX responses
|
||||
/// </summary>
|
||||
public class DecorationEventData
|
||||
{
|
||||
/// <summary>
|
||||
/// The decoration data (sprite, id, etc.)
|
||||
/// </summary>
|
||||
public DecorationData DecorationData { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The GameObject instance of the decoration (if applicable)
|
||||
/// </summary>
|
||||
public GameObject Instance { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Position where the event occurred (world space)
|
||||
/// </summary>
|
||||
public Vector3 Position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this decoration was dragged from the menu or from the statue
|
||||
/// </summary>
|
||||
public bool FromStatue { get; set; }
|
||||
|
||||
public DecorationEventData(DecorationData data, GameObject instance, Vector3 position, bool fromStatue = false)
|
||||
{
|
||||
DecorationData = data;
|
||||
Instance = instance;
|
||||
Position = position;
|
||||
FromStatue = fromStatue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5d9b3e7728c0420c8290986c31d5b738
|
||||
timeCreated: 1764248890
|
||||
@@ -39,29 +39,15 @@ namespace Minigames.StatueDressup.Display
|
||||
return;
|
||||
}
|
||||
|
||||
// DecorationDataManager exists (initialized in OnManagedAwake) but data loads async
|
||||
// Wait for data to finish loading before displaying decorations
|
||||
StartCoroutine(WaitForDataAndDisplay());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Wait for DecorationDataManager to finish loading data before displaying decorations
|
||||
/// </summary>
|
||||
private System.Collections.IEnumerator WaitForDataAndDisplay()
|
||||
{
|
||||
// Wait for data to load (manager is guaranteed to exist)
|
||||
while (!DecorationDataManager.Instance.IsLoaded)
|
||||
// Wait for decoration data manager to be ready (static method handles null instance)
|
||||
DecorationDataManager.WhenReady(() =>
|
||||
{
|
||||
yield return null;
|
||||
}
|
||||
|
||||
if (showDebugInfo)
|
||||
{
|
||||
Logging.Debug("[StatueDecorationLoader] DecorationData loaded, displaying decorations");
|
||||
}
|
||||
|
||||
// Load and display decorations
|
||||
LoadAndDisplayDecorations();
|
||||
if (showDebugInfo)
|
||||
{
|
||||
Logging.Debug("[StatueDecorationLoader] DecorationData ready, displaying decorations");
|
||||
}
|
||||
LoadAndDisplayDecorations();
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -70,7 +56,7 @@ namespace Minigames.StatueDressup.Display
|
||||
public void LoadAndDisplayDecorations()
|
||||
{
|
||||
// Check if DecorationData is loaded via manager
|
||||
if (DecorationDataManager.Instance == null || !DecorationDataManager.Instance.IsLoaded)
|
||||
if (DecorationDataManager.Instance == null || !DecorationDataManager.Instance.IsReady)
|
||||
{
|
||||
Logging.Warning("[StatueDecorationLoader] DecorationDataManager not ready. Cannot display decorations.");
|
||||
return;
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using Core;
|
||||
using Minigames.StatueDressup.Controllers;
|
||||
using Minigames.StatueDressup.Data;
|
||||
using Minigames.StatueDressup.Events;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -155,6 +156,10 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
{
|
||||
isDragging = true;
|
||||
|
||||
// Broadcast started dragging event (from grid)
|
||||
var eventDataObj = new DecorationEventData(decorationData, gameObject, transform.position, fromStatue: false);
|
||||
DecorationEventsManager.BroadcastDecorationStartedDragging(eventDataObj);
|
||||
|
||||
// Calculate offset from cursor to object center
|
||||
RectTransformUtility.ScreenPointToLocalPointInRectangle(
|
||||
canvas.transform as RectTransform,
|
||||
@@ -193,6 +198,10 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
|
||||
Logging.Debug($"[DecorationDraggableInstance] Drag ended: {decorationData?.DecorationName}");
|
||||
|
||||
// Broadcast finished dragging event
|
||||
var eventDataObj = new DecorationEventData(decorationData, gameObject, transform.position, fromStatue: isPlacedOnStatue);
|
||||
DecorationEventsManager.BroadcastDecorationFinishedDragging(eventDataObj);
|
||||
|
||||
// Check if overlapping with statue
|
||||
if (IsOverlappingStatue())
|
||||
{
|
||||
@@ -250,6 +259,10 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
|
||||
isPlacedOnStatue = true;
|
||||
|
||||
// Broadcast dropped on statue event
|
||||
var eventDataObj = new DecorationEventData(decorationData, gameObject, transform.position, fromStatue: false);
|
||||
DecorationEventsManager.BroadcastDecorationDroppedOnStatue(eventDataObj);
|
||||
|
||||
// Move to statue parent if specified
|
||||
if (statueParent != null && transform.parent != statueParent)
|
||||
{
|
||||
@@ -273,14 +286,22 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
{
|
||||
Logging.Debug($"[DecorationDraggableInstance] Pop-out and destroy: {decorationData?.DecorationName}");
|
||||
|
||||
// Broadcast dropped out event (animation starting)
|
||||
var eventDataObj = new DecorationEventData(decorationData, gameObject, transform.position, fromStatue: false);
|
||||
DecorationEventsManager.BroadcastDecorationDroppedOut(eventDataObj);
|
||||
|
||||
// Notify menu controller to hide outline immediately
|
||||
onFinishedCallback?.Invoke();
|
||||
|
||||
float duration = settings?.PlacementAnimationDuration ?? 0.3f;
|
||||
float duration = settings?.PlacementAnimationDuration ?? StatueDressupConstants.DefaultAnimationDuration;
|
||||
|
||||
// Play pop-out with fade animation
|
||||
TweenAnimationUtility.PopOutWithFade(transform, canvasGroup, duration, () =>
|
||||
{
|
||||
// Broadcast finished dropping out event (animation complete)
|
||||
var finalEventData = new DecorationEventData(decorationData, gameObject, transform.position, fromStatue: false);
|
||||
DecorationEventsManager.BroadcastDecorationFinishedDroppingOut(finalEventData);
|
||||
|
||||
Destroy(gameObject);
|
||||
});
|
||||
}
|
||||
@@ -301,6 +322,10 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
isPlacedOnStatue = false;
|
||||
isDragging = true;
|
||||
|
||||
// Broadcast started dragging event (from statue)
|
||||
var eventDataObj = new DecorationEventData(decorationData, gameObject, transform.position, fromStatue: true);
|
||||
DecorationEventsManager.BroadcastDecorationStartedDragging(eventDataObj);
|
||||
|
||||
// Show statue outline when picking up from statue
|
||||
if (onShowOutlineCallback != null)
|
||||
{
|
||||
@@ -345,6 +370,10 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
|
||||
Logging.Debug($"[DecorationDraggableInstance] Decoration tapped: {decorationData?.DecorationName}");
|
||||
|
||||
// Broadcast tap event
|
||||
var eventDataObj = new DecorationEventData(decorationData, gameObject, transform.position, fromStatue: true);
|
||||
DecorationEventsManager.BroadcastDecorationTappedOnStatue(eventDataObj);
|
||||
|
||||
// Future: Open detail view, play sound effect, show info popup, etc.
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using Core;
|
||||
using Minigames.StatueDressup.Controllers;
|
||||
using Minigames.StatueDressup.Data;
|
||||
using Minigames.StatueDressup.Events;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
@@ -17,7 +19,7 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
[SerializeField] private Image iconImage;
|
||||
[SerializeField] private DecorationData decorationData;
|
||||
|
||||
private Controllers.DecorationMenuController _menuController;
|
||||
private DecorationMenuController _menuController;
|
||||
private DecorationDraggableInstance _activeDraggableInstance;
|
||||
|
||||
// Properties
|
||||
@@ -26,7 +28,7 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
/// <summary>
|
||||
/// Initialize the icon with decoration data
|
||||
/// </summary>
|
||||
public void Initialize(DecorationData data, Controllers.DecorationMenuController controller)
|
||||
public void Initialize(DecorationData data, DecorationMenuController controller)
|
||||
{
|
||||
decorationData = data;
|
||||
_menuController = controller;
|
||||
@@ -46,6 +48,11 @@ namespace Minigames.StatueDressup.DragDrop
|
||||
if (_activeDraggableInstance == null)
|
||||
{
|
||||
Logging.Debug($"[DecorationGridIcon] Item tapped: {decorationData?.DecorationName}");
|
||||
|
||||
// Broadcast tapped in grid event
|
||||
var eventDataObj = new DecorationEventData(decorationData, gameObject, transform.position, fromStatue: false);
|
||||
DecorationEventsManager.BroadcastDecorationTappedInGrid(eventDataObj);
|
||||
|
||||
// Future: Open detail view, preview, etc.
|
||||
}
|
||||
}
|
||||
|
||||
3
Assets/Scripts/Minigames/StatueDressup/Events.meta
Normal file
3
Assets/Scripts/Minigames/StatueDressup/Events.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd293a0b6d2e4b28bd74bc8aff5fea01
|
||||
timeCreated: 1764248911
|
||||
@@ -0,0 +1,172 @@
|
||||
using Core;
|
||||
using Core.Lifecycle;
|
||||
using Minigames.StatueDressup.Data;
|
||||
|
||||
namespace Minigames.StatueDressup.Events
|
||||
{
|
||||
/// <summary>
|
||||
/// Manager for decoration VFX/SFX events.
|
||||
/// Listens to decoration state changes and triggers audio/visual feedback.
|
||||
/// </summary>
|
||||
public class DecorationEventsManager : ManagedBehaviour
|
||||
{
|
||||
public static DecorationEventsManager Instance { get; private set; }
|
||||
|
||||
// Static events for decoration state changes
|
||||
public static event System.Action<DecorationEventData> OnDecorationTappedInGrid;
|
||||
public static event System.Action<DecorationEventData> OnDecorationTappedOnStatue;
|
||||
public static event System.Action<DecorationEventData> OnDecorationStartedDragging;
|
||||
public static event System.Action<DecorationEventData> OnDecorationFinishedDragging;
|
||||
public static event System.Action<DecorationEventData> OnDecorationDroppedOnStatue;
|
||||
public static event System.Action<DecorationEventData> OnDecorationDroppedOut;
|
||||
public static event System.Action<DecorationEventData> OnDecorationFinishedDroppingOut;
|
||||
|
||||
internal override void OnManagedAwake()
|
||||
{
|
||||
base.OnManagedAwake();
|
||||
|
||||
// Singleton pattern
|
||||
if (Instance != null && Instance != this)
|
||||
{
|
||||
Logging.Warning("[DecorationEventsManager] Duplicate instance detected. Destroying duplicate.");
|
||||
Destroy(gameObject);
|
||||
return;
|
||||
}
|
||||
|
||||
Instance = this;
|
||||
|
||||
// Subscribe to all events
|
||||
OnDecorationTappedInGrid += HandleDecorationTappedInGrid;
|
||||
OnDecorationTappedOnStatue += HandleDecorationTappedOnStatue;
|
||||
OnDecorationStartedDragging += HandleDecorationStartedDragging;
|
||||
OnDecorationFinishedDragging += HandleDecorationFinishedDragging;
|
||||
OnDecorationDroppedOnStatue += HandleDecorationDroppedOnStatue;
|
||||
OnDecorationDroppedOut += HandleDecorationDroppedOut;
|
||||
OnDecorationFinishedDroppingOut += HandleDecorationFinishedDroppingOut;
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
{
|
||||
// Unsubscribe from all events
|
||||
if (Instance == this)
|
||||
{
|
||||
OnDecorationTappedInGrid -= HandleDecorationTappedInGrid;
|
||||
OnDecorationTappedOnStatue -= HandleDecorationTappedOnStatue;
|
||||
OnDecorationStartedDragging -= HandleDecorationStartedDragging;
|
||||
OnDecorationFinishedDragging -= HandleDecorationFinishedDragging;
|
||||
OnDecorationDroppedOnStatue -= HandleDecorationDroppedOnStatue;
|
||||
OnDecorationDroppedOut -= HandleDecorationDroppedOut;
|
||||
OnDecorationFinishedDroppingOut -= HandleDecorationFinishedDroppingOut;
|
||||
|
||||
Instance = null;
|
||||
}
|
||||
}
|
||||
|
||||
#region Static Broadcasting Methods
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast that a decoration was tapped in the grid menu
|
||||
/// </summary>
|
||||
public static void BroadcastDecorationTappedInGrid(DecorationEventData eventData)
|
||||
{
|
||||
OnDecorationTappedInGrid?.Invoke(eventData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast that a decoration already on the statue was tapped
|
||||
/// </summary>
|
||||
public static void BroadcastDecorationTappedOnStatue(DecorationEventData eventData)
|
||||
{
|
||||
OnDecorationTappedOnStatue?.Invoke(eventData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast that a decoration started being dragged
|
||||
/// </summary>
|
||||
public static void BroadcastDecorationStartedDragging(DecorationEventData eventData)
|
||||
{
|
||||
OnDecorationStartedDragging?.Invoke(eventData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast that a decoration finished being dragged (released)
|
||||
/// </summary>
|
||||
public static void BroadcastDecorationFinishedDragging(DecorationEventData eventData)
|
||||
{
|
||||
OnDecorationFinishedDragging?.Invoke(eventData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast that a decoration was successfully dropped on the statue
|
||||
/// </summary>
|
||||
public static void BroadcastDecorationDroppedOnStatue(DecorationEventData eventData)
|
||||
{
|
||||
OnDecorationDroppedOnStatue?.Invoke(eventData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast that a decoration was dropped outside the statue (animation starts)
|
||||
/// </summary>
|
||||
public static void BroadcastDecorationDroppedOut(DecorationEventData eventData)
|
||||
{
|
||||
OnDecorationDroppedOut?.Invoke(eventData);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Broadcast that a decoration finished its drop-out animation
|
||||
/// </summary>
|
||||
public static void BroadcastDecorationFinishedDroppingOut(DecorationEventData eventData)
|
||||
{
|
||||
OnDecorationFinishedDroppingOut?.Invoke(eventData);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Event Handlers (Stubbed with Logs)
|
||||
|
||||
private void HandleDecorationTappedInGrid(DecorationEventData eventData)
|
||||
{
|
||||
Logging.Debug($"[DecorationEventsManager] Decoration tapped in grid: {eventData.DecorationData?.DecorationId}");
|
||||
// TODO: Play tap SFX/VFX
|
||||
}
|
||||
|
||||
private void HandleDecorationTappedOnStatue(DecorationEventData eventData)
|
||||
{
|
||||
Logging.Debug($"[DecorationEventsManager] Decoration tapped on statue: {eventData.DecorationData?.DecorationId}");
|
||||
// TODO: Play tap SFX/VFX (different from grid tap?)
|
||||
}
|
||||
|
||||
private void HandleDecorationStartedDragging(DecorationEventData eventData)
|
||||
{
|
||||
Logging.Debug($"[DecorationEventsManager] Decoration started dragging: {eventData.DecorationData?.DecorationId} (FromStatue: {eventData.FromStatue})");
|
||||
// TODO: Play drag start SFX, maybe show drag VFX
|
||||
}
|
||||
|
||||
private void HandleDecorationFinishedDragging(DecorationEventData eventData)
|
||||
{
|
||||
Logging.Debug($"[DecorationEventsManager] Decoration finished dragging: {eventData.DecorationData?.DecorationId}");
|
||||
// TODO: Play drag release SFX
|
||||
}
|
||||
|
||||
private void HandleDecorationDroppedOnStatue(DecorationEventData eventData)
|
||||
{
|
||||
Logging.Debug($"[DecorationEventsManager] Decoration dropped on statue: {eventData.DecorationData?.DecorationId}");
|
||||
// TODO: Play success SFX, maybe show placement VFX
|
||||
}
|
||||
|
||||
private void HandleDecorationDroppedOut(DecorationEventData eventData)
|
||||
{
|
||||
Logging.Debug($"[DecorationEventsManager] Decoration dropped out (animation starting): {eventData.DecorationData?.DecorationId}");
|
||||
// TODO: Play drop-out SFX (whoosh/disappear sound?)
|
||||
}
|
||||
|
||||
private void HandleDecorationFinishedDroppingOut(DecorationEventData eventData)
|
||||
{
|
||||
Logging.Debug($"[DecorationEventsManager] Decoration finished dropping out: {eventData.DecorationData?.DecorationId}");
|
||||
// TODO: Play finish SFX (poof sound?), maybe show VFX
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5c9796e0044a4fcd95b02a19925a6b2b
|
||||
timeCreated: 1764248911
|
||||
63
Assets/Scripts/Minigames/StatueDressup/IReadyNotifier.cs
Normal file
63
Assets/Scripts/Minigames/StatueDressup/IReadyNotifier.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
|
||||
namespace Minigames.StatueDressup
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface for managers that load asynchronously and notify when ready.
|
||||
/// Allows dependent components to safely access the manager via WhenReady callbacks.
|
||||
/// </summary>
|
||||
public interface IReadyNotifier
|
||||
{
|
||||
/// <summary>
|
||||
/// True when the manager has finished initialization and is ready to use
|
||||
/// </summary>
|
||||
bool IsReady { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Event invoked when the manager becomes ready
|
||||
/// </summary>
|
||||
event Action OnReady;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Extension methods for IReadyNotifier to provide common callback behavior
|
||||
/// </summary>
|
||||
public static class ReadyNotifierExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Execute callback when ready. If already ready, executes immediately.
|
||||
/// If not ready yet, subscribes to OnReady event and executes when fired.
|
||||
/// </summary>
|
||||
public static void WhenReady(this IReadyNotifier notifier, Action callback)
|
||||
{
|
||||
if (notifier == null)
|
||||
{
|
||||
Core.Logging.Warning("[ReadyNotifierExtensions] Notifier is null, cannot execute callback");
|
||||
return;
|
||||
}
|
||||
|
||||
if (callback == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (notifier.IsReady)
|
||||
{
|
||||
// Already ready - execute immediately
|
||||
callback.Invoke();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Not ready yet - subscribe to event and auto-unsubscribe after invocation
|
||||
Action handler = null;
|
||||
handler = () =>
|
||||
{
|
||||
callback.Invoke();
|
||||
notifier.OnReady -= handler; // Unsubscribe to prevent memory leaks
|
||||
};
|
||||
notifier.OnReady += handler;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: da5633d4a0f84ceeaca54bb2c542dca4
|
||||
timeCreated: 1764244569
|
||||
@@ -0,0 +1,24 @@
|
||||
namespace Minigames.StatueDressup
|
||||
{
|
||||
/// <summary>
|
||||
/// Default constants for StatueDressup minigame.
|
||||
/// These serve as fallbacks when settings fail to load.
|
||||
/// Prefer using settings configuration over these constants.
|
||||
/// </summary>
|
||||
public static class StatueDressupConstants
|
||||
{
|
||||
// Pagination
|
||||
public const int DefaultMenuItemsPerPage = 20;
|
||||
public const int DefaultGalleryItemsPerPage = 20;
|
||||
|
||||
// Animations
|
||||
public const float DefaultAnimationDuration = 0.3f;
|
||||
|
||||
// Gallery/Photos - Performance Critical
|
||||
// Note: These affect memory usage and should ideally come from settings
|
||||
public const int DefaultThumbnailSize = 256;
|
||||
public const int DefaultMaxCachedThumbnails = 50;
|
||||
public const float DefaultEnlargedScale = 2.5f;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 86c9225c5cc54b8b99b1964c393de5a3
|
||||
timeCreated: 1764242098
|
||||
Reference in New Issue
Block a user