Example #1
0
 private static void ExecuteAction(InspectorLog.LogItem item)
 {
     item.Execute();
 }
Example #2
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (logEntryStyle == null)
            {
                logEntryStyle = new GUIStyle(EditorStyles.helpBox)
                {
                    clipping = TextClipping.Clip,
                    wordWrap = false
                };

                logTextStyle = new GUIStyle
                {
                    wordWrap  = false,
                    clipping  = TextClipping.Clip,
                    font      = logEntryStyle.font,
                    fontSize  = logEntryStyle.fontSize,
                    fontStyle = logEntryStyle.fontStyle
                };
                logTextStyle.normal.textColor = logEntryStyle.normal.textColor;
                logTextStyle.contentOffset    = logEntryStyle.contentOffset;
                logTextStyle.padding          = logEntryStyle.padding;
                logTextStyle.richText         = true;

                elipsisStyle = new GUIStyle(logTextStyle);
                elipsisStyle.padding.left  = 0;
                elipsisStyle.contentOffset = new Vector2(0, elipsisStyle.contentOffset.y);

                DebugIcon   = EditorGUIUtility.IconContent("IN-AddComponentRight", "").image;
                InfoIcon    = EditorGUIUtility.IconContent("console.infoicon.sml", "").image;
                WarningIcon = EditorGUIUtility.IconContent("console.warnicon.sml", "").image;
                ErrorIcon   = EditorGUIUtility.IconContent("console.erroricon.sml", "").image;
                ConsoleIcon = EditorGUIUtility.IconContent("UnityEditor.ConsoleWindow", "").image;
                SendIcon    = EditorGUIUtility.IconContent("CollabPush", "").image;
                ReceiveIcon = EditorGUIUtility.IconContent("CollabPull", "").image;
            }
            if (position != lastPosition || logSize != lastLogSize)
            {
                RecalculateRects(position, logSize);
            }

            label = new GUIContent(label.text, ConsoleIcon, label.tooltip);

            Rect headerRect = new Rect(lastPosition.x, lastPosition.y, lastPosition.width, EditorGUIUtility.singleLineHeight);

            if (log.Expandable)
            {
                EditorGUI.BeginChangeCheck();
                property.isExpanded = EditorGUI.Foldout(headerRect, property.isExpanded, label, true);
                if (EditorGUI.EndChangeCheck())
                {
                    EditorUtility.SetDirty(property.serializedObject.targetObject);
                }

                if (!property.isExpanded)
                {
                    return;
                }
            }
            else
            {
                EditorGUI.LabelField(rect_header, label);
            }

            int logItemsCount = log.Count;
            int scrollMax     = logItemsCount - logSize;

            Event currentEvent = Event.current;

            if (logItemsCount > logSize)
            {
                float handleSize = Mathf.Max(3 / Mathf.Sqrt(logItemsCount - logSize), 0.075f);

                if (scroll == -1)
                {
                    scroll = scrollMax;
                }

                scroll      += scrollBuffer;
                scrollBuffer = 0;

                if (currentEvent.rawType == EventType.ScrollWheel && rect_content.Contains(currentEvent.mousePosition))
                {
                    if ((Math.Abs(scroll - 1.0f) < 0.01f && currentEvent.delta.y > 0) ||
                        (Math.Abs(scroll) < 0.01f && currentEvent.delta.y < 0))
                    {
                        // Let us scroll normally, optionally we can interupt the scrolling
                        currentEvent.Use();
                    }
                    else
                    {
                        scroll += Mathf.RoundToInt(currentEvent.delta.y);
                        currentEvent.Use();
                    }
                }

                float smallScroll = GUI.VerticalScrollbar(rect_scrollbar, (float)scroll / (float)scrollMax, handleSize, 0.0f, 1.0f + handleSize);
                scroll = Mathf.RoundToInt(smallScroll * scrollMax);
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                GUI.VerticalScrollbar(rect_scrollbar, scroll, 1.0f, 0.0f, 1.0f);
                EditorGUI.EndDisabledGroup();

                scroll = logItemsCount;
            }

            if (logItemsCount != 0)
            {
                int scrollOffset = scroll;
                if (logItemsCount <= logSize)
                {
                    scrollOffset = 0;
                }

                int offset = Mathf.RoundToInt(scrollOffset);

                if (currentEvent.type == EventType.MouseDown)
                {
                    if (rect_content.Contains(currentEvent.mousePosition))
                    {
                        float posInContent = Mathf.InverseLerp(rect_content.yMin, rect_content.yMax, currentEvent.mousePosition.y);

                        int clickedIndex = Mathf.FloorToInt(posInContent * logSize);
                        int logIndex     = clickedIndex + offset;

                        if (currentEvent.clickCount == 2)
                        {
                            InspectorLog.LogItem item = log.FullLog[logIndex];
#if OPEN_SCRIPT
                            ExecuteAction(item);
#endif

                            selectedEntry = logIndex;
                        }
                        else
                        {
                            selectedEntry = logIndex;
                        }

                        EditorUtility.SetDirty(property.serializedObject.targetObject);
                        currentEvent.Use();
                    }
                    else
                    {
                    }
                }
                if (currentEvent.type == EventType.KeyDown)
                {
                    if (currentEvent.keyCode == KeyCode.DownArrow)
                    {
                        if (selectedEntry != logItemsCount - 1)
                        {
                            selectedEntry++;
                        }

                        if (selectedEntry >= scroll + logSize)
                        {
                            scroll = selectedEntry - logSize + 1;
                        }
                        else if (selectedEntry < scroll)
                        {
                            scroll = selectedEntry;
                        }

                        EditorUtility.SetDirty(property.serializedObject.targetObject);
                        currentEvent.Use();
                    }
                    else if (currentEvent.keyCode == KeyCode.UpArrow)
                    {
                        if (selectedEntry != 0)
                        {
                            selectedEntry--;
                        }

                        if (selectedEntry >= scroll + logSize)
                        {
                            scroll = selectedEntry - logSize + 1;
                        }
                        else if (selectedEntry < scroll)
                        {
                            scroll = selectedEntry;
                        }

                        EditorUtility.SetDirty(property.serializedObject.targetObject);
                        currentEvent.Use();
                    }
                }
                else if (currentEvent.type == EventType.Repaint)
                {
                    Color originalColour = GUI.color;
                    GUI.Box(rect_content, "", EditorStyles.helpBox);

                    for (int i = 0; i < rect_logContents.Length; i++)
                    {
                        int index = i + offset;

                        if (index < 0)
                        {
                            continue;
                        }

                        if (index >= logItemsCount)
                        {
                            break;
                        }

                        Rect logRect = rect_logContents[i];
                        InspectorLog.LogItem item = log.FullLog[index];

                        if (selectedEntry == index)
                        {
                            GUI.color = new Color(0.25f, 0.45f, 1.0f, 1.0f);
                        }
                        else if (index % 2 == 0)
                        {
                            GUI.color = new Color(0.8f, 0.8f, 0.8f, 1.0f);
                        }
                        else
                        {
                            GUI.color = new Color(0.7f, 0.7f, 0.7f, 1.0f);
                        }

                        string content;
                        if (log.ShowIndex)
                        {
                            content = index.ToString() + ": " + item.content;
                        }
                        else
                        {
                            content = item.content;
                        }

                        logEntryStyle.Draw(logRect, false, false, false, false);

                        Texture icon = null;
                        switch (item.category)
                        {
                        case InspectorLog.LogCategory.Debug:
                            icon = DebugIcon;
                            break;

                        case InspectorLog.LogCategory.Info:
                            icon = InfoIcon;
                            break;

                        case InspectorLog.LogCategory.Warning:
                            icon = WarningIcon;
                            break;

                        case InspectorLog.LogCategory.Error:
                            icon = ErrorIcon;
                            break;

                        case InspectorLog.LogCategory.Send:
                            icon = SendIcon;
                            break;

                        case InspectorLog.LogCategory.Receive:
                            icon = ReceiveIcon;
                            break;
                        }

                        TextCroppingField(logRect, new GUIContent(content, icon));
                    }

                    GUI.color = originalColour;
                }
            }
            else
            {
                GUI.Box(rect_content, "Empty", EditorStyles.helpBox);
            }
        }
