Created
May 21, 2023 23:09
-
-
Save WeirdBeardDev/cd9a51ee77157f36171e0cc624786225 to your computer and use it in GitHub Desktop.
A Unity script template to create a Logger scriptable object.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* This work by Jason "Aj" Comfort (https://weirdbearddev.com) is licensed under | |
* CC BY-SA 4.0. To view a copy of this license, visit https://creativecommons.org/licenses/by-sa/4.0 | |
* Original idea based on [Software Architecture in Unity](https://www.youtube.com/watch?v=sh7f4K9Wbj8) video | |
*/ | |
using UnityEngine; | |
[CreateAssetMenu(fileName = "NewLogger", menuName = "ScriptableObjects/New Logger", order = 1)] | |
public class LoggerSO : ScriptableObject | |
{ | |
#region Members | |
private const string DName = nameof(LoggerSO); // Debug name | |
[Header("Logging")] | |
[SerializeField] private bool _showLogs = true; | |
[Header("Customization")] | |
[SerializeField] private string _prefixName = default; | |
[SerializeField] private Color _prefixColor = default; | |
private string _hexColor = default; | |
#endregion Members | |
#region Methods | |
public void Log(string className, string text) | |
{ | |
if (_showLogs) | |
Debug.Log($"<color={_hexColor}>{_prefixName}{(string.IsNullOrEmpty(_prefixName) ? "" : ": ")}{className}:</color> {text}"); | |
} | |
#endregion Methods | |
#region Helpers | |
private void OnValidate() => _hexColor = $"#{ColorUtility.ToHtmlStringRGBA(_prefixColor)}"; | |
#endregion Helpers | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment