C# 存在Unity日志记录问题的SmartFoxServer
我有一个关于Debug.Log如何在Unity中使用SmartFoxServer的问题。我正在写一个多人游戏。这场比赛总有四名球员。由于Unity/Visual Studio的问题,我无法使用Visual Studio调试器(每次遇到断点时,它都会使Unity崩溃)。因此,我使用Debug.Log 我的问题是:当我有四个客户机在运行(一个在Unity中,另外三个在运行编译的构建)并且我有一个Debug.Log代码在运行时,它会对每个实例运行还是只对Unity实例运行 仅供参考,当我进行构建时,我只进行普通构建。我没有检查开发版本。当我收到服务器的响应时,我看到了奇怪的行为。有时,Debug.Log会打印4次,有时只打印一次。我可以调试Java扩展,断点只命中一次 下面是Unity C#代码的一些示例: 有时上面的Debug.Log代码会被调用一次,有时调用2次或5次。根据日志记录的工作方式,我预计会有1次(它只在Unity版本运行时调试)或4次(在游戏运行的每个实例中调试一次)C# 存在Unity日志记录问题的SmartFoxServer,c#,unity3d,unity5,smartfoxserver,C#,Unity3d,Unity5,Smartfoxserver,我有一个关于Debug.Log如何在Unity中使用SmartFoxServer的问题。我正在写一个多人游戏。这场比赛总有四名球员。由于Unity/Visual Studio的问题,我无法使用Visual Studio调试器(每次遇到断点时,它都会使Unity崩溃)。因此,我使用Debug.Log 我的问题是:当我有四个客户机在运行(一个在Unity中,另外三个在运行编译的构建)并且我有一个Debug.Log代码在运行时,它会对每个实例运行还是只对Unity实例运行 仅供参考,当我进行构建时,我
感谢Debug.Log将为每个实例运行,如果您想查看编译版本(我假设为exe)上的消息,那么我建议您构建一个名为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);
}
//您将如何在代码中使用它
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方法,或者该类没有附加到层次结构中的更多对象
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 ) {
}