Example #3
0
        private void DrawElement(int index, InspectorLog.LogItem item, Rect logRect)
        {
            if (Event.current.type == EventType.Repaint)
            {
                var originalColor = GUI.color;
                if (SelectedIndex == index)
                {
                    GUI.color = new Color(0.25f, 0.45f, 1.0f, 1.0f);
                }
                else
                if (index % 2 == 0)
                {
                    GUI.color = new Color(0.8f, 0.8f, 0.8f, 1.0f);
                }
                else
                {
                    GUI.color = new Color(0.7f, 0.7f, 0.7f, 1.0f);
                }

                string content;
                if (log.ShowIndex)
                {
                    content = index.ToString() + ": " + item.content;
                }
                else
                {
                    content = item.content;
                }

                logEntryStyle.Draw(logRect, false, false, false, false);

                Texture icon = null;
                switch (item.category)
                {
                case InspectorLog.LogCategory.Debug:
                    icon = DebugIcon;
                    break;

                case InspectorLog.LogCategory.Info:
                    icon = InfoIcon;
                    break;

                case InspectorLog.LogCategory.Warning:
                    icon = WarningIcon;
                    break;

                case InspectorLog.LogCategory.Error:
                    icon = ErrorIcon;
                    break;

                case InspectorLog.LogCategory.Send:
                    icon = SendIcon;
                    break;

                case InspectorLog.LogCategory.Receive:
                    icon = ReceiveIcon;
                    break;
                }

                TextCroppingField(logRect, new GUIContent(content, icon));
                GUI.color = originalColor;
            }
            else if (Event.current.type == EventType.MouseDown)
            {
                if (logRect.Contains(Event.current.mousePosition))
                {
                    SelectedIndex = index;
                    if (Event.current.clickCount == 2)
                    {
#if OPEN_SCRIPT
                        ExecuteAction(item);
#endif
                    }
                    Event.current.Use();
                }
            }
        }
