Пример #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);
        }
Пример #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;
        }