示例#1
0
        private void    UpdateFilteredRows()
        {
            ConsoleFlags flags = (ConsoleFlags)UnityLogEntries.consoleFlags;

            this.mainStream.collapse       = (flags & ConsoleFlags.Collapse) != 0;
            this.mainStream.displayLog     = (flags & ConsoleFlags.LogLevelLog) != 0;
            this.mainStream.displayWarning = (flags & ConsoleFlags.LogLevelWarning) != 0;
            this.mainStream.displayError   = (flags & ConsoleFlags.LogLevelError) != 0;
            this.mainStream.RefreshFilteredRows();
        }
        private static GUIStyle GetStyleForErrorMode(ConsoleFlags flags, bool isIcon, bool isSmall)
        {
            // Errors
            if (flags == ConsoleFlags.LogLevelError)
            {
                if (isIcon)
                {
                    if (isSmall)
                    {
                        return(Constants.IconErrorSmallStyle);
                    }
                    return(Constants.IconErrorStyle);
                }

                if (isSmall)
                {
                    return(Constants.ErrorSmallStyle);
                }
                return(Constants.ErrorStyle);
            }
            // Warnings
            if (flags == ConsoleFlags.LogLevelWarning)
            {
                if (isIcon)
                {
                    if (isSmall)
                    {
                        return(Constants.IconWarningSmallStyle);
                    }
                    return(Constants.IconWarningStyle);
                }

                if (isSmall)
                {
                    return(Constants.WarningSmallStyle);
                }
                return(Constants.WarningStyle);
            }
            // Logs
            if (isIcon)
            {
                if (isSmall)
                {
                    return(Constants.IconLogSmallStyle);
                }
                return(Constants.IconLogStyle);
            }

            if (isSmall)
            {
                return(Constants.LogSmallStyle);
            }
            return(Constants.LogStyle);
        }
 private static Texture2D GetIconForErrorMode(ConsoleFlags flags, bool large)
 {
     // Errors
     if (flags == ConsoleFlags.LogLevelError)
     {
         return(large ? iconError : iconErrorSmall);
     }
     // Warnings
     if (flags == ConsoleFlags.LogLevelWarning)
     {
         return(large ? iconWarn : iconWarnSmall);
     }
     // Logs
     return(large ? iconInfo : iconInfoSmall);
 }
