22 lines
648 B
C#
22 lines
648 B
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
|
|
namespace BrewMonster.Assets.PerfectWorld.Scripts.Common
|
|
{
|
|
public abstract class Singleton<T> where T : class, new()
|
|
{
|
|
private static readonly Lazy<T> _instance = new Lazy<T>(() => new T());
|
|
public static T Instance => _instance.Value;
|
|
|
|
// Protected constructor prevents external instantiation
|
|
protected Singleton()
|
|
{
|
|
if (_instance.IsValueCreated)
|
|
throw new InvalidOperationException($"Singleton<{typeof(T).Name}> already created!");
|
|
}
|
|
}
|
|
}
|