Iuvo Unity 0.5.1
This is library containing a variety of helper classes and extension methods for the Unity gane engine.
GitHub | Iuvo Unity Updates | Creator
Loading...
Searching...
No Matches
IuvoUnity.Debug.IuvoDebug Class Reference

If you ever cant see the debug logs, make sure to call IuvoDebug.Initialize() in your main scene and that the correct Validation Levels are set. More...

Classes

class  IuvoDebugRunner

Public Types

enum  ValidationLevel { Debug , Warning , Error }
enum  LogDestination { PersistentFile , EditorFile , CustomFile }

Static Public Member Functions

static void EnableValidationLevel (ValidationLevel level, bool enable)
static void Initialize ()
static void SetLogFilePath (string path)
static void DebugTransform (Transform toDebug, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugPosition (Vector3 position, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugRotation (Quaternion rotation, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugEulerAngles (Vector3 eulerAngles, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugScale (Vector3 scale, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugLossyScale (Vector3 lossyScale, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static bool RaycastDebug (Vector3 origin, Vector3 direction, out RaycastHit hit, float distance=Mathf.Infinity, int layerMask=Physics.DefaultRaycastLayers, Color? debugColor=null, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugLogIuvoVersion ([CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugIuvoGame (IuvoGame game, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugLog (string message, bool richTxtMsg=true, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugLogWarning (string message, bool richTxtMsg=true, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)
static void DebugLogError (string message, bool richTxtMsg=false, [CallerMemberName] string memberName="", [CallerFilePath] string filePath="", [CallerLineNumber] int lineNumber=0)

Static Public Attributes

static HashSet< ValidationLevelEnabledLevels
static HashSet< LogDestinationEnabledDestinations

Static Private Member Functions

static void EnqueueLog (string message)
static System.Collections.IEnumerator FlushPersistentLogQueueRoutine ()
static System.Collections.IEnumerator FlushEditorLogQueueRoutine ()
static System.Collections.IEnumerator FlushCustomLogQueueRoutine ()
static void FinalFlushOnQuitPersistentLog ()
static void FinalFlushOnQuitEditorLog ()
static void FinalFlushOnQuitCustomLog ()
static string FormatMessage (string level, string message, string memberName, string filePath, int lineNumber, out string richTextMessage, bool richTxtMsg)

Static Private Attributes

static string persistentLogFilePath = Path.Combine(Application.persistentDataPath, "IuvoDebugLog_Persistent.txt")
static string editorLogFilePath = Path.Combine(Application.dataPath, "IuvoDebugLog_Editor.txt")
static string customLogFilePath = ""
static readonly Queue< string > persistentLogQueue = new Queue<string>()
static readonly Queue< string > editorLogQueue = new Queue<string>()
static readonly Queue< string > customLogQueue = new Queue<string>()
static readonly object fileLock = new object()
static bool coroutineStarted = false

Detailed Description

If you ever cant see the debug logs, make sure to call IuvoDebug.Initialize() in your main scene and that the correct Validation Levels are set.

Member Enumeration Documentation

◆ LogDestination

Enumerator
PersistentFile 
EditorFile 
CustomFile 
59 {
60 PersistentFile,
61 EditorFile,
62 CustomFile
63 }

◆ ValidationLevel

Enumerator
Debug 
Warning 
Error 
19 {
20 Debug,
21 Warning,
22 Error
23 }

Member Function Documentation

◆ DebugEulerAngles()

void IuvoUnity.Debug.IuvoDebug.DebugEulerAngles ( Vector3 eulerAngles,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
308 {
309 if (!EnabledLevels.Contains(ValidationLevel.Debug)) return;
310 DebugLog($"Angles: {eulerAngles:F3}", false, memberName, filePath, lineNumber);
311 }

References DebugLog(), and EnabledLevels.

Referenced by DebugTransform().

◆ DebugIuvoGame()

void IuvoUnity.Debug.IuvoDebug.DebugIuvoGame ( IuvoGame game,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static

will be removed once class fully implements

350 {
351 if (!EnabledLevels.Contains(ValidationLevel.Debug)) return;
352 if (game == null)
353 {
354 DebugLogWarning("IuvoGame instance is null", false, memberName, filePath, lineNumber);
355 return;
356 }
357 DebugLog($"Game: {game.gameName}", false, memberName, filePath, lineNumber);
358 DebugLog($"Game Version: {game.gameVersion}", false, memberName, filePath, lineNumber);
359 DebugLog($"Developer: {game.developerName}", false, memberName, filePath, lineNumber);
360 DebugLog($"Publisher: {game.publisherName}", false, memberName, filePath, lineNumber);
361 DebugLog($"Screen Resolution: {game.screenWidth}x{game.screenHeight}", false, memberName, filePath, lineNumber);
362
363 {
364 if (game.systemsStateMachine != null)
365 {
366 if (game.systemsStateMachine.currentState != null)
367 {
368 DebugLog($"Systems State: {game.systemsStateMachine.currentState.stateName}", false, memberName, filePath, lineNumber);
369 }
370 else
371 {
372 DebugLogWarning("Systems StateMachine current state is null", false, memberName, filePath, lineNumber);
373 }
374 }
375 else
376 {
377 DebugLogWarning("Systems StateMachine is null", false, memberName, filePath, lineNumber);
378 }
379 }
380
381 // check for the game debug interface
382 IGameDebug gameDebug = game as IGameDebug;
383 if (gameDebug != null)
384 {
385 gameDebug.LogGameInfo();
386 gameDebug.LogGameState();
387 }
388 else
389 {
390 DebugLogWarning("IuvoGame does not implement IGameDebug interface", false, memberName, filePath, lineNumber);
391 }
392 }
ConditionalStateMachine systemsStateMachine
Definition IuvoGame.cs:33

References DebugLog(), DebugLogWarning(), EnabledLevels, IuvoUnity.Constants.IGameDebug.LogGameInfo(), IuvoUnity.Constants.IGameDebug.LogGameState(), and IuvoUnity.Constants.IuvoGame.systemsStateMachine.

Referenced by IuvoUnity.Debug.TestDebugButton.TestFunction().

◆ DebugLog()

void IuvoUnity.Debug.IuvoDebug.DebugLog ( string message,
bool richTxtMsg = true,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
398 {
399 if (!EnabledLevels.Contains(ValidationLevel.Debug)) return;
400 string richFormatted;
401 string formatted = FormatMessage("[DEBUG]", message, memberName, filePath, lineNumber, out richFormatted, richTxtMsg);
402 UnityEngine.Debug.Log(richFormatted);
403 EnqueueLog(formatted);
404 }

References EnabledLevels, EnqueueLog(), and FormatMessage().

Referenced by IuvoUnity.StateMachines.CSM.ConditionalStateMachine.ChangeState(), DebugEulerAngles(), DebugIuvoGame(), DebugLogIuvoVersion(), DebugLossyScale(), DebugPosition(), DebugRotation(), DebugScale(), IuvoUnity.Configurations.HealthConfiguration.ImplementDefaultScalingAlgorithm(), IuvoUnity.Configurations.LevelConfiguration.ImplementDefaultScalingAlgorithm(), IuvoUnity.Extensions.GameObjectExtensions.LogComponents< T >(), IuvoUnity.Extensions.GameObjectExtensions.LogComponentsInChildren< T >(), IuvoUnity.Constants.IuvoGame.LogGameInfo(), IuvoUnity.Constants.IuvoGame.LogGameState(), IuvoUnity.BaseClasses.HealthComponent.OnDestroy(), IuvoUnity.Configurations.HealthConfiguration.OnDisable(), IuvoUnity.Configurations.LevelConfiguration.OnDisable(), IuvoUnity.RPG.Stat.OnDisable(), IuvoUnity.RPG.Stat.OnEnable(), IuvoUnity.Inputs.BaseInputActionLegacy.Perform(), IuvoUnity.Inputs.InputActionBase.Perform(), IuvoUnity.Configurations.BaseConfig< T >.PrintInfo(), IuvoUnity.Configurations.HealthConfiguration.PrintInfo(), IuvoUnity.Configurations.LevelConfiguration.PrintInfo(), IuvoUnity.Configurations.TimerConfiguration.PrintInfo(), IuvoUnity.Configurations.LevelConfiguration.Serialize(), IuvoUnity.Configurations.HealthConfiguration.SetLevelScalingCurve(), IuvoUnity.Configurations.LevelConfiguration.SetLevelScalingCurve(), TimerTestUI.Start(), and IuvoUnity.Debug.TestDebugButton.TestFunction().

◆ DebugLogError()

void IuvoUnity.Debug.IuvoDebug.DebugLogError ( string message,
bool richTxtMsg = false,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
418 {
419 if (!EnabledLevels.Contains(ValidationLevel.Error)) return;
420 string richFormatted;
421 string formatted = FormatMessage("[ERROR]", message, memberName, filePath, lineNumber, out richFormatted, richTxtMsg);
422 UnityEngine.Debug.LogError(richFormatted);
423 EnqueueLog(formatted);
424 }

References EnabledLevels, EnqueueLog(), and FormatMessage().

Referenced by IuvoUnity.BaseClasses.LevelComponent.AddExperience(), IuvoUnity.BaseClasses.LevelComponent.AddLevels(), IuvoUnity.StateMachines.CSM.ConditionalStateMachine.Awake(), TimerTestUI.Awake(), IuvoUnity.Configurations.TimerConfiguration.Configure(), IuvoUnity.ProceduralGeneration.Room.CreateRoom(), IuvoUnity.ProceduralGeneration.ProceduralStripMesh.GenerateBetweenStrips(), IuvoUnity.Configurations.BaseConfig< T >.GetConfigSerializePath(), IuvoUnity.BaseClasses.LevelComponent.GetExperienceToNextLevel(), IuvoUnity.Configurations.HealthConfiguration.GetMaxHealthAtLevel(), IuvoUnity.ProceduralGeneration.Room.InitializeRoom(), IuvoUnity.BaseClasses.LevelComponent.LoseLevels(), IuvoUnity.BaseClasses.LevelComponent.OnDestroy(), IuvoUnity.Configurations.TimerConfiguration.Reconfigure(), IuvoUnity.ProceduralGeneration.Room.RemoveSharedWalls(), IuvoUnity.Extensions.GameObjectExtensions.ScaleNonStaticChildrenWithMesh(), IuvoUnity.Extensions.GameObjectExtensions.ScaleStaticChildrenWithMesh(), IuvoUnity.Configurations.LevelConfiguration.Serialize(), IuvoUnity.BaseClasses.LevelComponent.SerializeSelf(), IuvoUnity.Extensions.MeshRendererExtensions.SetCulling(), IuvoUnity.StateMachines.CSM.ConditionalStateMachine.SetForceDefaultState(), IuvoUnity.StateMachines.CSM.ConditionalStateMachine.SetForcePrevState(), IuvoUnity.Configurations.HealthConfiguration.SetLevelScalingCurve(), IuvoUnity.Configurations.LevelConfiguration.SetLevelScalingCurve(), IuvoUnity.BaseClasses.LevelComponent.Start(), IuvoUnity.ProceduralGeneration.Room.Start(), IuvoUnity.Debug.TestDebugButton.TestFunction(), IuvoUnity.BaseClasses.LevelComponent.TryGetLevelConfig(), IuvoUnity.BaseClasses.HealthComponent.UpdateMaxHealth(), and IuvoUnity.Extensions.MaterialExtensions.WithShader().

◆ DebugLogIuvoVersion()

void IuvoUnity.Debug.IuvoDebug.DebugLogIuvoVersion ( [CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
343 {
344 string version = IuvoCore.GetVersion();
345 DebugLog($"IuvoUnity Version: {version}", false, memberName, filePath, lineNumber);
346 }

References DebugLog(), and IuvoUnity.Core.IuvoCore.GetVersion().

Referenced by IuvoUnity.Debug.TestDebugButton.TestFunction().

◆ DebugLogWarning()

void IuvoUnity.Debug.IuvoDebug.DebugLogWarning ( string message,
bool richTxtMsg = true,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
408 {
409 if (!EnabledLevels.Contains(ValidationLevel.Warning)) return;
410 string richFormatted;
411 string formatted = FormatMessage("[WARNING]", message, memberName, filePath, lineNumber, out richFormatted, richTxtMsg);
412 UnityEngine.Debug.LogWarning(richFormatted);
413 EnqueueLog(formatted);
414 }

References EnabledLevels, EnqueueLog(), and FormatMessage().

Referenced by IuvoUnity.BaseClasses.LevelComponent.AddExperience(), IuvoUnity.BaseClasses.LevelComponent.AddLevels(), IuvoUnity.BaseClasses.LevelComponent.AddLevelUpPoint(), IuvoUnity.DataStructs.Timer.AwaitFinish(), IuvoUnity.Inputs.InputActionBase.Awake(), IuvoUnity.StateMachines.CSM.ConditionalStateMachine.Awake(), IuvoUnity.StateMachines.CSM.ConditionalStateMachine.ChangeState(), IuvoUnity.DataStructs.ContextKeyGroups.CheckForDuplicateEnumNames(), IuvoUnity.Extensions.BoxColliderExtensions.CombineBoxCollidersToMesh(), IuvoUnity.BaseClasses.DamageComponent.DamageComponent(), IuvoUnity.BaseClasses.DamageComponent.DealDamage(), DebugIuvoGame(), IuvoUnity.DataStructs.DecrementTimer.DecrementTimer(), IuvoUnity.Configurations.LevelConfiguration.DeserializeLevelComponent(), IuvoUnity.ProceduralGeneration.ProceduralStripMesh.GenerateMesh(), IuvoUnity.Configurations.BaseConfig< T >.GetConfigSerializePath(), IuvoUnity.DataStructs.MultiTimer.GetDuration(), IuvoUnity.Configurations.LevelConfiguration.GetExpAtLevel(), IuvoUnity.StateMachines.CSM.ConditionalStateMachine.HandleContinue(), IuvoUnity.StateMachines.CSM.ConditionalStateMachine.HandleFallbackLogic(), IuvoUnity.BaseClasses.HealthComponent.Heal(), IuvoUnity.DataStructs.IncrementTimer.IncrementTimer(), IuvoUnity.DataStructs.Chain< T >.InsertAt(), IuvoUnity.BaseClasses.LevelComponent.LoseExperience(), IuvoUnity.BaseClasses.LevelComponent.LoseLevels(), IuvoUnity.DataStructs.MultiTimer.Remaining(), IuvoUnity.DataStructs.Context.Set< T >(), IuvoUnity.DataStructs.MultiTimer.SetDuration(), IuvoUnity.RPG.Stat.SetStatName(), IuvoUnity.Extensions.BoxColliderExtensions.SnapTo(), IuvoUnity.BaseClasses.LevelComponent.SpendLevelUpPoint(), IuvoUnity.BaseClasses.HealthComponent.Start(), IuvoUnity.StateMachines.CSM.ConditionalStateMachineAnalyzer.Start(), IuvoUnity.BaseClasses.HealthComponent.TakeDamage(), IuvoUnity.Debug.TestDebugButton.TestFunction(), IuvoUnity.StateMachines.CSM.ConditionalStateMachine.TryChangeState(), IuvoUnity.DataStructs.Chain< T >.ValidateLinks(), IuvoUnity.Extensions.MaterialExtensions.WithBuffer(), IuvoUnity.Extensions.MaterialExtensions.WithMainColor(), IuvoUnity.Extensions.MaterialExtensions.WithMainTexture(), IuvoUnity.Extensions.MaterialExtensions.WithRenderingMode(), IuvoUnity.Extensions.MaterialExtensions.WithShader(), IuvoUnity.Extensions.MaterialExtensions.WithShader(), IuvoUnity.Extensions.MaterialExtensions.WithShader(), and IuvoUnity.Extensions.MaterialExtensions.WithTextureArray().

◆ DebugLossyScale()

void IuvoUnity.Debug.IuvoDebug.DebugLossyScale ( Vector3 lossyScale,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
322 {
323 if (!EnabledLevels.Contains(ValidationLevel.Debug)) return;
324 DebugLog($"Lossy Scale: {lossyScale:F3}", false, memberName, filePath, lineNumber);
325 }

References DebugLog(), and EnabledLevels.

Referenced by DebugTransform().

◆ DebugPosition()

void IuvoUnity.Debug.IuvoDebug.DebugPosition ( Vector3 position,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
294 {
295 if (!EnabledLevels.Contains(ValidationLevel.Debug)) return;
296 DebugLog($"Position: {position:F3}", false, memberName, filePath, lineNumber);
297 }

References DebugLog(), and EnabledLevels.

Referenced by DebugTransform().

◆ DebugRotation()

void IuvoUnity.Debug.IuvoDebug.DebugRotation ( Quaternion rotation,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
301 {
302 if (!EnabledLevels.Contains(ValidationLevel.Debug)) return;
303 DebugLog($"Quaternion: {rotation.x:F3}, {rotation.y:F3}, {rotation.z:F3}, {rotation.w:F3}", false, memberName, filePath, lineNumber);
304 }

References DebugLog(), and EnabledLevels.

Referenced by DebugTransform().

◆ DebugScale()

void IuvoUnity.Debug.IuvoDebug.DebugScale ( Vector3 scale,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
315 {
316 if (!EnabledLevels.Contains(ValidationLevel.Debug)) return;
317 DebugLog($"Scale: {scale:F3}", false, memberName, filePath, lineNumber);
318 }

References DebugLog(), and EnabledLevels.

Referenced by DebugTransform().

◆ DebugTransform()

void IuvoUnity.Debug.IuvoDebug.DebugTransform ( Transform toDebug,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
282 {
283 if (!EnabledLevels.Contains(ValidationLevel.Debug)) return;
284
285 DebugPosition(toDebug.position, memberName, filePath, lineNumber);
286 DebugRotation(toDebug.rotation, memberName, filePath, lineNumber);
287 DebugEulerAngles(toDebug.eulerAngles, memberName, filePath, lineNumber);
288 DebugScale(toDebug.localScale, memberName, filePath, lineNumber);
289 DebugLossyScale(toDebug.lossyScale, memberName, filePath, lineNumber);
290 }

References DebugEulerAngles(), DebugLossyScale(), DebugPosition(), DebugRotation(), DebugScale(), and EnabledLevels.

◆ EnableValidationLevel()

void IuvoUnity.Debug.IuvoDebug.EnableValidationLevel ( ValidationLevel level,
bool enable )
static
32 {
33 if (enable) EnabledLevels.Add(level);
34 else EnabledLevels.Remove(level);
35 }

References EnabledLevels.

◆ EnqueueLog()

void IuvoUnity.Debug.IuvoDebug.EnqueueLog ( string message)
staticprivate
90 {
91 lock (fileLock)
92 {
93 if (EnabledDestinations.Contains(LogDestination.CustomFile) && !string.IsNullOrEmpty(customLogFilePath))
94 {
95 customLogQueue.Enqueue(message);
96 }
97
98 if (EnabledDestinations.Contains(LogDestination.PersistentFile))
99 {
100 persistentLogQueue.Enqueue(message);
101 }
102
103 if (EnabledDestinations.Contains(LogDestination.EditorFile))
104 {
105 editorLogQueue.Enqueue(message);
106 }
107 }
108 }

References customLogFilePath, customLogQueue, editorLogQueue, EnabledDestinations, fileLock, and persistentLogQueue.

Referenced by DebugLog(), DebugLogError(), and DebugLogWarning().

◆ FinalFlushOnQuitCustomLog()

void IuvoUnity.Debug.IuvoDebug.FinalFlushOnQuitCustomLog ( )
staticprivate
224 {
225 lock (fileLock)
226 {
227 if (editorLogQueue.Count > 0)
228 {
229 try
230 {
231 Directory.CreateDirectory(Path.GetDirectoryName(customLogFilePath));
232 File.AppendAllLines(customLogFilePath, customLogQueue);
233 customLogQueue.Clear();
234 }
235 catch (Exception ex)
236 {
237 UnityEngine.Debug.LogError($"[IuvoDebug] Final flush failed: {ex}");
238 }
239 }
240 }
241 }

References customLogFilePath, customLogQueue, editorLogQueue, and fileLock.

Referenced by Initialize().

◆ FinalFlushOnQuitEditorLog()

void IuvoUnity.Debug.IuvoDebug.FinalFlushOnQuitEditorLog ( )
staticprivate
204 {
205 lock (fileLock)
206 {
207 if (editorLogQueue.Count > 0)
208 {
209 try
210 {
211 Directory.CreateDirectory(Path.GetDirectoryName(editorLogFilePath));
212 File.AppendAllLines(editorLogFilePath, editorLogQueue);
213 editorLogQueue.Clear();
214 }
215 catch (Exception ex)
216 {
217 UnityEngine.Debug.LogError($"[IuvoDebug] Final flush failed: {ex}");
218 }
219 }
220 }
221 }

References editorLogFilePath, editorLogQueue, and fileLock.

Referenced by Initialize().

◆ FinalFlushOnQuitPersistentLog()

void IuvoUnity.Debug.IuvoDebug.FinalFlushOnQuitPersistentLog ( )
staticprivate
184 {
185 lock (fileLock)
186 {
187 if (persistentLogQueue.Count > 0)
188 {
189 try
190 {
191 Directory.CreateDirectory(Path.GetDirectoryName(persistentLogFilePath));
192 File.AppendAllLines(persistentLogFilePath, persistentLogQueue);
193 persistentLogQueue.Clear();
194 }
195 catch (Exception ex)
196 {
197 UnityEngine.Debug.LogError($"[IuvoDebug] Final flush failed: {ex}");
198 }
199 }
200 }
201 }

References fileLock, persistentLogFilePath, and persistentLogQueue.

Referenced by Initialize().

◆ FlushCustomLogQueueRoutine()

System.Collections.IEnumerator IuvoUnity.Debug.IuvoDebug.FlushCustomLogQueueRoutine ( )
staticprivate
159 {
160 while (true)
161 {
162 lock (fileLock)
163 {
164 if (editorLogQueue.Count > 0)
165 {
166 try
167 {
168 Directory.CreateDirectory(Path.GetDirectoryName(customLogFilePath));
169 File.AppendAllLines(customLogFilePath, customLogQueue);
170 customLogQueue.Clear(); // only clear on success
171 }
172 catch (Exception ex)
173 {
174 UnityEngine.Debug.LogError($"[IuvoDebug] Failed to write log to file: {ex}");
175 }
176 }
177 }
178 yield return new WaitForSecondsRealtime(1f); // batch write every 1 sec
179 }
180 }

References customLogFilePath, customLogQueue, editorLogQueue, and fileLock.

Referenced by Initialize().

◆ FlushEditorLogQueueRoutine()

System.Collections.IEnumerator IuvoUnity.Debug.IuvoDebug.FlushEditorLogQueueRoutine ( )
staticprivate
135 {
136 while (true)
137 {
138 lock (fileLock)
139 {
140 if (editorLogQueue.Count > 0)
141 {
142 try
143 {
144 Directory.CreateDirectory(Path.GetDirectoryName(editorLogFilePath));
145 File.AppendAllLines(editorLogFilePath, editorLogQueue);
146 editorLogQueue.Clear(); // only clear on success
147 }
148 catch (Exception ex)
149 {
150 UnityEngine.Debug.LogError($"[IuvoDebug] Failed to write log to file: {ex}");
151 }
152 }
153 }
154 yield return new WaitForSecondsRealtime(1f); // batch write every 1 sec
155 }
156 }

References editorLogFilePath, editorLogQueue, and fileLock.

Referenced by Initialize().

◆ FlushPersistentLogQueueRoutine()

System.Collections.IEnumerator IuvoUnity.Debug.IuvoDebug.FlushPersistentLogQueueRoutine ( )
staticprivate
111 {
112 while (true)
113 {
114 lock (fileLock)
115 {
116 if (persistentLogQueue.Count > 0)
117 {
118 try
119 {
120 Directory.CreateDirectory(Path.GetDirectoryName(persistentLogFilePath));
121 File.AppendAllLines(persistentLogFilePath, persistentLogQueue);
122 persistentLogQueue.Clear(); // only clear on success
123 }
124 catch (Exception ex)
125 {
126 UnityEngine.Debug.LogError($"[IuvoDebug] Failed to write log to file: {ex}");
127 }
128 }
129 }
130 yield return new WaitForSecondsRealtime(1f); // batch write every 1 sec
131 }
132 }

References fileLock, persistentLogFilePath, and persistentLogQueue.

Referenced by Initialize().

◆ FormatMessage()

string IuvoUnity.Debug.IuvoDebug.FormatMessage ( string level,
string message,
string memberName,
string filePath,
int lineNumber,
out string richTextMessage,
bool richTxtMsg )
staticprivate
246 {
247 string fileName = Path.GetFileName(filePath);
248
249 string color = level == "[ERROR]" ? "orange" :
250 level == "[WARNING]" ? "yellow" :
251 "green";
252
253 string richLevel = $"<color={color}>{level}</color>";
254
255
256
257 string richMessage = $"<color={color}>{message}</color>";
258 if (level == "[WARNING]") richMessage = $"<color={color}><i>{message}</i></color>";
259 else if (level == "[ERROR]") richMessage = $"<color={color}><b>{message}</b></color>";
260
261 string location = $"[{memberName} in {fileName}:{lineNumber}]";
262 string richLocation = $"[{memberName} in {fileName}:{lineNumber}]";
263 if (level == "[ERROR]") richLocation = $"<b>[{memberName} in {fileName}:{lineNumber}]</b>";
264
265 string val = $"{level} {message} {location}";
266 richTextMessage = val;
267 if (!richTxtMsg)
268 {
269 richMessage = message;
270 richLocation = $"[{memberName} in {fileName}:{lineNumber}]";
271 richTextMessage = $"{level} {richMessage} {richLocation}";
272 }
273
274 string dateTime = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
275 val = $"{dateTime} {val}";
276 return val;
277 }

Referenced by DebugLog(), DebugLogError(), and DebugLogWarning().

◆ Initialize()

void IuvoUnity.Debug.IuvoDebug.Initialize ( )
static
37 {
38 if (!coroutineStarted)
39 {
40 // Create a persistent runner for coroutines
41 var runnerObj = new GameObject("IuvoDebugRunner");
42 UnityEngine.Object.DontDestroyOnLoad(runnerObj);
43 var runner = runnerObj.AddComponent<IuvoDebugRunner>();
44 runner.StartCoroutine(FlushPersistentLogQueueRoutine());
45 runner.StartCoroutine(FlushEditorLogQueueRoutine());
46 runner.StartCoroutine(FlushCustomLogQueueRoutine());
47
48 // Ensure final flush on quit
49 Application.quitting += FinalFlushOnQuitPersistentLog;
50 Application.quitting += FinalFlushOnQuitEditorLog;
51 Application.quitting += FinalFlushOnQuitCustomLog;
52
53 coroutineStarted = true;
54 }
55 }

References coroutineStarted, FinalFlushOnQuitCustomLog(), FinalFlushOnQuitEditorLog(), FinalFlushOnQuitPersistentLog(), FlushCustomLogQueueRoutine(), FlushEditorLogQueueRoutine(), and FlushPersistentLogQueueRoutine().

Referenced by IuvoUnity.Debug.TestDebugButton.Awake().

◆ RaycastDebug()

bool IuvoUnity.Debug.IuvoDebug.RaycastDebug ( Vector3 origin,
Vector3 direction,
out RaycastHit hit,
float distance = Mathf::Infinity,
int layerMask = Physics::DefaultRaycastLayers,
Color? debugColor = null,
[CallerMemberName] string memberName = "",
[CallerFilePath] string filePath = "",
[CallerLineNumber] int lineNumber = 0 )
static
330 {
331 if (!EnabledLevels.Contains(ValidationLevel.Debug))
332 {
333 hit = new RaycastHit();
334 return false;
335 }
336
337 return PhysicsHelpers.RaycastDebug(origin, direction, out hit, distance, layerMask, debugColor);
338 }

References EnabledLevels, and IuvoUnity.IuvoPhysics.PhysicsHelpers.RaycastDebug().

◆ SetLogFilePath()

void IuvoUnity.Debug.IuvoDebug.SetLogFilePath ( string path)
static
82 {
83 lock (fileLock)
84 {
85 customLogFilePath = string.IsNullOrEmpty(path) ? persistentLogFilePath : path;
86 }
87 }

References customLogFilePath, fileLock, and persistentLogFilePath.

Member Data Documentation

◆ coroutineStarted

bool IuvoUnity.Debug.IuvoDebug.coroutineStarted = false
staticprivate

Referenced by Initialize().

◆ customLogFilePath

string IuvoUnity.Debug.IuvoDebug.customLogFilePath = ""
staticprivate

◆ customLogQueue

readonly Queue<string> IuvoUnity.Debug.IuvoDebug.customLogQueue = new Queue<string>()
staticprivate

◆ editorLogFilePath

string IuvoUnity.Debug.IuvoDebug.editorLogFilePath = Path.Combine(Application.dataPath, "IuvoDebugLog_Editor.txt")
staticprivate

◆ editorLogQueue

readonly Queue<string> IuvoUnity.Debug.IuvoDebug.editorLogQueue = new Queue<string>()
staticprivate

◆ EnabledDestinations

HashSet<LogDestination> IuvoUnity.Debug.IuvoDebug.EnabledDestinations
static
Initial value:
= new HashSet<LogDestination>
{
LogDestination.PersistentFile,
LogDestination.EditorFile,
}
LogDestination
Definition IuvoDebug.cs:59
@ CustomFile
Definition IuvoDebug.cs:62
65 {
66 LogDestination.PersistentFile,
67 LogDestination.EditorFile,
68 LogDestination.CustomFile
69 };

Referenced by EnqueueLog().

◆ EnabledLevels

HashSet<ValidationLevel> IuvoUnity.Debug.IuvoDebug.EnabledLevels
static
Initial value:
= new HashSet<ValidationLevel>
{
ValidationLevel.Warning,
}
ValidationLevel
Definition IuvoDebug.cs:19
@ Error
Definition IuvoDebug.cs:22
26 {
27 ValidationLevel.Debug,
28 ValidationLevel.Warning,
29 ValidationLevel.Error
30 };

Referenced by DebugEulerAngles(), DebugIuvoGame(), DebugLog(), DebugLogError(), DebugLogWarning(), DebugLossyScale(), DebugPosition(), DebugRotation(), DebugScale(), DebugTransform(), EnableValidationLevel(), and RaycastDebug().

◆ fileLock

◆ persistentLogFilePath

string IuvoUnity.Debug.IuvoDebug.persistentLogFilePath = Path.Combine(Application.persistentDataPath, "IuvoDebugLog_Persistent.txt")
staticprivate

◆ persistentLogQueue

readonly Queue<string> IuvoUnity.Debug.IuvoDebug.persistentLogQueue = new Queue<string>()
staticprivate

The documentation for this class was generated from the following file:
  • D:/Unity/IuvoUnityCore/Assets/IuvoUnity/Runtime/Debug/IuvoDebug.cs