示例#4
0
 public static void SetFlag(ConsoleFlags flag, bool value)
 {
     try {
         var      logEntries      = System.Type.GetType("UnityEditor.LogEntries, UnityEditor.dll");
         object[] parametersArray = new object[] {
             (int)flag,
             value
         };
         var clearMethod = logEntries.GetMethod("SetConsoleFlag", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
         if (clearMethod != null)
         {
             clearMethod.Invoke(null, parametersArray);
         }
     } catch (System.Exception ex) {
         TouchBar.Log(ex);
     }
 }
示例#5
0
        public static bool GetFlag(ConsoleFlags flag)
        {
            try {
                var logEntries = System.Type.GetType("UnityEditor.LogEntries, UnityEditor.dll");
                //object[] parametersArray = new object[] { (int) flag,
                //          true
                //     };
                //var clearMethod = logEntries.GetMethod("SetConsoleFlag", System.Reflection.BindingFlags.Static | System.Reflection.BindingFlags.Public);
                var clearMethod = logEntries.GetProperty("consoleFlags");
                if (clearMethod != null)
                {
                    int          value = (int)clearMethod.GetValue(null, null);
                    ConsoleFlags flags = (ConsoleFlags)value;
                    bool         show  = ((flags & flag) != 0);

                    return(show);
                }
            } catch (System.Exception ex) {
                TouchBar.Log(ex);
                return(false);
            }
            return(false);
        }
示例#6
0
 private static void SetFlag(ConsoleFlags flags, bool val)
 {
     LogEntries.SetConsoleFlag((int)flags, val);
 }
示例#7
0
 private static bool HasFlag(ConsoleFlags flags)
 {
     return((LogEntries.consoleFlags & (int)flags) != 0);
 }
示例#8
0
文件: WinAPI.cs 项目: FoxCutter/Tools
 static public extern Microsoft.Win32.SafeHandles.SafeFileHandle CreateConsoleScreenBuffer(DesiredAccess DesiredAccess, ShareMode ShareMode, IntPtr SecurityAttributes, ConsoleFlags Flags, IntPtr ScreenBufferData);
        void OnGUI()
        {
            Event e = Event.current;

            LoadIcons();
            LogEntries.wrapped.UpdateEntries();

            if (!m_HasUpdatedGuiStyles)
            {
                m_LineHeight   = Mathf.RoundToInt(Constants.ErrorStyle.lineHeight);
                m_BorderHeight = Constants.ErrorStyle.border.top + Constants.ErrorStyle.border.bottom;
                UpdateListView();
            }

            GUILayout.BeginHorizontal(Constants.Toolbar);

            if (GUILayout.Button(Constants.ClearLabel, Constants.MiniButton))
            {
                LogEntries.Clear();
                GUIUtility.keyboardControl = 0;
            }

            int currCount = LogEntries.wrapped.GetCount();

            if (m_ListView.totalRows != currCount && m_ListView.totalRows > 0)
            {
                // scroll bar was at the bottom?
                if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight)
                {
                    m_ListView.scrollPos.y = currCount * RowHeight - ms_LVHeight;
                }
            }

            if (LogEntries.wrapped.searchFrame)
            {
                LogEntries.wrapped.searchFrame = false;
                int selectedIndex = LogEntries.wrapped.GetSelectedEntryIndex();
                if (selectedIndex != -1)
                {
                    int showIndex = selectedIndex + 1;
                    if (currCount > showIndex)
                    {
                        int showCount = ms_LVHeight / RowHeight;
                        showIndex = showIndex + showCount / 2;
                    }
                    m_ListView.scrollPos.y = showIndex * RowHeight - ms_LVHeight;
                }
            }

            EditorGUILayout.Space();

            bool wasCollapsed = LogEntries.wrapped.collapse;

            LogEntries.wrapped.collapse = GUILayout.Toggle(wasCollapsed, Constants.CollapseLabel, Constants.MiniButton);

            bool collapsedChanged = (wasCollapsed != LogEntries.wrapped.collapse);

            if (collapsedChanged)
            {
                // unselect if collapsed flag changed
                m_ListView.row = -1;

                // scroll to bottom
                m_ListView.scrollPos.y = LogEntries.wrapped.GetCount() * RowHeight;
            }

            SetFlag(ConsoleFlags.ClearOnPlay, GUILayout.Toggle(HasFlag(ConsoleFlags.ClearOnPlay), Constants.ClearOnPlayLabel, Constants.MiniButton));
#if UNITY_2019_1_OR_NEWER
            SetFlag(ConsoleFlags.ClearOnBuild, GUILayout.Toggle(HasFlag(ConsoleFlags.ClearOnBuild), Constants.ClearOnBuildLabel, Constants.MiniButton));
#endif
            SetFlag(ConsoleFlags.ErrorPause, GUILayout.Toggle(HasFlag(ConsoleFlags.ErrorPause), Constants.ErrorPauseLabel, Constants.MiniButton));

#if UNITY_2018_3_OR_NEWER
            ConnectionGUILayout.AttachToPlayerDropdown(m_ConsoleAttachToPlayerState, EditorStyles.toolbarDropDown);
#endif

            EditorGUILayout.Space();

            if (m_DevBuild)
            {
                GUILayout.FlexibleSpace();
                SetFlag(ConsoleFlags.StopForAssert, GUILayout.Toggle(HasFlag(ConsoleFlags.StopForAssert), Constants.StopForAssertLabel, Constants.MiniButton));
                SetFlag(ConsoleFlags.StopForError, GUILayout.Toggle(HasFlag(ConsoleFlags.StopForError), Constants.StopForErrorLabel, Constants.MiniButton));
            }

            GUILayout.FlexibleSpace();

            // Search bar
            GUILayout.Space(4f);
            SearchField(e);

            int errorCount = 0, warningCount = 0, logCount = 0;
            LogEntries.wrapped.GetCountsByType(ref errorCount, ref warningCount, ref logCount);
            EditorGUI.BeginChangeCheck();
            bool setLogFlag     = GUILayout.Toggle(LogEntries.wrapped.HasFlag((int)ConsoleFlags.LogLevelLog), new GUIContent((logCount <= 999 ? logCount.ToString() : "999+"), logCount > 0 ? iconInfoSmall : iconInfoMono), Constants.MiniButton);
            bool setWarningFlag = GUILayout.Toggle(LogEntries.wrapped.HasFlag((int)ConsoleFlags.LogLevelWarning), new GUIContent((warningCount <= 999 ? warningCount.ToString() : "999+"), warningCount > 0 ? iconWarnSmall : iconWarnMono), Constants.MiniButton);
            bool setErrorFlag   = GUILayout.Toggle(LogEntries.wrapped.HasFlag((int)ConsoleFlags.LogLevelError), new GUIContent((errorCount <= 999 ? errorCount.ToString() : "999+"), errorCount > 0 ? iconErrorSmall : iconErrorMono), Constants.MiniButton);
            // Active entry index may no longer be valid
            if (EditorGUI.EndChangeCheck())
            {
            }

            LogEntries.wrapped.SetFlag((int)ConsoleFlags.LogLevelLog, setLogFlag);
            LogEntries.wrapped.SetFlag((int)ConsoleFlags.LogLevelWarning, setWarningFlag);
            LogEntries.wrapped.SetFlag((int)ConsoleFlags.LogLevelError, setErrorFlag);

            if (GUILayout.Button(new GUIContent(errorCount > 0 ? iconFirstErrorSmall : iconFirstErrorMono, Constants.FirstErrorLabel), Constants.MiniButton))
            {
                int firstErrorIndex = LogEntries.wrapped.GetFirstErrorEntryIndex();
                if (firstErrorIndex != -1)
                {
                    SetActiveEntry(firstErrorIndex);
                    LogEntries.wrapped.searchFrame = true;
                }
            }

            GUILayout.EndHorizontal();

            SplitterGUILayout.BeginVerticalSplit(spl);
            int rowHeight = RowHeight;
            EditorGUIUtility.SetIconSize(new Vector2(rowHeight, rowHeight));
            GUIContent tempContent      = new GUIContent();
            int        id               = GUIUtility.GetControlID(0);
            int        rowDoubleClicked = -1;

            /////@TODO: Make Frame selected work with ListViewState
            using (new GettingLogEntriesScope(m_ListView))
            {
                int  selectedRow      = -1;
                bool openSelectedItem = false;
                bool collapsed        = LogEntries.wrapped.collapse;
                foreach (ListViewElement el in ListViewGUI.ListView(m_ListView, Constants.Box))
                {
                    if (e.type == EventType.MouseDown && e.button == 0 && el.position.Contains(e.mousePosition))
                    {
                        m_ListView.row = el.row;
                        selectedRow    = el.row;
                        if (e.clickCount == 2)
                        {
                            openSelectedItem = true;
                        }
                    }
                    else if (e.type == EventType.Repaint)
                    {
                        int    mode           = 0;
                        int    entryCount     = 0;
                        int    searchIndex    = 0;
                        int    searchEndIndex = 0;
                        string text           = LogEntries.wrapped.GetEntryLinesAndFlagAndCount(el.row, ref mode, ref entryCount,
                                                                                                ref searchIndex, ref searchEndIndex);
                        ConsoleFlags flag       = (ConsoleFlags)mode;
                        bool         isSelected = LogEntries.wrapped.IsEntrySelected(el.row);

                        // Draw the background
                        GUIStyle s = el.row % 2 == 0 ? Constants.OddBackground : Constants.EvenBackground;
                        s.Draw(el.position, false, false, isSelected, false);

                        // Draw the icon
#if !UNITY_2017_3_OR_NEWER
                        if (Constants.LogStyleLineCount == 1)
                        {
                            Rect rt = el.position;
                            rt.x     += 6f;
                            rt.y     += 2f;
                            rt.width  = 16f;
                            rt.height = 16f;
                            GUI.DrawTexture(rt, GetIconForErrorMode(flag, false));
                        }
                        else
#endif
                        {
                            GUIStyle iconStyle = GetStyleForErrorMode(flag, true, Constants.LogStyleLineCount == 1);
                            iconStyle.Draw(el.position, false, false, isSelected, false);
                        }

                        // Draw the text
                        tempContent.text = text;
                        GUIStyle errorModeStyle = GetStyleForErrorMode(flag, false, Constants.LogStyleLineCount == 1);

                        if (string.IsNullOrEmpty(LogEntries.wrapped.searchString) || searchIndex == -1 || searchIndex >= text.Length)
                        {
                            errorModeStyle.Draw(el.position, tempContent, id, isSelected);
                        }
                        else
                        {
                            errorModeStyle.DrawWithTextSelection(el.position, tempContent, GUIUtility.keyboardControl, searchIndex, searchEndIndex);
                        }

                        if (collapsed)
                        {
                            Rect badgeRect = el.position;
                            tempContent.text = entryCount.ToString(CultureInfo.InvariantCulture);
                            Vector2 badgeSize = Constants.CountBadge.CalcSize(tempContent);
                            badgeRect.xMin  = badgeRect.xMax - badgeSize.x;
                            badgeRect.yMin += ((badgeRect.yMax - badgeRect.yMin) - badgeSize.y) * 0.5f;
                            badgeRect.x    -= 5f;
                            GUI.Label(badgeRect, tempContent, Constants.CountBadge);
                        }
                    }
                }

                if (selectedRow != -1)
                {
                    if (m_ListView.scrollPos.y >= m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight)
                    {
                        m_ListView.scrollPos.y = m_ListView.rowHeight * m_ListView.totalRows - ms_LVHeight - 1;
                    }
                }

                // Make sure the selected entry is up to date
                if (m_ListView.totalRows == 0 || m_ListView.row >= m_ListView.totalRows || m_ListView.row < 0)
                {
                }
                else
                {
                    if (m_ListView.selectionChanged)
                    {
                        SetActiveEntry(m_ListView.row);
                    }
                }

                // Open entry using return key
                if ((GUIUtility.keyboardControl == m_ListView.ID) && (e.type == EventType.KeyDown) && (e.keyCode == KeyCode.Return) && (m_ListView.row != 0))
                {
                    selectedRow      = m_ListView.row;
                    openSelectedItem = true;
                }

                if (e.type != EventType.Layout && ListViewGUI.ilvState.rectHeight != 1)
                {
                    ms_LVHeight = ListViewGUI.ilvState.rectHeight;
                }

                if (openSelectedItem)
                {
                    rowDoubleClicked = selectedRow;
                    e.Use();
                }

                if (selectedRow != -1)
                {
                    SetActiveEntry(selectedRow);
                }
            }

            // Prevent dead locking in EditorMonoConsole by delaying callbacks (which can log to the console) until after LogEntries.EndGettingEntries() has been
            // called (this releases the mutex in EditorMonoConsole so logging again is allowed). Fix for case 1081060.
            if (rowDoubleClicked != -1)
            {
                LogEntries.wrapped.StacktraceListView_RowGotDoubleClicked();
            }

            EditorGUIUtility.SetIconSize(Vector2.zero);

            StacktraceListView(e, tempContent);

            SplitterGUILayout.EndVerticalSplit();

            // Copy & Paste selected item
            if ((e.type == EventType.ValidateCommand || e.type == EventType.ExecuteCommand) && e.commandName == "Copy")
            {
                if (e.type == EventType.ExecuteCommand)
                {
                    LogEntries.wrapped.StacktraceListView_CopyAll();
                }
                e.Use();
            }
        }
