public static bool DoMediumFoldoutError(Dictionary <Material, Toggles> foldouts, Material mat, MaterialEditor me, MaterialProperty toggleProp, bool errorCond, int buttonCount, string header)
 {
     foldouts[mat].SetState(header, MediumFoldoutError(header, foldouts[mat].GetState(header), errorCond, buttonCount, me, mat));
     FoldoutProperty(me, toggleProp);
     MGUI.Space6();
     return(foldouts[mat].GetState(header));
 }
        public static void SubFoldout(
            string header, Dictionary <Material, Toggles> foldouts,
            Dictionary <Action, GUIContent> buttons, Material mat,
            MaterialEditor me, Action DisplayTabContent, bool error
            )
        {
            int  buttonCount = buttons != null ? buttons.Count : 0;
            bool isToggled   = DisplayErrorSubFoldoutElements(me, header, foldouts[mat].GetState(header), buttonCount, 0, error);

            foldouts[mat].SetState(header, isToggled);

            if (buttons != null)
            {
                DisplaySubFoldoutButtons(buttons);
            }
            else
            {
                MGUI.Space18();
            }

            if (isToggled)
            {
                MGUI.Space10();
                DisplayTabContent();
                MGUI.Space4();
            }
            else
            {
                MGUI.Space4();
            }
        }
        public static bool DisplayFoldoutElements(MaterialEditor me, string header, bool display, int buttonCount, int size)
        {
            GUIStyle formatting = GetFoldoutFormatting();
            Rect     rect       = GUILayoutUtility.GetRect(MGUI.GetInspectorWidth(), formatting.fixedHeight, formatting);

            rect.width -= foldoutOffsets[buttonCount];
            rect.x     -= 8f;

            Event evt       = Event.current;
            Color bgCol     = GUI.backgroundColor;
            bool  mouseOver = rect.Contains(evt.mousePosition);

            if (evt.type == EventType.MouseDown && mouseOver)
            {
                foldoutClicked = true;
                evt.Use();
            }

            else if (evt.type == EventType.Repaint && foldoutClicked && mouseOver)
            {
                GUI.backgroundColor = Color.gray;
                me.Repaint();
            }

            if (ContainsDigit(header))
            {
                header = header.Substring(0, header.Length - 2);
            }

            GUI.Box(rect, header, formatting);
            GUI.backgroundColor = bgCol;
            return(FoldoutToggle(rect, evt, mouseOver, display, 0));
        }
 public static bool DoMediumFoldout(Dictionary <Material, Toggles> foldouts, Material mat, MaterialEditor me, MaterialProperty prop, int buttonCount, string header)
 {
     foldouts[mat].SetState(header, MediumFoldout(header, foldouts[mat].GetState(header), buttonCount, me));
     FoldoutProperty(me, prop);
     MGUI.Space6();
     return(foldouts[mat].GetState(header));
 }
 public static void MaskProperty(Material mat, MaterialEditor me, bool display, MaterialProperty mask, MaterialProperty scroll)
 {
     if (display)
     {
         me.TexturePropertySingleLine(new GUIContent("Mask Texture"), mask);
         TextureSOScroll(me, mask, scroll, mask.textureValue);
         MGUI.Space4();
     }
 }
        public static GUIStyle GetSubFoldoutFormatting(int buttonCount)
        {
            GUIStyle formatting = new GUIStyle("ShurikenModuleTitle");

            formatting.contentOffset = new Vector2(20f, -2f);
            formatting.fixedHeight   = 22f;
            formatting.fixedWidth    = MGUI.GetInspectorWidth() - subFoldoutOffsets[buttonCount];
            formatting.fontSize      = 11;
            return(formatting);
        }
        public static bool MaskFoldout(string header, bool display)
        {
            float           lw        = EditorGUIUtility.labelWidth - 13;
            GUILayoutOption clickArea = GUILayout.MaxWidth(lw);
            Rect            rect      = GUILayoutUtility.GetRect(0, 18f, clickArea);

            MGUI.SpaceN24();
            header = "    " + header;
            EditorGUILayout.LabelField(header);
            MGUI.Space24();
            return(DoMaskToggle(display, rect));
        }
        public static bool FoldoutError(string header, bool display, MaterialEditor me, Material mat, bool[] errorConds, int buttonCount)
        {
            GUIStyle formatting = new GUIStyle("ShurikenModuleTitle");

            formatting.font            = new GUIStyle(EditorStyles.boldLabel).font;
            formatting.contentOffset   = new Vector2(20f, -3f);
            formatting.hover.textColor = Color.gray;
            formatting.fixedHeight     = 28f;
            formatting.fontSize        = 10;

            Rect rect = GUILayoutUtility.GetRect(MGUI.GetInspectorWidth(), formatting.fixedHeight, formatting);

            rect.width -= foldoutOffsets[buttonCount];
            rect.x     -= 8f;

            Event evt   = Event.current;
            Color bgCol = GUI.backgroundColor;

            foreach (bool b in errorConds)
            {
                if (b)
                {
                    GUI.backgroundColor = errorCol;
                    break;
                }
            }
            bool mouseOver = rect.Contains(evt.mousePosition);

            if (evt.type == EventType.MouseDown && mouseOver)
            {
                foldoutClicked = true;
                evt.Use();
            }

            else if (evt.type == EventType.Repaint && foldoutClicked && mouseOver)
            {
                GUI.backgroundColor = Color.gray;
                me.Repaint();
            }

            if (ContainsDigit(header))
            {
                header = header.Substring(0, header.Length - 2);
            }

            GUI.Box(rect, header, formatting);
            GUI.backgroundColor = bgCol;

            return(FoldoutToggle(rect, evt, mouseOver, display, 0));
        }
        public static bool MediumFoldoutError(string header, bool display, bool errorCond, int buttonCount, MaterialEditor me, Material mat)
        {
            GUIStyle formatting = new GUIStyle("ShurikenModuleTitle");
            float    lw         = EditorGUIUtility.labelWidth;

            formatting.contentOffset = new Vector2(20f, -2f);
            formatting.fixedHeight   = 22f;
            formatting.fixedWidth    = MGUI.GetInspectorWidth() - subFoldoutOffsets[buttonCount];
            formatting.fontSize      = 10;

            Rect rect = GUILayoutUtility.GetRect(0f, 20f, formatting);

            rect.x    -= 4f;
            rect.width = lw;

            Event evt   = Event.current;
            Color bgCol = GUI.backgroundColor;

            if (errorCond)
            {
                GUI.backgroundColor = errorCol;
            }

            bool mouseOver = rect.Contains(evt.mousePosition);

            if (evt.type == EventType.MouseDown && mouseOver)
            {
                foldoutClicked = true;
                evt.Use();
            }

            else if (evt.type == EventType.Repaint && foldoutClicked && mouseOver)
            {
                GUI.backgroundColor = Color.gray;
                me.Repaint();
            }

            if (ContainsDigit(header))
            {
                header = header.Substring(0, header.Length - 2);
            }

            GUI.Box(rect, header, formatting);
            GUI.backgroundColor = bgCol;

            return(FoldoutToggle(rect, evt, mouseOver, display, 1));
        }
        public static bool DoMaskToggle(bool display, Rect rect)
        {
            Event evt       = Event.current;
            Rect  arrowRect = new Rect(rect.x - 1f, rect.y + 5f, 0f, 0f);

            if (evt.rawType == EventType.Repaint)
            {
                EditorStyles.foldout.Draw(arrowRect, false, false, display, false);
            }
            if (evt.rawType == EventType.MouseDown && rect.Contains(evt.mousePosition))
            {
                display = !display;
                evt.Use();
            }
            MGUI.SpaceN20();
            return(display);
        }
        public static void DisplaySubFoldoutButtons(Dictionary <Action, GUIContent> buttons)
        {
            float buttonSpacing = 23f;

            GUILayout.BeginHorizontal();
            Rect r = EditorGUILayout.GetControlRect();

            r.y     -= 1f;
            r.x     += MGUI.GetInspectorWidth() + EditorGUIUtility.labelWidth + buttonSpacing + 12f;
            r.width  = buttonSpacing;
            r.height = 20f;
            for (int i = 0; i < buttons.Count; i++)
            {
                r.x -= (buttonSpacing + 1f) * Mathf.Clamp01(i);
                if (GUI.Button(r, buttons.Values.ElementAt(i)))
                {
                    buttons.Keys.ElementAt(i).Invoke();
                }
            }
            GUILayout.EndHorizontal();
        }
        public static void Foldout(
            string header, Dictionary <Material, Toggles> foldouts,
            Dictionary <Action, GUIContent> buttons, Material mat,
            MaterialEditor me, Action DisplayTabContent, bool[] errors
            )
        {
            bool isToggled = DisplayErrorFoldoutElements(me, header, foldouts[mat].GetState(header), buttons.Count, 0, errors);

            foldouts[mat].SetState(header, isToggled);

            if (buttons != null)
            {
                DisplayFoldoutButtons(buttons);
            }

            if (isToggled)
            {
                MGUI.Space8();
                DisplayTabContent();
                MGUI.Space4();
            }
        }
        void OnGUI()
        {
            MGUI.Space10();
            if (needsRefresh)
            {
                selection = 0;
                PopulateMaterialList();
                needsRefresh = false;
            }
            MGUI.Space8();
            GUILayout.Label(matCount + " material(s) with keywords found...");
            MGUI.SpaceN4();

            // Display list of materials
            // float boxSpacing = position.height-200 > 10 ? position.height-200 : 10;
            float spacing = (position.height / 2.0f);

            ContentBox(new Vector2(position.width, spacing));
            scrollPos0 = EditorGUILayout.BeginScrollView(scrollPos0, GUILayout.Width(position.width + 1), GUILayout.Height(spacing));
            if (materialNames != null)
            {
                selection = GUILayout.SelectionGrid(selection, materialNames, 1);
            }
            if (materials.Count > 0)
            {
                materials.TryGetValue(materialNames[selection], out selectedMat);
            }
            EditorGUILayout.EndScrollView();

            // Display list of keywords
            ContentBox(new Vector2(position.width, spacing / 2));
            scrollPos1 = EditorGUILayout.BeginScrollView(scrollPos1, GUILayout.Width(position.width + 1), GUILayout.Height(spacing / 2));
            if (selectedMat != null)
            {
                keywords = selectedMat.shaderKeywords;
                if (excludeWhitelisted)
                {
                    keywords = IsolateKeywords(selectedMat.shaderKeywords, whitelist);
                }
                GUILayout.SelectionGrid(0, keywords, 1, new GUIStyle("Label"));
            }
            EditorGUILayout.EndScrollView();

            // Display info about selection
            if (selectedMat != null)
            {
                GUILayout.Label("Shader:		"+ selectedMat.shader.name);
                GUILayout.Label("Total Keywords:	"+ keywords.Length);
            }

            // Controls

            excludeWhitelisted = GUILayout.Toggle(excludeWhitelisted, " Exclude Whitelisted Keywords");
            if (hasToggled != excludeWhitelisted)
            {
                needsRefresh = true;
            }
            hasToggled = excludeWhitelisted;
            if (GUILayout.Button("Refresh List"))
            {
                needsRefresh = true;
            }
            if (GUILayout.Button("Locate Selected"))
            {
                EditorUtility.FocusProjectWindow();
                EditorGUIUtility.PingObject(selectedMat);
            }
        }