private void DrawLog() { GUILayout.BeginVertical(); posLeft = GUILayout.BeginScrollView(posLeft, GUILayout.MinHeight(splitterPos), GUILayout.Height(splitterPos), GUILayout.MaxHeight(splitterPos), GUILayout.ExpandWidth(true)); int logStart = 0; for (int i = 0; i < logDatas.Count; i++) { LogData logData = logDatas[i]; if (!logLevels.Contains(logData.logLevel)) { continue; } logStart += 1; if (GUILayout.Toggle(selectLog == i, string.Format("[{0}] [{1}] {2}\n{3}", logData.logTime.ToString(TIME_FORMATER), logData.logLevel, logData.logMessage, logData.logBasicData), logStart % 2 == 0 ? LogStyle1 : LogStyle2, GUILayout.ExpandWidth(true), GUILayout.Height(logHeight))) { if (selectLog == i) { continue; } selectLog = i; detailedLog = string.Format("[{0}] [{1}] {2}\n{3}\n{4}", logData.logTime.ToString(TIME_FORMATER), logData.logLevel, logData.logMessage, logData.logBasicData, logData.logTrack); } } GUILayout.EndScrollView(); // 分割线 GUILayout.Box("", SplitterStyle, GUILayout.Height(6), GUILayout.ExpandWidth(true)); splitterRect = GUILayoutUtility.GetLastRect(); // 显示详细信息 posRight = GUILayout.BeginScrollView(posRight, GUILayout.ExpandWidth(true), GUILayout.ExpandHeight(true)); GUILayout.Label(detailedLog, LogStyle1); GUILayout.EndScrollView(); GUILayout.EndVertical(); if (Event.current != null) { if (Event.current.rawType == EventType.MouseUp) { if (dragging) { dragging = false; Cursors.SetCursor(CursorType.Arrow); } } if (dragging) { splitterPos = Event.current.mousePosition.y - 83; if (splitterPos >= windowRect.height - logHeight - 110) { splitterPos = windowRect.height - logHeight - 110; } if (splitterPos <= logHeight) { splitterPos = logHeight; } } if (splitterRect.size.x == 1) { return; } if (splitterRect.Contains(Event.current.mousePosition)) { Cursors.SetCursor(CursorType.SizeNS); if (Event.current.rawType == EventType.MouseDown) { dragging = true; } } else { if (!dragging) { Cursors.SetCursor(CursorType.Arrow); } } } else { if (dragging) { dragging = false; } } }
/// <summary> /// 绘制日志 /// </summary> private void DrawLog() { GUILayout.BeginVertical(); DrawSplitLineHorizontal(); logScrollPos = GUILayout.BeginScrollView(logScrollPos, GUILayout.ExpandWidth(true)); int logStart = 0; if (!isCollapse) { for (int i = 0; i < logDatas.Count; i++) { LogData logData = logDatas[i]; if (!logLevels.Contains(logData.logLevel)) { continue; } logStart += 1; if (GUILayout.Toggle(selectLog == i, string.Format("[{0}] [{1}] {2}\n{3}", logData.logTime.ToString(TIME_FORMATER), logData.logLevel, logData.logMessage, logData.logBasicData), logStyle, GUILayout.ExpandWidth(true), GUILayout.Height(logHeight))) { if (selectLog != i) { selectLog = i; detailedLog = string.Format("[{0}] [{1}] {2}\n{3}\n{4}", logData.logTime.ToString(TIME_FORMATER), logData.logLevel, logData.logMessage, logData.logBasicData, logData.logTrack); } } GUI.Label(GUILayoutUtility.GetLastRect(), LogLevelIcons[(int)logData.logLevel - 1], logIconStyle); } } else { for (int i = 0; i < logCollapseDatas.Count; i++) { LogData logData = logCollapseDatas[i]; if (!logLevels.Contains(logData.logLevel)) { continue; } logStart += 1; if (GUILayout.Toggle(selectLog == i, string.Format("[{0}] [{1}] {2}\n{3}", logData.logTime.ToString(TIME_FORMATER), logData.logLevel, logData.logMessage, logData.logBasicData), logStyle, GUILayout.ExpandWidth(true), GUILayout.Height(logHeight))) { if (selectLog != i) { selectLog = i; detailedLog = string.Format("[{0}] [{1}] {2}\n{3}\n{4}", logData.logTime.ToString(TIME_FORMATER), logData.logLevel, logData.logMessage, logData.logBasicData, logData.logTrack); } } Rect rect = GUILayoutUtility.GetLastRect(); GUI.Label(rect, LogLevelIcons[(int)logData.logLevel - 1], logIconStyle); Debug.Log(logScrollPos); rect.x += logScrollPos.x + Screen.width - 300; //GUILayout.Label(logCollapseCount[i].ToString(), logLevelIconToggleStyle, logLevelButtonOptions); //GUILayout.Label(LogLevelIcons[(int)logData.logLevel - 1], logCollapseCountStyle); GUI.Label(rect, logCollapseCount[i].ToString(), logCollapseCountStyle); } } GUILayout.EndScrollView(); GUILayout.EndVertical(); }
public void Log(LogData logData) { logDatas.Add(logData); }