[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

@@ -8,18 +8,20 @@ using UnityEngine.InputSystem;
public class InputManager : MonoBehaviour
{
private static InputManager _instance;
private static bool _isQuitting = false;
public static InputManager Instance
{
get
{
if (_instance == null)
if (_instance == null && Application.isPlaying && !_isQuitting)
{
_instance = FindAnyObjectByType<InputManager>();
if (_instance == null)
{
var go = new GameObject("InputManager");
_instance = go.AddComponent<InputManager>();
DontDestroyOnLoad(go);
// DontDestroyOnLoad(go);
}
}
return _instance;
@@ -36,7 +38,7 @@ public class InputManager : MonoBehaviour
void Awake()
{
_instance = this;
DontDestroyOnLoad(gameObject);
// DontDestroyOnLoad(gameObject);
playerInput = GetComponent<PlayerInput>();
if (playerInput == null)
{
@@ -70,6 +72,11 @@ public class InputManager : MonoBehaviour
}
}
void OnApplicationQuit()
{
_isQuitting = true;
}
/// <summary>
/// Sets the default ITouchInputConsumer to receive input events.
/// </summary>