/// <summary> /// Renders the entries. /// </summary> private void DrawEntries() { var rect = new Rect(this.headerWidth, 0.0f, 0.0f, this.entryRowHeight); foreach (var sourceName in TimelineLog.Sources.Keys.OfType <string>().OrderBy(s => s)) { var source = TimelineLog.Sources[sourceName] as TimelineLogSource; if (source.IsFolded) { continue; } GUI.color = this.bgColor1; var columnWidth = 100.0f; var width = Mathf.Max(this.canvasWidth, this.position.width); var count = width / columnWidth; for (var index = 0; index < count; index++) { var timeRect = new Rect(index * columnWidth, rect.y, 1.0f, this.rowHeight); EditorGUIEx.DrawRectangle(timeRect, this.bgColor1); timeRect.x += 2.0f; timeRect.width = columnWidth; GUI.Label(timeRect, ((index * columnWidth) / this.timeScale) + "s"); } rect.y += this.rowHeight + (this.rowHeight - this.entryRowHeight) * 0.5f; GUI.color = Color.white; foreach (var categoryName in source.Categories.Keys.OfType <string>().OrderBy(s => s)) { var entries = source.Categories[categoryName] as LinkedList <TimelineLogEntry>; foreach (var entry in entries) { var delta = entry.End - entry.Start; var content = new GUIContent( entry.Message, entry.Message + Environment.NewLine + "Start: " + entry.Start + "s" + Environment.NewLine + "End: " + entry.End + "s" + Environment.NewLine + "Delta: " + delta + "s" ); rect.x = entry.Start * this.timeScale; rect.width = this.entryStyle.fixedWidth = Mathf.Max(delta * this.timeScale, this.minEntryWidth) ; EditorGUIEx.DrawRectangle(rect, entry.Color); GUI.color = Color.white; GUI.Label(rect, content, this.entryStyle); } rect.y += this.rowHeight; } } }
/// <summary> /// Draws the editable property. /// </summary> /// <param name="position"> /// Rectangle on the screen to use for the property GUI. /// </param> /// <param name="property"> /// The SerializedProperty to make the custom GUI for. /// </param> /// <param name="label"> /// The label of this property. /// </param> public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { position.height = cls.height; using (new EditorGUI.PropertyScope(position, label, property)) { var input = string.Empty; var hasChange = EditorGUIEx.ChangeCheck(() => { input = EditorGUI.TextArea(position, property.stringValue, this.style); }); if (hasChange) { property.stringValue = input; } } }
/// <summary> /// Renders the background of the timeline. /// </summary> private void DrawBackground() { var rect = new Rect(0.0f, 0.0f, this.position.width - this.scrollbarWidth, this.rowHeight); foreach (var sourceName in TimelineLog.Sources.Keys.OfType <string>().OrderBy(s => s)) { // nothing to output here, but still increment y-axis rect.y += this.rowHeight; var source = TimelineLog.Sources[sourceName] as TimelineLogSource; if (source.IsFolded) { continue; } for (var index = 0; index < source.Categories.Count; index++) { var color = (rect.y % (this.rowHeight * 2.0f)) == 0.0f ? this.bgColor1 : this.bgColor2; EditorGUIEx.DrawRectangle(rect, color); rect.y += this.rowHeight; } } GUI.color = Color.white; }