Created
October 11, 2018 19:11
-
-
Save j4rv/945b50531be067a967c073e22ca9ba47 to your computer and use it in GitHub Desktop.
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 UnityEngine; | |
public class LazyngletonBehaviour<T> : MonoBehaviour where T : LazyngletonBehaviour<T> { | |
private static T _instance; | |
public static T Instance { | |
get{ | |
if(_instance == null){ | |
GameObject newInstance = new GameObject(); | |
_instance = newInstance.AddComponent<T>(); | |
newInstance.name = _instance.GetType().Name; | |
_instance.OnFirstCall(); | |
} | |
return _instance; | |
} | |
} | |
protected virtual void OnFirstCall () {} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment