Repository navigation
Singletons
Three Unity-side singletons, plus the engine-free ManeSingleton in ManeTools-dotNET.
| Type | Backing | When to use |
|---|---|---|
ManeSingleton<T> |
Plain C# | Domain code, no GameObject |
UnitySingleton<T> |
MonoBehaviour |
Needs a scene object / Update
|
ScriptableSingleton<T> |
ScriptableObject |
Data asset, or a hidden runtime instance |
MainThreadDispatcher |
UnitySingleton |
Queue work from background threads |
First access to Instance finds a scene component (including inactive) or creates a DontDestroyOnLoad object named [TypeName]. SetInstance / ClearInstance / IsReady() match the dotNET singleton.
using Mane.Unity;
using UnityEngine;
public class AudioHub : UnitySingleton<AudioHub>
{
public void Play(AudioClip clip) { /* ... */ }
}
AudioHub.Instance.Play(clip);A second instance in Awake throws if another is already registered. Destroyed Unity objects count as not ready.
Looks for a loaded asset first, otherwise creates a hidden runtime instance (HideAndDontSave). Prefer assigning an asset and calling SetInstance (or cloning it yourself) so play mode does not mutate the project asset.
MainThreadDispatcher.RunOnMainThread(() => uiText.text = result);Must exist before you call RunOnMainThread (place it in a scene, or touch Instance on the main thread first). If it is not ready, the call logs an error and returns. Actions run on the next Update.
openupm add com.manefunction.tools-unity