[Misc] Singleton pattern improvements, get rid of warnings and errors

This commit is contained in:
Michal Pikulski
2025-09-08 08:45:13 +02:00
parent f161d0069b
commit 3b0988243e
7 changed files with 52 additions and 57 deletions

View File

@@ -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>