33 Debug.LogWarning($
"[Singleton<{typeof(T)}>] Instance will not be returned because the application is quitting.");
38 if (_instance !=
null)
43 var instances = FindObjectsOfType<T>();
44 var count = instances.Length;
47 Debug.Log($
"[Singleton<{typeof(T)}>] An instance is needed in the scene and no existing instances were found, so a new instance will be created.");
48 return _instance =
new GameObject($
"(Singleton){typeof(T)}").AddComponent<T>();
52 Debug.LogWarning($
"[Singleton<{typeof(T)}>] There should never be more than one Singleton of type {typeof(T)} in the scene, but {count} were found. The first instance found will be used, and all others will be destroyed.");
53 for (var i = 1; i < instances.Length; i++)
55 Destroy(instances[i]);
59 return _instance = instances[0];