forked from nikita/muzika-gromche
31 lines
795 B
C#
31 lines
795 B
C#
using UnityEngine;
|
|
|
|
namespace MuzikaGromche;
|
|
|
|
// A global MonoBehaviour instance to run coroutines from non-MonoBehaviour or static context.
|
|
internal static class GlobalBehaviour
|
|
{
|
|
sealed class AdhocBehaviour : MonoBehaviour;
|
|
|
|
static AdhocBehaviour? instance = null;
|
|
|
|
public static MonoBehaviour Instance
|
|
{
|
|
get
|
|
{
|
|
if (instance == null)
|
|
{
|
|
var go = new GameObject("MuzikaGromche_GlobalBehaviour", [
|
|
typeof(AdhocBehaviour),
|
|
])
|
|
{
|
|
hideFlags = HideFlags.HideAndDontSave
|
|
};
|
|
Object.DontDestroyOnLoad(go);
|
|
instance = go.GetComponent<AdhocBehaviour>();
|
|
}
|
|
return instance;
|
|
}
|
|
}
|
|
}
|