Example #1
0
        private void Awake()
        {
            // Only one instance of debug console is allowed
            if (instance == null)
            {
                instance = this;

                // If it is a singleton object, don't destroy it between scene changes
                if (singleton)
                {
                    DontDestroyOnLoad(gameObject);
                }
            }
            else if (this != instance)
            {
                Destroy(gameObject);
                return;
            }

            pooledLogEntries = new List <DebugLogEntry>(16);
            pooledLogItems   = new List <DebugLogItem>(16);
            queuedLogEntries = new DynamicCircularBuffer <QueuedDebugLogEntry>(16);
            commandHistory   = new CircularBuffer <string>(commandHistorySize);

            logEntriesLock = new object();

            canvasTR = (RectTransform)transform;

            // Associate sprites with log types
            logSpriteRepresentations = new Dictionary <LogType, Sprite>
            {
                { LogType.Log, infoLog },
                { LogType.Warning, warningLog },
                { LogType.Error, errorLog },
                { LogType.Exception, errorLog },
                { LogType.Assert, errorLog }
            };

            // Initially, all log types are visible
            filterInfoButton.color    = filterButtonsSelectedColor;
            filterWarningButton.color = filterButtonsSelectedColor;
            filterErrorButton.color   = filterButtonsSelectedColor;

            collapsedLogEntries          = new List <DebugLogEntry>(128);
            collapsedLogEntriesMap       = new Dictionary <DebugLogEntry, int>(128);
            uncollapsedLogEntriesIndices = new DebugLogIndexList();
            indicesOfListEntriesToShow   = new DebugLogIndexList();

            recycledListView.Initialize(this, collapsedLogEntries, indicesOfListEntriesToShow, logItemPrefab.Transform.sizeDelta.y);
            recycledListView.UpdateItemsInTheList(true);

            if (minimumHeight < 200f)
            {
                minimumHeight = 200f;
            }

            nullPointerEventData = new PointerEventData(null);
        }