Example #4
0
        public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
        {
            if (position != lastPosition || logSize != lastLogSize)
            {
                RecalculateRects(position, logSize);
            }

            Rect headerRect = new Rect(lastPosition.x, lastPosition.y, lastPosition.width, EditorGUIUtility.singleLineHeight);

            if (log.Expandable)
            {
                property.isExpanded = EditorGUI.Foldout(headerRect, property.isExpanded, label, true);
                if (!property.isExpanded)
                {
                    return;
                }
            }
            else
            {
                EditorGUI.LabelField(rect_header, label);
            }

            int logItemsCount = log.Count;
            int scrollMax     = logItemsCount - logSize;

            Event currentEvent = Event.current;

            if (logItemsCount > logSize)
            {
                float handleSize = Mathf.Max(1 / Mathf.Sqrt(logItemsCount - logSize), 0.075f);

                if (scroll == -1)
                {
                    scroll = scrollMax;
                }

                scroll      += scrollBuffer;
                scrollBuffer = 0;

                if (currentEvent.rawType == EventType.ScrollWheel && rect_content.Contains(currentEvent.mousePosition))
                {
                    if ((scroll == 1.0f && currentEvent.delta.y > 0) ||
                        (scroll == 0.0f && currentEvent.delta.y < 0))
                    {
                        // Let us scroll normally, optionally we can interupt the scrolling
                        currentEvent.Use();
                    }
                    else
                    {
                        scroll += Mathf.RoundToInt(currentEvent.delta.y);
                        currentEvent.Use();
                    }
                }

                float smallScroll = GUI.VerticalScrollbar(rect_scrollbar, (float)scroll / (float)scrollMax, handleSize, 0.0f, 1.0f + handleSize);
                scroll = Mathf.RoundToInt(smallScroll * scrollMax);
            }
            else
            {
                EditorGUI.BeginDisabledGroup(true);
                GUI.VerticalScrollbar(rect_scrollbar, scroll, 1.0f, 0.0f, 1.0f);
                EditorGUI.EndDisabledGroup();

                scroll = logItemsCount;
            }

            if (logItemsCount != 0)
            {
                int scrollOffset = scroll;
                if (logItemsCount <= logSize)
                {
                    scrollOffset = 0;
                }

                int offset = Mathf.RoundToInt(scrollOffset);

                if (currentEvent.type == EventType.MouseDown)
                {
                    if (rect_content.Contains(currentEvent.mousePosition))
                    {
                        float posInContent = Mathf.InverseLerp(rect_content.yMin, rect_content.yMax, currentEvent.mousePosition.y);

                        int clickedIndex = Mathf.FloorToInt(posInContent * logSize);
                        int logIndex     = clickedIndex + offset;

                        if (currentEvent.clickCount == 2)
                        {
                            InspectorLog.LogItem item = log.FullLog[logIndex];
                            ExecuteAction(item);

                            selectedEntry = logIndex;
                        }
                        else
                        {
                            selectedEntry = logIndex;
                        }

                        EditorUtility.SetDirty(property.serializedObject.targetObject);
                        currentEvent.Use();
                    }
                }
                else if (currentEvent.type == EventType.Repaint)
                {
                    Color originalColour = GUI.color;
                    GUI.Box(rect_content, "", EditorStyles.helpBox);

                    for (int i = 0; i < rect_logContents.Length; i++)
                    {
                        int index = i + offset;

                        if (index < 0)
                        {
                            continue;
                        }

                        if (index >= logItemsCount)
                        {
                            break;
                        }

                        Rect logRect = rect_logContents[i];
                        InspectorLog.LogItem item = log.FullLog[index];

                        if (selectedEntry == index)
                        {
                            GUI.color = new Color(0.25f, 0.45f, 1.0f, 1.0f);
                        }
                        else if (index % 2 == 0)
                        {
                            GUI.color = new Color(0.8f, 0.8f, 0.8f, 1.0f);
                        }
                        else
                        {
                            GUI.color = new Color(0.7f, 0.7f, 0.7f, 1.0f);
                        }

                        if (log.ShowIndex)
                        {
                            EditorStyles.helpBox.Draw(logRect, index.ToString() + ": " + item.content, false, false, false, false);
                        }
                        else
                        {
                            EditorStyles.helpBox.Draw(logRect, item.content, false, false, false, false);
                        }
                    }

                    GUI.color = originalColour;
                }
            }
            else
            {
                GUI.Box(rect_content, "Empty", EditorStyles.helpBox);
            }
        }