private void DrawLogList() { _qtLogs = UnityLoggerServer.StartGettingLogs(); _cacheLogCount = _qtLogs; int cntLogs = 0; List <int> rows = new List <int>(_qtLogs); List <BluLog> logs = new List <BluLog>(_qtLogs); for (int i = 0; i < _qtLogs; i++) { var log = GetSimpleLog(i); if (HasPattern(log, i)) { cntLogs++; rows.Add(i); logs.Add(log); } } _qtLogs = cntLogs; float windowWidth = WindowWidth; float windowHeight = _topPanelHeight - DrawYPos; float buttonWidth = ButtonWidth; if (_qtLogs * ButtonHeight > windowHeight) { buttonWidth -= 15f; } float viewWidth = buttonWidth; float viewHeight = _qtLogs * ButtonHeight; Rect scrollViewPosition = new Rect(x: 0f, y: DrawYPos, width: windowWidth, height: windowHeight); Rect scrollViewViewRect = new Rect(x: 0f, y: 0f, width: viewWidth, height: viewHeight); GUI.DrawTexture(scrollViewPosition, BluConsoleSkin.EvenBackTexture); Vector2 oldScrollPosition = _logListScrollPosition; _logListScrollPosition = GUI.BeginScrollView(position: scrollViewPosition, scrollPosition: _logListScrollPosition, viewRect: scrollViewViewRect); int firstRenderLogIndex = (int)(_logListScrollPosition.y / ButtonHeight); firstRenderLogIndex = Mathf.Clamp(firstRenderLogIndex, 0, _qtLogs); int lastRenderLogIndex = firstRenderLogIndex + (int)(windowHeight / ButtonHeight) + 2; lastRenderLogIndex = Mathf.Clamp(lastRenderLogIndex, 0, _qtLogs); float buttonY = firstRenderLogIndex * ButtonHeight; bool hasSomeClick = false; int cnt = 0; for (int i = firstRenderLogIndex; i < lastRenderLogIndex; i++) { var row = rows[i]; var log = logs[i]; var styleBack = GetLogBackStyle(i); var styleMessage = GetLogListStyle(log); string showMessage = GetTruncatedMessage(GetLogListMessage(log)); var contentMessage = new GUIContent(showMessage); var rectMessage = new Rect(x: 0, y: buttonY, width: viewWidth, height: ButtonHeight); bool isSelected = i == _logListSelectedMessage ? true : false; DrawBack(rectMessage, styleBack, isSelected); if (IsRepaintEvent) { styleMessage.Draw(rectMessage, contentMessage, false, false, isSelected, false); } bool messageClicked = IsClicked(rectMessage); bool isLeftClick = messageClicked ? Event.current.button == 0 : false; if (UnityLoggerServer.HasFlag(ConsoleWindowFlag.Collapse)) { int quantity = UnityLoggerServer.GetLogCount(row); var collapseCount = Mathf.Min(quantity, MAX_LENGTH_COLLAPSE); var collapseText = collapseCount.ToString(); if (collapseCount >= MAX_LENGTH_COLLAPSE) { collapseText += "+"; } var collapseContent = new GUIContent(collapseText); var collapseSize = BluConsoleSkin.CollapseStyle.CalcSize(collapseContent); var collapseRect = new Rect(x: viewWidth - collapseSize.x - 5f, y: (buttonY + buttonY + ButtonHeight - collapseSize.y) * 0.5f, width: collapseSize.x, height: collapseSize.y); GUI.Label(collapseRect, collapseContent, BluConsoleSkin.CollapseStyle); } if (messageClicked) { _selectedLog = GetCompleteLog(row); hasSomeClick = true; if (!isLeftClick && i == _logListSelectedMessage) { DrawPopup(Event.current, log); } if (isLeftClick && i == _logListSelectedMessage) { if (IsDoubleClickLogListButton) { _logListLastTimeClicked = 0.0f; var completeLog = GetCompleteLog(row); JumpToSource(completeLog, 0); } else { PingLog(_selectedLog); _logListLastTimeClicked = EditorApplication.timeSinceStartup; } } else { PingLog(_selectedLog); _logListSelectedMessage = i; } _logDetailSelectedFrame = -1; } buttonY += ButtonHeight; cnt++; } UnityLoggerServer.StopGettingsLogs(); GUI.EndScrollView(); if (_hasScrollWheelUp || hasSomeClick) { _isFollowScroll = false; } else if (_logListScrollPosition != oldScrollPosition) { _isFollowScroll = false; float topOffset = viewHeight - windowHeight; if (_logListScrollPosition.y >= topOffset) { _isFollowScroll = true; } } if (!IsFollowScroll) { return; } float endY = viewHeight - windowHeight; _logListScrollPosition.y = endY; }
public override void OnGUI(int id) { base.OnGUI(id); UnityLoggerServer.StartGettingLogs(); SelectedMessage = Mathf.Clamp(SelectedMessage, -1, QtLogs - 1); float buttonWidth = DefaultButtonWidth; if (QtLogs * DefaultButtonHeight > WindowRect.height) { buttonWidth -= 15f; } float viewWidth = buttonWidth; float viewHeight = QtLogs * DefaultButtonHeight; Rect scrollWindowRect = WindowRect; Rect scrollViewRect = new Rect(x: 0f, y: 0f, width: viewWidth, height: viewHeight); GUI.DrawTexture(scrollWindowRect, BluConsoleSkin.EvenBackTexture); Vector2 oldScrollPosition = ScrollPosition; ScrollPosition = GUI.BeginScrollView(position: scrollWindowRect, scrollPosition: ScrollPosition, viewRect: scrollViewRect); GUI.DrawTexture(WindowRect, BluConsoleSkin.OddBackTexture); int firstRenderLogIndex = (int)(ScrollPosition.y / DefaultButtonHeight); firstRenderLogIndex = Mathf.Clamp(firstRenderLogIndex, 0, QtLogs); int lastRenderLogIndex = firstRenderLogIndex + (int)(WindowRect.height / DefaultButtonHeight) + 2; lastRenderLogIndex = Mathf.Clamp(lastRenderLogIndex, 0, QtLogs); // Handling up/down arrow keys if (HasKeyboardArrowKeyInput) { bool isFrameOutsideOfRange = SelectedMessage <firstRenderLogIndex + 1 || SelectedMessage> lastRenderLogIndex - 3; if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Up) { ScrollPosition.y = DefaultButtonHeight * SelectedMessage; } else if (isFrameOutsideOfRange && KeyboardArrowKeyDirection == Direction.Down) { int md = lastRenderLogIndex - firstRenderLogIndex - 3; float ss = md * DefaultButtonHeight; float sd = WindowRect.height - ss; ScrollPosition.y = (DefaultButtonHeight * (SelectedMessage + 1) - ss - sd); } } float buttonY = firstRenderLogIndex * DefaultButtonHeight; bool hasCollapse = UnityLoggerServer.HasFlag(ConsoleWindowFlag.Collapse); bool hasSomeClick = false; for (int i = firstRenderLogIndex; i < lastRenderLogIndex; i++) { int row = Rows[i]; BluLog log = Logs[i]; var styleBack = BluConsoleSkin.GetLogBackStyle(i); var styleMessage = BluConsoleSkin.GetLogListStyle(log.LogType); string showMessage = GetTruncatedListMessage(log); var contentMessage = new GUIContent(showMessage); var rectMessage = new Rect(x: 0, y: buttonY, width: viewWidth, height: DefaultButtonHeight); bool isSelected = i == SelectedMessage; DrawBackground(rectMessage, styleBack, isSelected); if (IsRepaintEvent) { styleMessage.Draw(rectMessage, contentMessage, false, false, isSelected, false); } bool messageClicked = IsClicked(rectMessage); bool isLeftClick = messageClicked && Event.current.button == 0; if (hasCollapse) { int quantity = UnityLoggerServer.GetLogCount(row); var collapseCount = Mathf.Min(quantity, LogConfiguration.MaxAmountOfLogsCollapse); var collapseText = collapseCount.ToString(); if (collapseCount >= LogConfiguration.MaxAmountOfLogsCollapse) { collapseText += "+"; } var collapseContent = new GUIContent(collapseText); var collapseSize = BluConsoleSkin.CollapseStyle.CalcSize(collapseContent); var collapseRect = new Rect(x: viewWidth - collapseSize.x - 5f, y: (buttonY + buttonY + DefaultButtonHeight - collapseSize.y) * 0.5f, width: collapseSize.x, height: collapseSize.y); GUI.Label(collapseRect, collapseContent, BluConsoleSkin.CollapseStyle); } if (messageClicked) { hasSomeClick = true; if (SelectedMessage != i) { LastTimeClicked = 0.0f; } if (isLeftClick) { BluUtils.PingLog(GetCompleteLog(row)); SelectedMessage = i; } if (!isLeftClick) { DrawPopup(log); } if (isLeftClick && i == SelectedMessage) { if (IsDoubleClick) { LastTimeClicked = 0.0f; var completeLog = GetCompleteLog(row); BluUtils.JumpToSourceFile(completeLog, 0); } else { LastTimeClicked = EditorApplication.timeSinceStartup; } } } buttonY += DefaultButtonHeight; } GUI.EndScrollView(); if (IsScrollUp || hasSomeClick) { IsFollowScroll = false; } else if (ScrollPosition != oldScrollPosition) { IsFollowScroll = false; float topOffset = viewHeight - WindowRect.height; if (ScrollPosition.y >= topOffset) { IsFollowScroll = true; } } if (IsFollowScroll) { ScrollPosition.y = viewHeight - WindowRect.height; } UnityLoggerServer.StopGettingsLogs(); }