123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198 |
- using System;
- using System.Diagnostics;
- using UnityEngine;
- namespace kt.Utility
- {
- public static class DebugUtility
- {
- public static void LogErrorFromException(Exception exception)
- {
- DebugUtility.LogErrorFromException(null, exception);
- }
- public static void LogErrorFromException(string message, Exception exception)
- {
- if (!string.IsNullOrEmpty(message))
- {
- UnityEngine.Debug.LogError(message);
- }
- UnityEngine.Debug.LogException(exception);
- }
- public static void MessageBox(string f_strTitle, string f_strMsg)
- {
- NUty.WinMessageBox(NUty.GetWindowHandle(), f_strMsg, f_strTitle, 0);
- }
- public static void DrawAxis(Vector3 pos, Quaternion rot, Color x_color, Color y_color, Color z_color, float line_length = 0.0625f)
- {
- UnityEngine.Debug.DrawLine(pos, pos + rot * Vector3.right * line_length, x_color);
- UnityEngine.Debug.DrawLine(pos, pos + rot * Vector3.up * line_length, y_color);
- UnityEngine.Debug.DrawLine(pos, pos + rot * Vector3.forward * line_length, z_color);
- }
- public static void DrawAxis(Vector3 pos, Quaternion rot, float line_length = 0.0625f)
- {
- DebugUtility.DrawAxis(pos, rot, Color.red, Color.green, Color.blue, line_length);
- }
- public static void DrawObjAxis(Transform obj_trans, Color x_color, Color y_color, Color z_color, float line_length = 0.0625f)
- {
- DebugUtility.DrawAxis(obj_trans.position, obj_trans.rotation, x_color, y_color, z_color, line_length);
- }
- public static void DrawObjAxis(Transform obj_trans, float ray_length = 0.0625f)
- {
- DebugUtility.DrawObjAxis(obj_trans, Color.red, Color.green, Color.blue, ray_length);
- }
- public static void DrawSquare(Vector3 pos, Quaternion rot, Vector3 forward_axis, Color axis_col, Color square_col, float size = 0.025f)
- {
- UnityEngine.Debug.DrawRay(pos, rot * forward_axis * size, axis_col);
- rot *= Quaternion.FromToRotation(Vector3.forward, forward_axis);
- Vector3 vector = pos + rot * (Vector3.right + Vector3.up) * size;
- Vector3 vector2 = pos + rot * (Vector3.right + Vector3.down) * size;
- Vector3 vector3 = pos + rot * (Vector3.left + Vector3.down) * size;
- Vector3 vector4 = pos + rot * (Vector3.left + Vector3.up) * size;
- UnityEngine.Debug.DrawLine(vector, vector2, square_col);
- UnityEngine.Debug.DrawLine(vector2, vector3, square_col);
- UnityEngine.Debug.DrawLine(vector3, vector4, square_col);
- UnityEngine.Debug.DrawLine(vector4, vector, square_col);
- }
- public static void DrawSquare(Vector3 pos, Quaternion rot, Vector3 forward_axis, float size = 0.025f)
- {
- DebugUtility.DrawSquare(pos, rot, forward_axis, Color.blue, Color.white, size);
- }
- public static void DrawSquare(Vector3 pos, Quaternion rot, float size = 0.025f)
- {
- DebugUtility.DrawSquare(pos, rot, Vector3.forward, Color.blue, Color.white, size);
- }
- public static void Vec3DetailLog(Vector3 vec)
- {
- UnityEngine.Debug.LogFormat("({0}, {1}, {2})", new object[]
- {
- vec.x,
- vec.y,
- vec.z
- });
- }
- public static class Assert
- {
- public static void IsTrue(bool condition)
- {
- DebugUtility.Assert.Call(condition, "Assertion failed. Value was False.");
- }
- public static void IsTrue(bool condition, string message)
- {
- DebugUtility.Assert.Call(condition, message);
- }
- public static void IsFalse(bool condition)
- {
- DebugUtility.Assert.Call(!condition, "Assertion failed. Value was True.");
- }
- public static void IsFalse(bool condition, string message)
- {
- DebugUtility.Assert.Call(!condition, message);
- }
- public static void IsNull<T>(T value) where T : class
- {
- DebugUtility.Assert.Call(value == null, "Assertion failed. Value was not Null.");
- }
- public static void IsNull(UnityEngine.Object value, string message)
- {
- DebugUtility.Assert.Call(value == null, message);
- }
- public static void IsNull<T>(T value, string message) where T : class
- {
- DebugUtility.Assert.Call(value == null, message);
- }
- public static void IsNotNull<T>(T value) where T : class
- {
- DebugUtility.Assert.Call(value != null, "Assertion failed. Value was Null.");
- }
- public static void IsNotNull(UnityEngine.Object value, string message)
- {
- DebugUtility.Assert.Call(value != null, message);
- }
- public static void IsNotNull<T>(T value, string message) where T : class
- {
- DebugUtility.Assert.Call(value != null, message);
- }
- public static void Call(bool condition, string message)
- {
- if (condition)
- {
- return;
- }
- DebugUtility.Assert.Call(message);
- }
- public static void Call(string message)
- {
- if (message == null)
- {
- message = string.Empty;
- }
- StackFrame stackFrame = new StackFrame(1, true);
- string fileName = stackFrame.GetFileName();
- int fileLineNumber = stackFrame.GetFileLineNumber();
- string f_strMsg = string.Concat(new object[]
- {
- fileName,
- "(",
- fileLineNumber,
- ") \n",
- message
- });
- UnityEngine.Debug.LogError("Assert! " + message);
- DebugUtility.MessageBox("Error", f_strMsg);
- UnityEngine.Debug.Break();
- Application.Quit();
- }
- public static void Call(bool condition, Func<string> messageCallback)
- {
- if (condition)
- {
- return;
- }
- DebugUtility.Assert.Call(messageCallback);
- }
- public static void Call(Func<string> messageCallback)
- {
- StackFrame stackFrame = new StackFrame(1, true);
- string fileName = stackFrame.GetFileName();
- int fileLineNumber = stackFrame.GetFileLineNumber();
- string text = (messageCallback == null) ? string.Empty : messageCallback();
- string f_strMsg = string.Concat(new object[]
- {
- fileName,
- "(",
- fileLineNumber,
- ") \n",
- text
- });
- UnityEngine.Debug.LogError("Assert! " + text);
- DebugUtility.MessageBox("Error", f_strMsg);
- UnityEngine.Debug.Break();
- Application.Quit();
- }
- }
- }
- }
|