示例#10
0
        private static void Initialize(ConsoleFlags flag, string romName)
        {
            //Do a fast initalize for a legacy read.
            if (flag.Equals(ConsoleFlags.ReadAll) || flag.Equals(ConsoleFlags.Read))
            {
                XPathDocument docNav = new XPathDocument(HTT_XML);
                XPathNavigator nav = docNav.CreateNavigator();
                string strExpression =
                    string.Format("/HiToText/Entry[Header/Games/Name=\"{0}\"]", romName);
                XPathNodeIterator NodeIter = nav.Select(strExpression);
                NodeIter.MoveNext();

                r = new HXMLReader(NodeIter.Current);
            }
            else
            {
                //Load up XML file
#if DEBUG
                r = new HXMLReader(HTT_XML);
#else
                if (File.Exists(HTT_XML))
                    r = new HXMLReader(HTT_XML);
#endif
            }
            supportedGames = r.GetSupportedGames();
        }
示例#11
0
        /// <summary>
        /// Displays the top menus.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        private Rect    DrawHeader(Rect r)
        {
            GeneralSettings settings = HQ.Settings.Get <GeneralSettings>();
            float           width    = r.width;

            // Draw Unity native features. This way is better because using style Toolbar in BeginHorizontal creates an unwanted left margin.
            GUI.Box(r, GUIContent.none, settings.ToolbarStyle);

            if (string.IsNullOrEmpty(settings.clearLabel) == false)
            {
                Utility.content.text    = settings.clearLabel;
                Utility.content.tooltip = Utility.content.text != "Clear" ? "Clear" : string.Empty;
                r.width = settings.MenuButtonStyle.CalcSize(Utility.content).x;
                if (GUI.Button(r, Utility.content, settings.MenuButtonStyle) == true)
                {
                    this.Clear();
                }
                r.x += r.width + 5F;
            }

            EditorGUI.BeginChangeCheck();

            ConsoleFlags flags = (ConsoleFlags)UnityLogEntries.consoleFlags;

            if (string.IsNullOrEmpty(settings.collapseLabel) == false)
            {
                Utility.content.text    = settings.collapseLabel;
                Utility.content.tooltip = Utility.content.text != "Collapse" ? "Collapse" : string.Empty;
                r.width       = settings.MenuButtonStyle.CalcSize(Utility.content).x;
                this.collapse = GUI.Toggle(r, (flags & ConsoleFlags.Collapse) != 0, Utility.content, settings.MenuButtonStyle);
                r.x          += r.width;
            }

            if (string.IsNullOrEmpty(settings.clearOnPlayLabel) == false)
            {
                Utility.content.text    = settings.clearOnPlayLabel;
                Utility.content.tooltip = Utility.content.text != "Clear on Play" ? "Clear on Play" : string.Empty;
                r.width          = settings.MenuButtonStyle.CalcSize(Utility.content).x;
                this.clearOnPlay = GUI.Toggle(r, (flags & ConsoleFlags.ClearOnPlay) != 0, Utility.content, settings.MenuButtonStyle);
                r.x += r.width;
            }

            if (string.IsNullOrEmpty(settings.errorPauseLabel) == false)
            {
                Utility.content.text    = settings.errorPauseLabel;
                Utility.content.tooltip = Utility.content.text != "Error Pause" ? "Error Pause" : string.Empty;
                r.width           = settings.MenuButtonStyle.CalcSize(Utility.content).x;
                this.breakOnError = GUI.Toggle(r, (flags & ConsoleFlags.ErrorPause) != 0, Utility.content, settings.MenuButtonStyle);
                r.x += r.width;
            }

            Utility.content.tooltip = string.Empty;

            if (EditorGUI.EndChangeCheck() == true)
            {
                UnityLogEntries.SetConsoleFlag((int)ConsoleFlags.Collapse, this.collapse);
                UnityLogEntries.SetConsoleFlag((int)ConsoleFlags.ClearOnPlay, this.clearOnPlay);
                UnityLogEntries.SetConsoleFlag((int)ConsoleFlags.ErrorPause, this.breakOnError);

                if (this.OptionAltered != null)
                {
                    this.OptionAltered();
                }

                Utility.RepaintConsoleWindow();
            }

            try
            {
                if (this.AfterGUIHeaderLeftMenu != null)
                {
                    this.AfterGUIHeaderLeftMenu();
                }
            }
            catch (Exception ex)
            {
                this.errorPopup.exception = ex;
            }

            r.x += 5F;

            // Draw tabs menu.
            if (this.visibleModules.Length > 1)
            {
                for (int i = 0; i < this.visibleModules.Length; i++)
                {
                    r = this.visibleModules[i].DrawMenu(r, this.workingModuleId);
                }
            }

            r.x    += 5F;
            r.width = width - r.x;
            r.xMax += autoPaddingRightHeaderMenu;

            try
            {
                if (this.AfterGUIHeaderRightMenu != null)
                {
                    r = this.AfterGUIHeaderRightMenu.Invoke(r);
                }
            }
            catch (Exception ex)
            {
                this.errorPopup.exception = ex;
            }

            // Display right menus.
            try
            {
                if (this.BeforeGUIHeaderRightMenu != null)
                {
                    r = this.BeforeGUIHeaderRightMenu.Invoke(r);
                }
            }
            catch (Exception ex)
            {
                this.errorPopup.exception = ex;
            }

            if (r.width < 0F)
            {
                autoPaddingRightHeaderMenu += -r.width;
            }
            else if (r.width > 0F)
            {
                if (autoPaddingRightHeaderMenu > 0F)
                {
                    this.Repaint();
                    autoPaddingRightHeaderMenu -= 1F;
                    if (autoPaddingRightHeaderMenu < 0F)
                    {
                        autoPaddingRightHeaderMenu = 0F;
                    }
                }
            }

            r.y += settings.menuHeight;

            if (this.errorPopup.exception != null)
            {
                r.x      = 0F;
                r.width  = width;
                r.height = this.errorPopup.boxHeight;
                this.errorPopup.OnGUIRect(r);

                r.y += r.height;
            }

            return(r);
        }
示例#12
0
 private void SetFlag(ConsoleFlags flags, bool val)
 {
     LogEntries.SetConsoleFlag((int) flags, val);
 }
示例#13
0
 private bool HasFlag(ConsoleFlags flags)
 {
     return ((LogEntries.consoleFlags & flags) != 0);
 }
示例#14
0
        /// <summary>
        /// Console ウィンドウの設定のオン・オフを変更します
        /// </summary>
        public static void SetConsoleFlag(ConsoleFlags bit, bool value)
        {
            var methodInfo = ms_type.GetMethod(nameof(SetConsoleFlag), BINDING_ATTR);

            methodInfo.Invoke(null, new object[] { ( int )bit, value });
        }
示例#15
0
 private bool HasFlag(ConsoleFlags flags)
 {
     return((LogEntries.consoleFlags & flags) != 0);
 }