private void DrawLogs() { m_LogScrollPosition = EditorGUILayout.BeginScrollView(m_LogScrollPosition, EditorStyles.textArea); { for (int i = 0; i < m_Log.entries.Count; i++) { Log.Entry entry = m_Log.entries[i]; if (m_Styles == null) { m_Styles = new Styles(); } Rect position = GUILayoutUtility.GetRect(m_Styles.Content(entry.message), m_Styles.zebraStyle); // Input int controlID = GUIUtility.GetControlID(321324, FocusType.Keyboard, position); Event current = Event.current; EventType eventType = current.GetTypeForControl(controlID); if (eventType == EventType.MouseDown && position.Contains(current.mousePosition)) { if (current.clickCount == 2) { InternalEditorUtility.OpenFileAtLineExternal(entry.fileName, entry.lineNumber); } GUIUtility.keyboardControl = controlID; m_SelectedLogIndex = i; current.Use(); GUI.changed = true; } if (current.type == EventType.KeyDown) { if (current.keyCode == KeyCode.UpArrow && m_SelectedLogIndex > 0) { m_SelectedLogIndex--; current.Use(); } if (current.keyCode == KeyCode.DownArrow && m_SelectedLogIndex < m_Log.entries.Count - 1) { m_SelectedLogIndex++; current.Use(); } } if (eventType == EventType.Repaint) { bool isHover = entry.id % 2 == 0; bool isActive = false; bool isOn = true; bool hasKeyboardFocus = m_SelectedLogIndex == i; m_Styles.zebraStyle.Draw(position, m_Styles.Content(entry.message), isHover, isActive, isOn, hasKeyboardFocus); } } GUILayout.FlexibleSpace(); if (m_SelectedLogIndex < 0 || m_SelectedLogIndex >= m_Log.entries.Count) { // If we go out of bounds we zero out our selection m_SelectedLogIndex = -1; } } EditorGUILayout.EndScrollView(); }
private void DrawLogs() { m_LogScrollPosition = EditorGUILayout.BeginScrollView(m_LogScrollPosition, EditorStyles.textArea); { for (int i = 0; i < m_Entries.arraySize; i++) { SerializedProperty entry = m_Entries.GetArrayElementAtIndex(i); if (m_Styles == null) { m_Styles = new Styles(); } SerializedProperty message = entry.FindPropertyRelative("message"); SerializedProperty id = entry.FindPropertyRelative("id"); Rect position = GUILayoutUtility.GetRect(m_Styles.Content(message.stringValue), m_Styles.zebraStyle); // Input int controlID = GUIUtility.GetControlID(321324, FocusType.Keyboard, position); Event current = Event.current; EventType eventType = current.GetTypeForControl(controlID); if (eventType == EventType.MouseDown && position.Contains(current.mousePosition)) { if (current.clickCount == 2) { SerializedProperty fileName = entry.FindPropertyRelative("fileName"); SerializedProperty lineNumber = entry.FindPropertyRelative("lineNumber"); InternalEditorUtility.OpenFileAtLineExternal(fileName.stringValue, lineNumber.intValue); } GUIUtility.keyboardControl = controlID; m_SelectedLogIndex = i; current.Use(); GUI.changed = true; } if (current.type == EventType.KeyDown) { if (current.keyCode == KeyCode.UpArrow && m_SelectedLogIndex > 0) { m_SelectedLogIndex--; current.Use(); } if (current.keyCode == KeyCode.DownArrow && m_SelectedLogIndex < m_Entries.arraySize - 1) { m_SelectedLogIndex++; current.Use(); } } if (eventType == EventType.Repaint) { bool isHover = id.intValue % 2 == 0; bool isActive = false; bool isOn = true; bool hasKeyboardFocus = m_SelectedLogIndex == i; m_Styles.zebraStyle.Draw(position, m_Styles.Content(message.stringValue), isHover, isActive, isOn, hasKeyboardFocus); } } GUILayout.FlexibleSpace(); if (m_SelectedLogIndex < 0 || m_SelectedLogIndex >= m_Entries.arraySize) { // If we go out of bounds we zero out our selection m_SelectedLogIndex = -1; } } EditorGUILayout.EndScrollView(); }