You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
CrowdControl/Assets/3rd/StompyRobot/SRDebugger/Scripts/Internal/InternalOptionsRegistry.cs

42 lines
1.2 KiB
C#

1 month ago
using System;
using System.Collections.Generic;
using SRF.Service;
namespace SRDebugger.Internal
{
/// <summary>
/// Workaround for the debug panel not being initialized on startup.
/// SROptions needs to register itself but not cause auto-initialization.
/// This class buffers requests to register contains until there is a handler in place to deal with them.
/// Once the handler is in place, all buffered requests are passed in and future requests invoke the handler directly.
/// </summary>
[Service(typeof(InternalOptionsRegistry))]
public sealed class InternalOptionsRegistry
{
private List<object> _registeredContainers = new List<object>();
private Action<object> _handler;
public void AddOptionContainer(object obj)
{
if (_handler != null)
{
_handler(obj);
return;
}
_registeredContainers.Add(obj);
}
public void SetHandler(Action<object> action)
{
_handler = action;
foreach (object o in _registeredContainers)
{
_handler(o);
}
_registeredContainers = null;
}
}
}