Esempio n. 1
0
        protected Channel(string channelName, Color channelColor, IChannel parent = null)
        {
            if (s_Instance != null)
            {
                return;
            }

            s_Instance = this;

            m_ChannelName  = channelName;
            m_ChannelColor = channelColor;
            m_ColorString  = !Zebug.ColorTagsOnlyInEditor || Application.isEditor
                                ? $"<color={channelColor.ToHexString()}>{channelName}: </color>"
                                : channelName + ": ";

            //  --- Default on or not? This is a hard problem to solve. People who add channels
            //      themselves would generally like them to be on and show up without having to do
            //      anything extra. However for people not currently debugging that module, as well
            //      as designers and artists... probably do not want it to show up randomly.
            //      Half the point of this library is to help cut down on console log clutter.
            //      Currently for things that default off you need to add GUI to Set the log
            //      to true for you.
            //      2020-11-23: You can now set a preprocessor define to force to default.
            bool defaultOn = false;

            #if ZEBUG_ALL_ON
            defaultOn = true;
            #endif

            //  --- Some builds have been run on device and have stored _off_ fields for things that
            //      shouldn't have, like ZebugBase. This will make sure it resets them all on.
            bool forceToDefault = false;

            #if ZEBUG_FORCE_TO_DEFAULT
            forceToDefault = true;
            #endif

            if (parent != null)
            {
                m_Parent = parent;
                m_Depth  = m_Parent.Depth() + 1;
            }
            else
            {
                bool isBase = channelName == "ZebugBase"; // todo this isn't great
                if (!isBase)
                {
                    //  --- This should potentially be a serializable null, depending on how I want the
                    //      hierarchy editor code to look.
                    m_Parent = Zebug.Instance;
                    m_Depth  = 1;
                    m_Parent.AddChild(this);
                }
                else
                {
                    //  --- We're the base channel!
                    defaultOn = true;
                }
            }

            if (m_Parent != null)
            {
                m_Parent.AddChild(this);
            }

            string fullName = FullName();
            string logKey   = kLogKeyPrefix + fullName;
            if (forceToDefault || !PlayerPrefs.HasKey(logKey))
            {
                PlayerPrefs.SetInt(logKey, defaultOn ? 1 : 0);
            }

            m_LogEnabled = PlayerPrefs.GetInt(logKey) == 1;

            string gizmoKey = kGizmoKeyPrefix + fullName;
            if (!PlayerPrefs.HasKey(gizmoKey))
            {
                PlayerPrefs.SetInt(gizmoKey, 0);
            }

            m_GizmosEnabled = PlayerPrefs.GetInt(gizmoKey) == 1;

            Zebug.s_Channels.Add(this);
        }