,如果你想看到(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方法,或者這個類沒有附加到層次結構中的更多對象。