Add docs, cleanup structure

This commit is contained in:
Michal Pikulski
2025-11-27 14:19:01 +01:00
parent a57fca63bf
commit 3723857a14
22 changed files with 675 additions and 344 deletions

View 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;
}
}
}
}