Project Description
So, after all the projects that I have been starting and abandoning I finaly started creating my own library. This library is going to have the most commonly used features and the need to re-invent the wheel should be eliminated.
void Awake() => nUtils.CreateSingleton(ref instance, this, this.gameObject); public class nUtils { public static void CreateSingleton (ref T instance, T _this, GameObject obj) { if (instance == null) instance = _this; // If there is no instance, set it to current instance. if (!EqualityComparer .Default.Equals(instance, _this)) MonoBehaviour.Destroy(obj); // If this instance is a new instance, destroy object. MonoBehaviour.DontDestroyOnLoad(obj); // If this instance was not destroyed it should persist. }
The code above shows how I create a singleton with only one row.
Library/Source: https://github.com/n0tic/ByteVault-Library