mirror of
https://github.com/NuclearPowered/Reactor.git
synced 2026-10-20 01:46:21 +00:00
35 lines
756 B
C#
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;
|
|
}
|
|
}
|
|
}
|
|
}
|