public static bool DrawHeader(this UnityLabel current, object key = null, GUIStyle style = null, bool editable = false, Action callback = null, bool indention = true)
        {
            string stateName = key.IsNull() ? current + "Header" : key.GetHashCode().ToString();

            if (key is string)
            {
                stateName = (string)key;
            }
            bool state = EditorPrefs.GetBool(stateName);
            //current = state ? "▼ " + current : "▶ " + current;
            var fallback     = editable ? EditorStyles.textField : EditorStyles.label;
            var currentStyle = style.IsNull() ? fallback: new GUIStyle(style);

            if (state)
            {
                currentStyle.normal = currentStyle.onNormal;
            }
            if (!editable)
            {
                if (current.DrawButton(currentStyle, indention))
                {
                    state = !state;
                    EditorPrefs.SetBool(stateName, state);
                    if (!callback.IsNull())
                    {
                        callback();
                    }
                }
            }
            else
            {
                current.value.text = current.value.text.Draw(null, currentStyle, indention);
            }
            return(state);
        }
Beispiel #2
0
        public static bool DrawHeader(this UnityLabel current, Rect area, object key, GUIStyle style = null, bool indention = true)
        {
            string stateName = key.IsNull() ? current + "Foldout" : key.GetHashCode().ToString();

            if (key is string)
            {
                stateName = (string)key;
            }
            bool state = EditorPrefs.GetBool(stateName);

            current = state ? "▼ " + current : "▶ " + current;
            var currentStyle = style.IsNull() ? null : new GUIStyle(style);

            if (state)
            {
                currentStyle.normal = currentStyle.active;
            }
            if (current.DrawButton(area, currentStyle, indention))
            {
                state = !state;
                EditorPrefs.SetBool(stateName, state);
            }
            return(state);
        }