Example #2
0
        private void Awake()
        {
#if UNITY_EDITOR
            //在scene界面不让选中
            if (LayerMask.NameToLayer("SceneLocked") == -1)
            {
                var tagManager =
                    new UnityEditor.SerializedObject(
                        UnityEditor.AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/TagManager.asset")[0]);
                UnityEditor.SerializedProperty it = tagManager.GetIterator();
                bool showChildren = true;
                int  index        = 0;
                bool isLayer      = false;
                while (it.NextVisible(showChildren))
                {
//set your tags here
                    if (it.name == "data")
                    {
                        if (it.stringValue == "UI")
                        {
                            isLayer = true;
                        }
                        if (isLayer)
                        {
                            index++;
                        }
                        if (string.IsNullOrEmpty(it.stringValue) && index > 10)
                        {
                            it.stringValue = "SceneLocked";
                            break;
                        }
                    }
                }
                tagManager.ApplyModifiedProperties();
            }
            gameObject.layer = LayerMask.NameToLayer("SceneLocked");
            UnityEditor.Tools.lockedLayers |= 1 << LayerMask.NameToLayer("SceneLocked");
#endif

            Application.logMessageReceivedThreaded += ReceivedLog;

            // Only one instance of debug console is allowed
            if (!Instance)
            {
                Instance = this;

                // If it is a singleton object, don't destroy it between scene changes
                if (singleton)
                {
                    DontDestroyOnLoad(gameObject);
                }
            }
            else if (Instance != this)
            {
                Destroy(gameObject);
                return;
            }
            //gameObject.hideFlags = HideFlags.HideInHierarchy | HideFlags.HideInInspector;
            pooledLogEntries = new List <DebugLogEntry>(16);
            pooledLogItems   = new List <DebugLogItem>(16);
            queuedLogEntries = new DynamicCircularBuffer <QueuedDebugLogEntry>(16);

            logEntriesLock = new object();

            canvasTR                       = (RectTransform)transform;
            logItemsScrollRectTR           = (RectTransform)logItemsScrollRect.transform;
            logItemsScrollRectOriginalSize = logItemsScrollRectTR.sizeDelta;

            // Associate sprites with log types
            logSpriteRepresentations = new Dictionary <LogType, Sprite>()
            {
                { LogType.Log, infoLog },
                { LogType.Warning, warningLog },
                { LogType.Error, errorLog },
                { LogType.Exception, errorLog },
                { LogType.Assert, errorLog }
            };

            // Initially, all log types are visible
            filterInfoButton.color    = filterButtonsSelectedColor;
            filterWarningButton.color = filterButtonsSelectedColor;
            filterErrorButton.color   = filterButtonsSelectedColor;

            collapsedLogEntries          = new List <DebugLogEntry>(128);
            collapsedLogEntriesMap       = new Dictionary <DebugLogEntry, int>(128);
            uncollapsedLogEntriesIndices = new DebugLogIndexList();
            indicesOfListEntriesToShow   = new DebugLogIndexList();

            recycledListView.Initialize(this, collapsedLogEntries, indicesOfListEntriesToShow, logItemPrefab.Transform.sizeDelta.y);
            recycledListView.UpdateItemsInTheList(true);

            if (minimumHeight < 200f)
            {
                minimumHeight = 200f;
            }

            if (enableSearchbar)
            {
                searchbar.GetComponent <InputField>().onValueChanged.AddListener(SearchTermChanged);
            }
            else
            {
                searchbar = null;
                searchbarSlotTop.gameObject.SetActive(false);
                searchbarSlotBottom.gameObject.SetActive(false);
            }

            hideButton.onClick.AddListener(HideLogWindow);
            clearButton.onClick.AddListener(ClearLogs);
            collapseButton.GetComponent <Button>().onClick.AddListener(CollapseButtonPressed);
            filterInfoButton.GetComponent <Button>().onClick.AddListener(FilterLogButtonPressed);
            filterWarningButton.GetComponent <Button>().onClick.AddListener(FilterWarningButtonPressed);
            filterErrorButton.GetComponent <Button>().onClick.AddListener(FilterErrorButtonPressed);
            snapToBottomButton.GetComponent <Button>().onClick.AddListener(() => SetSnapToBottom(true));
            showCommandBtn.onClick.AddListener(() => commandParent.gameObject.SetActive(!commandParent.gameObject.activeSelf));

            nullPointerEventData = new PointerEventData(null);
            commandBtnTemplate.gameObject.SetActive(false);
            foreach (var method in DebugLogConsole.Methods)
            {
                RefreshMethodButtons(NotifyCollectionChangedAction.Add, method);
            }
            DebugLogConsole.OnCommandChanged += RefreshMethodButtons;
        }
        private void OnEnable()
        {
            // Only one instance of debug console is allowed
            if (instance == null)
            {
                instance       = this;
                pooledLogItems = new List <DebugLogItem>();

                canvasTR = (RectTransform)transform;

                // Associate sprites with log types
                logSpriteRepresentations = new Dictionary <LogType, Sprite>
                {
                    { LogType.Log, infoLog },
                    { LogType.Warning, warningLog },
                    { LogType.Error, errorLog },
                    { LogType.Exception, errorLog },
                    { LogType.Assert, errorLog }
                };
                inputCommandHistory = new LinkedList <string>();

                // Initially, all log types are visible
                filterInfoButton.color    = filterButtonsSelectedColor;
                filterWarningButton.color = filterButtonsSelectedColor;
                filterErrorButton.color   = filterButtonsSelectedColor;

                collapsedLogEntries          = new List <DebugLogEntry>(128);
                collapsedLogEntriesMap       = new Dictionary <DebugLogEntry, int>(128);
                uncollapsedLogEntriesIndices = new DebugLogIndexList();
                indicesOfListEntriesToShow   = new DebugLogIndexList();

                recycledListView.Initialize(this, collapsedLogEntries, indicesOfListEntriesToShow, logItemPrefab.Transform.sizeDelta.y);
                recycledListView.UpdateItemsInTheList(true);

                nullPointerEventData = new PointerEventData(null);

                // If it is a singleton object, don't destroy it between scene changes
                if (singleton)
                {
                    DontDestroyOnLoad(gameObject);
                }
            }
            else if (this != instance)
            {
                Destroy(gameObject);
                return;
            }

            // Intercept debug entries
            Application.logMessageReceived -= ReceivedLog;
            Application.logMessageReceived += ReceivedLog;

            if (receiveLogcatLogsInAndroid)
            {
#if !UNITY_EDITOR && UNITY_ANDROID
                if (logcatListener == null)
                {
                    logcatListener = new DebugLogLogcatListener();
                }

                logcatListener.Start(logcatArguments);
#endif
            }

            // Listen for entered commands
            commandInputField.onValidateInput -= OnValidateCommand;
            commandInputField.onValidateInput += OnValidateCommand;

            if (minimumHeight < 200f)
            {
                minimumHeight = 200f;
            }

            //Debug.LogAssertion( "assert" );
            //Debug.LogError( "error" );
            //Debug.LogException( new System.IO.EndOfStreamException() );
            //Debug.LogWarning( "warning" );
            //Debug.Log( "log" );
        }
Example #4
0
        private void OnEnable()
        {
            // Only one instance of debug console is allowed
            if (instance == null)
            {
                instance       = this;
                pooledLogItems = new List <DebugLogItem>();

                canvasTR = (RectTransform)transform;

                // Associate sprites with log types
                logSpriteRepresentations = new Dictionary <LogType, Sprite>
                {
                    { LogType.Log, infoLog },
                    { LogType.Warning, warningLog },
                    { LogType.Error, errorLog },
                    { LogType.Exception, errorLog },
                    { LogType.Assert, errorLog }
                };

                // Set initial button colors
                collapseButton.color   = isCollapseOn ? collapseButtonSelectedColor : collapseButtonNormalColor;
                filterInfoButton.color = (logFilter & DebugLogFilter.Info) == DebugLogFilter.Info
                                                ? filterButtonsSelectedColor : filterButtonsNormalColor;
                filterWarningButton.color = (logFilter & DebugLogFilter.Warning) == DebugLogFilter.Warning
                                                ? filterButtonsSelectedColor : filterButtonsNormalColor;
                filterErrorButton.color = (logFilter & DebugLogFilter.Error) == DebugLogFilter.Error
                                                ? filterButtonsSelectedColor : filterButtonsNormalColor;

                collapsedLogEntries          = new List <DebugLogEntry>(128);
                collapsedLogEntriesMap       = new Dictionary <DebugLogEntry, int>(128);
                uncollapsedLogEntriesIndices = new DebugLogIndexList();
                indicesOfListEntriesToShow   = new DebugLogIndexList();

                recycledListView.Initialize(this, collapsedLogEntries, indicesOfListEntriesToShow, logItemPrefab.Transform.sizeDelta.y);
                recycledListView.SetCollapseMode(isCollapseOn);
                recycledListView.UpdateItemsInTheList(true);

                nullPointerEventData = new PointerEventData(null);

                // If it is a singleton object, don't destroy it between scene changes
                if (singleton)
                {
                    DontDestroyOnLoad(gameObject);
                }
            }
            else if (this != instance)
            {
                Destroy(gameObject);
                return;
            }

            // Intercept debug entries
            Application.logMessageReceived -= ReceivedLog;
            Application.logMessageReceived += ReceivedLog;

            // Listen for entered commands
            commandInputField.onValidateInput -= OnValidateCommand;
            commandInputField.onValidateInput += OnValidateCommand;

            if (minimumHeight < 200f)
            {
                minimumHeight = 200f;
            }

            //Debug.LogAssertion( "assert" );
            //Debug.LogError( "error" );
            //Debug.LogException( new System.IO.EndOfStreamException() );
            //Debug.LogWarning( "warning" );
            //Debug.Log( "log" );

            //FPS Counter on for mobile only
            if (Application.isMobilePlatform)
            {
                fpsCounter.enabled = true;
            }
            else
            {
                fpsCounter.enabled = false;
            }
        }