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

View File

@@ -16,7 +16,6 @@ namespace Input
private Vector2 lastHoldPosition;
private Coroutine pathfindingDragCoroutine;
private float pathfindingDragUpdateInterval = 0.1f; // Interval in seconds
private bool pendingTap = false; // Track if OnHoldEnd is following a tap (legacy, see below)
// --- Unity/Component References ---
private AIPath aiPath;
@@ -254,8 +253,5 @@ namespace Input
OnArrivedAtTarget?.Invoke();
}
}
// --- Legacy/Unused fields ---
// pendingTap: This field is not used in the current input flow. If you are not using tap/hold distinction logic elsewhere, consider removing it.
// If you want to remove it, please confirm and I will do so.
}
}