Esempio n. 1
0
        /// <summary>
        /// Register a debug info
        /// </summary>
        /// <param name="label">The label to display next to the string returned by the callback.</param>
        /// <param name="callback">A callback function to invoke that should return a string to display in the debug console.</param>
        public void RegisterDebugInfo(string label, GetDebugInfo callback)
        {
            if (string.IsNullOrEmpty(label))
            {
                throw new ArgumentNullException("label");
            }
            if (callback == null)
            {
                throw new ArgumentNullException("callback");
            }

            DebugInfo info = new DebugInfo();

            info.m_Label      = label;
            info.m_Callback   = callback;
            info.m_InfoObject = Instantiate(m_DebugInfoPrefab.gameObject) as GameObject;
            info.m_TextOutput = info.m_InfoObject.GetComponentInChildren <Text>();
            m_DebugInfos.Add(info);

            info.m_InfoObject.transform.SetParent(m_DebugInfoLayout.transform, false);
        }
Esempio n. 2
0
        /// <summary>
        /// Unregister a debug info hook.
        /// </summary>
        /// <param name="label">The label to unregister.</param>
        /// <param name="callback">The callback to unregister. If null, then the callback will be matched by label only.</param>
        /// <returns>Returns true if the callback was unregistered.</returns>
        public bool UnregisterDebugInfo(string label, GetDebugInfo callback = null)
        {
            if (string.IsNullOrEmpty(label))
            {
                throw new ArgumentNullException("label");
            }
            for (int i = 0; i < m_DebugInfos.Count; ++i)
            {
                if (m_DebugInfos[i].m_Label == label)
                {
                    if (callback != null && callback != m_DebugInfos[i].m_Callback)
                    {
                        continue;
                    }

                    Destroy(m_DebugInfos[i].m_InfoObject);
                    m_DebugInfos.RemoveAt(i);
                    return(true);
                }
            }

            return(false);
        }