,如果你想看到(EXE我假设)的编译版本的消息的会的debug.log为每个实例运行,那么我建议你建一个名为Debug_UI类,它的唯一目的是将Debug.Log中的所有消息显示到OnGui方法中。首先用你想记录的消息调用一个静态函数,该函数将调用Debug.Log,并将该日志插入到一个静态列表中,该静态列表将用于在OnGui上显示这些消息。
//静态公用事业类与DebugMessage功能
public static List<string> logs= new List<string>();
public static void DebugMessage (string logType, string message) {
logs.Add(message);
if (logType.Equals("warning"))
Debug.LogWarning(message);
else if (logType.Equals("regular"))
Debug.Log(message);
else if (logType.Equals("error"))
Debug.LogError(message);
}
// Debug_UI类
private bool _display;
private bool _log;
public Vector2 scrollPosition;
void OnGUI()
{
if (GUILayout.Button("Log")) _log = !_log;
if (_log)
{
scrollPosition = GUILayout.BeginScrollView(scrollPosition, GUILayout.Width(Screen.width), GUILayout.Height(Screen.height-130));
for(int i= Utilities.logs.Count-1; i >0; i--)
{
GUILayout.Label(Utilities.logs[i]);
}
GUILayout.EndScrollView();
if (GUILayout.Button("Clear"))
Utilities.logs.Clear();
if (GUILayout.Button("Copy To Clipboard"))
GUIUtility.systemCopyBuffer = CopyToClipboard();
}
}
private string CopyToClipboard()
{
string response = null;
for (int i = Utilities.logs.Count - 1; i > 0; i--)
{
response += Utilities.logs[i] + "\n";
}
return response;
}
//你怎么会在你的代码中使用它
public void OnExtensionResponse(BaseEvent evt) {
string cmd = (string)evt.Params["cmd"];
SFSObject dataObject = (SFSObject)evt.Params["params"];
Utilities.Text.DebugMessage("normal","Got response from server: " + cmd + " " + dataObject.GetUtfString("gameStatus"));
switch (cmd) {
}
和对于多次调用的消息,应检查是否未实现OnExtensionResponse方法,或者这个类没有附加到层次结构中的更多对象。