/// <summary> /// 连接到工具服务端,开始收集数据 /// </summary> /// <param name="host">Host.</param> /// <param name="port">Port.</param> /// <param name="isUDP">If set to <c>true</c> is UD.</param> public static void Begin(string host, int port, bool isUDP) { GameObject go = Common.go; LuaProfiler profiler = go.GetComponent <LuaProfiler>(); if (profiler == null) { profiler = go.AddComponent <LuaProfiler>(); } else { if (profiler.enabled) { return; } profiler.enabled = true; } s_isUDP = isUDP; if (isUDP) { if (s_udp == null) { s_udp = new UdpSocket { callback = EventCallback }; } s_udp.Connect(host, port, (uint)port); } else { if (s_tcp == null) { s_tcp = new TcpSocket { callback = EventCallback }; } s_tcp.Connect(host, port); } s_luaBegin.BeginPCall(); s_luaBegin.PCall(); s_luaBegin.EndPCall(); Logger.Log("Begin!", "LuaProfiler"); }
void OnGUI() { if (m_labelStyle == null) { m_labelStyle = new GUIStyle(); m_labelStyle.normal.textColor = Color.white; m_labelStyle.fontSize = 30; m_tfStyle = new GUIStyle(GUI.skin.textField); m_tfStyle.alignment = TextAnchor.MiddleCenter; m_tfStyle.fontSize = 30; m_btnStyle = new GUIStyle(GUI.skin.button); m_btnStyle.fontSize = 30; } if (m_profiler == null) { m_profiler = Common.go.GetComponent <LuaProfiler> (); } bool notRunning = m_profiler == null || !m_profiler.enabled; // ip and port GUI.enabled = notRunning; GUI.Label(m_p1, "ip :", m_labelStyle); m_ip = GUI.TextField(m_p2, m_ip, m_tfStyle); GUI.Label(m_p3, "port :", m_labelStyle); m_port = GUI.TextField(m_p4, m_port, m_tfStyle); if (m_isUDP) { m_isUDP = GUI.Button(m_p5, "tcp", m_btnStyle); } else { m_isUDP = !GUI.Button(m_p5, "udp", m_btnStyle); } GUI.enabled = true; // begin or end if (notRunning) { if (GUI.Button(m_p6, "BEGIN", m_btnStyle)) { LuaProfiler.Begin(m_ip, Int32.Parse(m_port), m_isUDP); PlayerPrefs.SetString("LuaProfiler.ip", m_ip); PlayerPrefs.SetString("LuaProfiler.port", m_port); PlayerPrefs.SetInt("LuaProfiler.isUDP", m_isUDP ? 1 : 0); } } else { if (GUI.Button(m_p6, "END", m_btnStyle)) { LuaProfiler.End(); } } // close if (GUI.Button(m_p7, "x", m_btnStyle)) { this.enabled = false; } }
private static void ShowLuaProfilerConsole() { LuaProfiler.Console(true); }