Skip to content

Instantly share code, notes, and snippets.

@brenocogu
Last active September 26, 2022 12:01
Show Gist options
  • Save brenocogu/8c06d7d710630bbbcd5a79bb932ae663 to your computer and use it in GitHub Desktop.
Save brenocogu/8c06d7d710630bbbcd5a79bb932ae663 to your computer and use it in GitHub Desktop.
Generic singleton class initialization for Non MonoBehaviours
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;
}
}
}
@brenocogu
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment