Files
Reactor/Reactor/PluginSingleton.cs
T
2020-12-22 19:45:06 +01:00

35 lines
756 B
C#

using System;
using System.Linq;
using BepInEx.IL2CPP;
namespace Reactor
{
public class PluginSingleton<T> where T : BasePlugin
{
private static T _instance;
public static T Instance
{
get
{
if (_instance == null)
{
_instance = Preloader.Chainloader.Plugins.Values.Select(x => x.Instance).OfType<T>().Single();
}
return _instance;
}
set
{
if (_instance != null)
{
throw new Exception($"Instance for {typeof(T).FullName} is already set");
}
_instance = value;
}
}
}
}