[Misc] Singleton pattern improvements, get rid of warnings and errors
This commit is contained in:
@@ -10,6 +10,7 @@ using UnityEngine.SceneManagement;
|
||||
public class SceneManagerService : MonoBehaviour
|
||||
{
|
||||
private static SceneManagerService _instance;
|
||||
private static bool _isQuitting = false;
|
||||
/// <summary>
|
||||
/// Singleton instance of the SceneManagerService.
|
||||
/// </summary>
|
||||
@@ -17,14 +18,14 @@ public class SceneManagerService : MonoBehaviour
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
if (_instance == null && Application.isPlaying && !_isQuitting)
|
||||
{
|
||||
_instance = FindAnyObjectByType<SceneManagerService>();
|
||||
if (_instance == null)
|
||||
{
|
||||
var go = new GameObject("SceneManagerService");
|
||||
_instance = go.AddComponent<SceneManagerService>();
|
||||
DontDestroyOnLoad(go);
|
||||
// DontDestroyOnLoad(go);
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
@@ -45,7 +46,12 @@ public class SceneManagerService : MonoBehaviour
|
||||
void Awake()
|
||||
{
|
||||
_instance = this;
|
||||
DontDestroyOnLoad(gameObject);
|
||||
// DontDestroyOnLoad(gameObject);
|
||||
}
|
||||
|
||||
void OnApplicationQuit()
|
||||
{
|
||||
_isQuitting = true;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user