Unity日志工具类的两种封装

思考并回答以下问题:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
using System;
#if UNITY_ENGINE
using UnityEngine;
#endif

public enum LogLevel
{
None = 0,
Exception = 1,
Error = 2,
Warning = 3,
Normal = 4,
Max = 5,
}

public static class Log
{

public static void LogInfo(this object selfMsg)
{
I(selfMsg);
}

public static void LogWarning(this object selfMsg)
{
W(selfMsg);
}

public static void LogError(this object selfMsg)
{
E(selfMsg);
}

public static void LogException(this Exception selfExp)
{
E(selfExp);
}

private static LogLevel mLogLevel = LogLevel.Normal;

public static LogLevel Level
{
get { return mLogLevel; }
set { mLogLevel = value; }
}

public static void I(object msg, params object[] args)
{
if (mLogLevel < LogLevel.Normal)
{
return;
}

if (args == null || args.Length == 0)
{
#if UNITY_ENGINE
Debug.Log(msg);
#endif
}
else
{
#if UNITY_ENGINE
Debug.LogFormat(msg.ToString(), args);
#endif
}
}

public static void E(Exception e)
{
if (mLogLevel < LogLevel.Exception)
{
return;
}
#if UNITY_ENGINE
Debug.LogException(e);
#endif
}

public static void E(object msg, params object[] args)
{
if (mLogLevel < LogLevel.Error)
{
return;
}

if (args == null || args.Length == 0)
{
#if UNITY_ENGINE
Debug.LogError(msg);
#endif
}
else
{
#if UNITY_ENGINE

Debug.LogError(string.Format(msg.ToString(), args));
#endif
}

}

public static void W(object msg)
{
if (mLogLevel < LogLevel.Warning)
{
return;
}
#if UNITY_ENGINE

Debug.LogWarning(msg);
#endif
}

public static void W(string msg, params object[] args)
{
if (mLogLevel < LogLevel.Warning)
{
return;
}
#if UNITY_ENGINE

Debug.LogWarning(string.Format(msg, args));
#endif
}
}
}

插件,DLL格式

1
2


0%