Last active
September 26, 2022 12:01
-
-
Save brenocogu/8c06d7d710630bbbcd5a79bb932ae663 to your computer and use it in GitHub Desktop.
Generic singleton class initialization for Non MonoBehaviours
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
/// <summary> | |
/// Non Monobehaviour Singleton Instance | |
/// </summary> | |
/// <typeparam name="T">Class to be Singleton</typeparam> | |
public class Singleton<T> where T : new() | |
{ | |
private static Lazy<T> lazyInstance = | |
new Lazy<T>(() => new T()); | |
public static T Instance | |
{ | |
get | |
{ | |
return lazyInstance.Value; | |
} | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For MonoSingleton check this: https://gist.github.com/brenocogu/41079ee0d093c3ad65dd67859a548e9f