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 |
First access to Instance finds a scene component (including inactive) or creates a DontDestroyOnLoad object named [TypeName]. SetInstance / ClearInstance / IsReady() match the ManeSingleton.
using Mane.Unity;
using UnityEngine;
public class AudioHub : UnitySingleton<AudioHub>
{
public void Play(AudioClip clip) { /* ... */ }
}
AudioHub.Instance.Play(clip);A second instance destroys its GameObject in Awake when another is already registered, for example when the scene that holds the singleton is loaded again. If you override Awake, call base.Awake() first and return when Instance != this. 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.
openupm add com.manefunction.tools-unity