private void LeftView(float height) { GUI.Box(new Rect(30, 74, 140, height), ""); GUILayout.BeginArea(new Rect(30, 75, 140, height)); m_snapScroll = GUILayout.BeginScrollView(m_snapScroll); for (int i = 0; i < m_snaps.Count; i++) { GUILayout.BeginHorizontal(); bool isSelectItem = false; if (m_snaps[i].Id == m_selectSnap.Id) { GUI.contentColor = Color.green; isSelectItem = true; } if (GUILayout.Button(m_snaps[i].Name)) { m_selectSnap = m_snaps[i]; } if (GUILayout.Button("x", GUILayout.Width(20))) { m_snaps.Remove(m_snaps[i]); if (isSelectItem && m_snaps.Count > 0) { m_selectSnap = m_snaps[0]; } return; } GUILayout.EndHorizontal(); GUI.contentColor = Color.white; } GUILayout.EndScrollView(); GUILayout.EndArea(); }
public void SnapShot(params object[] objs) { string profileName = (string)objs[0]; string text = (string)objs[1]; LuaTimeProfile profiler = null; if (string.IsNullOrEmpty(profileName)) { profiler = new LuaTimeProfile(++m_snapCount); } else { profiler = new LuaTimeProfile(profileName); } string[] lines = text.Split(new string[] { "\n" }, StringSplitOptions.None); for (int i = 1; i < lines.Length; i++) { string line = lines[i]; if (string.IsNullOrEmpty(line)) { continue; } //string[] fields = line.Split(new string[] { " : " }, StringSplitOptions.None); string[] fields = new string[6]; fields[0] = line.Substring(0, 41); fields[1] = line.Substring(43, 50); fields[2] = line.Substring(95, 12); fields[3] = line.Substring(109, 12); fields[4] = line.Substring(123, 12); fields[5] = line.Substring(137, 12); LuaTimeProfileItem item = new LuaTimeProfileItem(); item.RawText = line; item.Function = fields[0].Replace("|", "").Trim(); item.Source = fields[1].Trim(); item.Total = float.Parse(fields[2].Trim()); item.Average = float.Parse(fields[3].Replace("%", "").Trim()); item.Relative = fields[4].Trim(); item.Called = int.Parse(fields[5].Replace("|", "").Trim()); if (item.Source.Contains("perf/profiler")) { continue; } //Debug.Log(line); //Debug.Log(item.Function + " 11 " + item.Source + " 22 " + item.Total + " 33 " + item.Average + " 44 " + item.Relative + " 55 " + item.Called); profiler.ItemList.Add(item); } m_selectSnap = profiler; m_snaps.Add(profiler); SetSortType(m_sortType); }
private void UpBtnView() { GUILayout.BeginHorizontal(); if (GUILayout.Button("Load", GUILayout.Height(20), GUILayout.Width(80))) { string filePath = EditorUtility.OpenFilePanel("加载Lua时间性能分析文件", "", "txt"); string json = File.ReadAllText(filePath); if (!string.IsNullOrEmpty(json)) { LuaTimeProfile lm = JsonUtility.FromJson <LuaTimeProfile>(json); if (lm != null) { for (int i = 0; i < m_snaps.Count; i++) { if (m_snaps[i].Id == lm.Id) { m_selectSnap = m_snaps[i]; Debug.LogError("已经存在该文件"); return; } } m_selectSnap = lm; m_snaps.Add(lm); SetSortType(m_sortType); } } } if (GUILayout.Button("Save", GUILayout.Height(20), GUILayout.Width(80))) { if (m_selectSnap != null) { string filePath = EditorUtility.SaveFilePanel("保存Lua内存分析文件", "", m_selectSnap.Name, "txt"); string json = JsonUtility.ToJson(m_selectSnap); File.WriteAllText(filePath, json); } } if (GUILayout.Button("Clear", GUILayout.Height(20), GUILayout.Width(80))) { m_snaps.Clear(); m_snapCount = 0; m_selectSnap = null; } GUILayout.EndHorizontal(); }