Files
Click-PointRPG/Assets/Scripts/Utilities/DebugManager.cs

64 lines
1.7 KiB
C#

using UnityEngine;
/// <summary>
/// Centralized debug logging manager for consistent logging across all systems.
/// Provides a global debug toggle and formatted log output.
/// </summary>
public class DebugManager : MonoBehaviour
{
public static DebugManager Instance { get; private set; }
[SerializeField]
private bool enableGlobalDebugLogs = true;
void Awake()
{
if (Instance != null && Instance != this)
{
Debug.LogWarning("Multiple DebugManager instances detected. Destroying duplicate.", gameObject);
Destroy(gameObject);
return;
}
Instance = this;
}
void OnDestroy()
{
if (Instance == this) Instance = null;
}
/// <summary>
/// Log a message if debug logging is enabled
/// </summary>
public static void Log(string category, string message, Object context = null)
{
if (Instance == null || !Instance.enableGlobalDebugLogs) return;
Debug.Log($"[{category}] {message}", context);
}
/// <summary>
/// Log a warning message
/// </summary>
public static void LogWarning(string category, string message, Object context = null)
{
Debug.LogWarning($"[{category}] {message}", context);
}
/// <summary>
/// Log an error message
/// </summary>
public static void LogError(string category, string message, Object context = null)
{
Debug.LogError($"[{category}] {message}", context);
}
/// <summary>
/// Set global debug logging state
/// </summary>
public static void SetDebugEnabled(bool enabled)
{
if (Instance != null)
Instance.enableGlobalDebugLogs = enabled;
}
}