| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237 |
- #if (UNITY_5 || UNITY_2017_1_OR_NEWER)
- namespace MikuLuaProfiler
- {
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- using UnityEditor;
- using UnityEngine;
- public class LuaDiffScrollView
- {
- private bool m_isStaticRecord = false;
- private bool m_isRecord = false;
- private string m_staticDateTime = "";
- private string m_dateTime = "";
- LuaDiffInfo luaDiff;
- List<string> m_detailList;
- private Vector2 scrollPositionAdd;
- private Vector2 scrollPositionRm;
- private Vector2 scrollPositionNull;
- private Vector2 scrollPositionDetail;
- public void DoRefScroll()
- {
- if (m_isStaticRecord)
- {
- EditorGUILayout.LabelField(m_staticDateTime);
- }
- if (m_isRecord)
- {
- EditorGUILayout.LabelField(m_dateTime);
- }
- if (luaDiff == null) return;
- GUILayout.BeginHorizontal();
- #region value
- GUILayout.BeginVertical();
- scrollPositionAdd = GUILayout.BeginScrollView(scrollPositionAdd, EditorStyles.helpBox, GUILayout.Height(100));
- int drawCount = 0;
- foreach (var item in luaDiff.addRef)
- {
- string typeStr = item.Key.ToString();
- bool needBreak = false;
- foreach (var v in item.Value)
- {
- DrawItemInfo(v, typeStr, luaDiff.addDetail);
- drawCount++;
- if (drawCount > 200)
- {
- GUILayout.Label("more please show log", GUILayout.Width(400));
- needBreak = true;
- break;
- }
- }
- if (needBreak) break;
- }
- GUILayout.EndScrollView();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField("add values count:" + drawCount, GUILayout.Width(150));
- if (GUILayout.Button("ShowLog", GUILayout.Width(100)))
- {
- ShowLog("add", luaDiff.addRef, luaDiff.addDetail);
- }
- GUILayout.EndHorizontal();
- scrollPositionRm = GUILayout.BeginScrollView(scrollPositionRm, EditorStyles.helpBox, GUILayout.Height(100));
- drawCount = 0;
- foreach (var item in luaDiff.rmRef)
- {
- string typeStr = item.Key.ToString();
- bool needBreak = false;
- foreach (var v in item.Value)
- {
- DrawItemInfo(v, typeStr, luaDiff.rmDetail);
- drawCount++;
- if (drawCount > 200)
- {
- GUILayout.Label("more please show log", GUILayout.Width(400));
- needBreak = true;
- break;
- }
- }
- if (needBreak) break;
- }
- GUILayout.EndScrollView();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField("remain values count:" + drawCount, GUILayout.Width(150));
- if (GUILayout.Button("ShowLog", GUILayout.Width(100)))
- {
- ShowLog("remain", luaDiff.rmRef, luaDiff.rmDetail);
- }
- GUILayout.EndHorizontal();
- scrollPositionNull = GUILayout.BeginScrollView(scrollPositionNull, EditorStyles.helpBox, GUILayout.Height(100));
- drawCount = 0;
- foreach (var item in luaDiff.nullRef)
- {
- string typeStr = item.Key.ToString();
- bool needBreak = false;
- foreach (var v in item.Value)
- {
- DrawItemInfo(v, typeStr, luaDiff.nullDetail);
- drawCount++;
- if (drawCount > 200)
- {
- GUILayout.Label("more please show log", GUILayout.Width(400));
- needBreak = true;
- break;
- }
- }
- if (needBreak) break;
- }
- GUILayout.EndScrollView();
- GUILayout.BeginHorizontal();
- EditorGUILayout.LabelField("Destory null values count:" + drawCount, GUILayout.Width(200));
- if (GUILayout.Button("ShowLog", GUILayout.Width(100)))
- {
- ShowLog("null", luaDiff.nullRef, luaDiff.nullDetail);
- }
- GUILayout.EndHorizontal();
- GUILayout.EndVertical();
- #endregion
- #region detail
- scrollPositionDetail = GUILayout.BeginScrollView(scrollPositionDetail, EditorStyles.helpBox, GUILayout.Width(250));
- if (m_detailList != null)
- {
- foreach (var item in m_detailList)
- {
- GUILayout.Label(item);
- }
- }
- GUILayout.EndScrollView();
- #endregion
- GUILayout.EndHorizontal();
- }
- public void ShowLog(string fileName, Dictionary<LuaTypes, HashSet<string>> refDict, Dictionary<string, List<string>> detailDict)
- {
- StringBuilder sb = new StringBuilder();
- foreach (var item in refDict)
- {
- string typeStr = item.Key.ToString();
- List<string> list = null;
- foreach (var v in item.Value)
- {
- string key = v;
- if (detailDict.TryGetValue(key, out list))
- {
- sb.AppendLine("type:" + typeStr);
- for (int i = 0, imax = list.Count; i < imax; i++)
- {
- if (i == imax - 1)
- {
- sb.AppendLine(" └─ref" + (i + 1) + " url:" + list[i]);
- }
- else
- {
- sb.AppendLine(" ├─ref" + (i + 1) + " url:" + list[i]);
- }
- }
- }
- }
- }
- if (!Directory.Exists(Application.dataPath.Replace("Assets", "Diff")))
- {
- Directory.CreateDirectory(Application.dataPath.Replace("Assets", "Diff"));
- }
- string path = Application.dataPath.Replace("Assets", "Diff/" + fileName + ".txt");
- File.WriteAllText(path, sb.ToString());
- System.Diagnostics.Process.Start("explorer.exe", Application.dataPath.Replace("Assets", "Diff").Replace("/", "\\"));
- }
- public void DrawItemInfo(string key, string value, Dictionary<string, List<string>> dict)
- {
- GUILayout.BeginHorizontal();
- List<string> list = null;
- dict.TryGetValue(key, out list);
- int count = list == null ? 0 : list.Count;
- GUILayout.Label(string.Format("Key:{0}", key), GUILayout.Width(400));
- GUILayout.Label(string.Format("Value:{0}", value));
- GUILayout.Label(string.Format("Ref Count:{0}", count));
- if (GUILayout.Button("detail", GUILayout.Width(100)))
- {
- m_detailList = list == null ? m_detailList : list;
- StringBuilder sb = new StringBuilder();
- foreach (var item in m_detailList)
- {
- sb.AppendLine(item);
- }
- Debug.Log(sb.ToString());
- }
- GUILayout.EndHorizontal();
- }
- public void Clear()
- {
- m_isRecord = false;
- m_isStaticRecord = false;
- luaDiff = null;
- m_dateTime = "";
- m_staticDateTime = "";
- m_detailList = null;
- LuaHook.ClearStaticRecord();
- LuaHook.ClearRecord();
- }
- public void MarkIsStaticRecord()
- {
- m_staticDateTime = "static record:" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- m_isStaticRecord = true;
- }
- public void MarkIsRecord()
- {
- m_dateTime = "record" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
- m_isRecord = true;
- }
- public void DelDiffInfo(LuaDiffInfo info)
- {
- luaDiff = info;
- }
- }
- }
- #endif
|