/// <summary> /// Logs the command, adding it to the log history and triggers an event /// </summary> /// <param name="command"></param> /// <param name="color"></param> private static void LogCommand(string command, string color) { DebugLogItem item = new DebugLogItem(command, color, Time.frameCount, Time.time, 3, true); LogHistory.Add(item); MMDebugLogEvent.Trigger(new DebugLogItem(null, "", Time.frameCount, Time.time, 0, false)); }
// A log item is clicked, highlight it public void OnLogItemClicked(DebugLogItem item) { if (indexOfSelectedLogEntry != item.Index) { DeselectSelectedLogItem(); indexOfSelectedLogEntry = item.Index; positionOfSelectedLogEntry = item.Index * logItemHeight; heightOfSelectedLogEntry = item.CalculateExpandedHeight(item.ToString()); deltaHeightOfSelectedLogEntry = heightOfSelectedLogEntry - logItemHeight; manager.SetSnapToBottom(false); } else { DeselectSelectedLogItem(); } if (indexOfSelectedLogEntry >= currentTopIndex && indexOfSelectedLogEntry <= currentBottomIndex) { ColorLogItem(logItemsAtIndices[indexOfSelectedLogEntry], indexOfSelectedLogEntry); } CalculateContentHeight(); HardResetItems(); UpdateItemsInTheList(true); manager.ValidateScrollPosition(); }
private void LoadLogItems() { int selectedId = -1; // Save the selected log item.. if (this.LogItemsGrid.SelectedRows.Count != 0) { DebugLogItem selectedItem = this.LogItemsGrid.SelectedRows[0].Tag as DebugLogItem; selectedId = selectedItem.Logid; } // Save sorting state.. DataGridViewColumn sortColumn = this.LogItemsGrid.SortedColumn; SortOrder sortOrder = this.LogItemsGrid.SortOrder; // Filter debug log... List <DebugLogType> allowedTypes = SelectedLogTypes(); var filteredLog = from i in DebugLog.DebugLogItems where allowedTypes.Contains(i.Type) select i; this.LogItemsGrid.Rows.Clear(); foreach (DebugLogItem item in filteredLog) { int index = this.LogItemsGrid.Rows.Add( item.Time, item.Source, item.Type, item.Title); // Reapply selection.. if (item.Logid == selectedId) { this.LogItemsGrid.Rows[index].Selected = true; } // Save the item with the row for use later this.LogItemsGrid.Rows[index].Tag = item; } // Reapply sorting.. if (sortOrder == SortOrder.Ascending) { this.LogItemsGrid.Sort(sortColumn, ListSortDirection.Ascending); } else if (sortOrder == SortOrder.Descending) { this.LogItemsGrid.Sort(sortColumn, ListSortDirection.Descending); } // Select the first log item if none was selected before.. if (selectedId == -1 && this.LogItemsGrid.Rows.Count > 0) { this.LogItemsGrid.Rows[0].Selected = true; } // Reload the selected item LogItemsGrid_SelectionChanged(null, null); }
private void LoadLogItemDetails(DebugLogItem item) { if (item == null) { this.TimeLabel.Text = string.Empty; this.TypeLabel.Text = string.Empty; this.SourceLabel.Text = string.Empty; this.TitleLabel.Text = string.Empty; this.TextDataViewText.Text = string.Empty; this.WebDataBrowser.Navigate(""); return; } // Load the item properties into the details panel this.TimeLabel.Text = item.Time.ToString(); this.TypeLabel.Text = item.Type.ToString(); this.SourceLabel.Text = item.Source; this.TitleLabel.Text = item.Title; this.TextDataViewText.Text = item.Data; // Save the data to a temp file for "XML View" string tempFile = System.IO.Path.Combine( System.IO.Path.GetTempPath(), item.Type == DebugLogType.EwsTrace ? "ewseditordebuglogdata.xml" : "ewseditordebuglogdata.txt"); System.IO.File.WriteAllText(tempFile, item.Data); this.WebDataBrowser.Navigate(tempFile); }
private void LogItemsGrid_SelectionChanged(object sender, EventArgs e) { DebugLogItem item = null; // Make sure there is a selected raow if (this.LogItemsGrid.SelectedRows.Count == 1) { item = this.LogItemsGrid.SelectedRows[0].Tag as DebugLogItem; } LoadLogItemDetails(item); }
// Create (or unpool) a log item private void CreateLogItemAtIndex(int index) { DebugLogItem logItem = debugManager.UnpoolLogItem(); // Reposition the log item logItem.transformComponent.localPosition = new Vector3(1f, -index * logItemHeight, 0f); // Color the log item ColorLogItem(logItem, index); // To access this log item easily in the future, add it to the dictionary logItemsAtIndices[index] = logItem; }
// Color a log item using its index private void ColorLogItem(DebugLogItem logItem, int index) { if (index == indexOfSelectedLogEntry) { logItem.Image.color = logItemSelectedColor; } else if (index % 2 == 0) { logItem.Image.color = logItemNormalColor1; } else { logItem.Image.color = logItemNormalColor2; } }
/// <summary> /// Outputs the message object to the console, prefixed with the current timestamp /// </summary> /// <param name="message">Message.</param> public static void DebugLogTime(object message, string color = "", int timePrecision = 3, bool displayFrameCount = true) { if (!DebugLogsEnabled) { return; } string callerObjectName = new StackTrace().GetFrame(1).GetMethod().ReflectedType.Name; color = (color == "") ? "#00FFFF" : color; // colors string colorPrefix = ""; string colorSuffix = ""; if (!string.IsNullOrEmpty(color)) { colorPrefix = "<color=" + color + ">"; colorSuffix = "</color>"; } // build output string output = ""; if (displayFrameCount) { output += "<color=#82d3f9>[f" + Time.frameCount + "]</color> "; } output += "<color=#f9a682>[" + MMTime.FloatToTimeString(Time.time, false, true, true, true) + "]</color> "; output += callerObjectName + " : "; output += colorPrefix + message + colorSuffix; // we output to the console Debug.Log(output); DebugLogItem item = new DebugLogItem(message, color, Time.frameCount, Time.time, timePrecision, displayFrameCount); // we add to our DebugLog if (LogHistory.Count > _logHistoryMaxLength) { LogHistory.RemoveAt(0); } LogHistory.Add(item); // we trigger an event MMDebugLogEvent.Trigger(item); }
// Create (or unpool) a log item private void CreateLogItemAtIndex(int index) { DebugLogItem logItem = debugManager.PopLogItem(); // Reposition the log item Vector2 anchoredPosition = new Vector2(1f, -index * logItemHeight); if (index > indexOfSelectedLogEntry) { anchoredPosition.y -= deltaHeightOfSelectedLogEntry; } logItem.Transform.anchoredPosition = anchoredPosition; // Color the log item ColorLogItem(logItem, index); // To access this log item easily in the future, add it to the dictionary logItemsAtIndices[index] = logItem; }
static public void Trigger(DebugLogItem item) { OnEvent?.Invoke(item); }
// Pool an unused log item public void PoolLogItem(DebugLogItem logItem) { logItem.gameObject.SetActive(false); pooledLogItems.Add(logItem); }