public static void DrawColorGroupHorizontal(Rect rect, ColorGroup cg, Action onClick) { guiBGColor = GUI.backgroundColor; if (cg != null && cg.Count > 0) { GUI.backgroundColor = StylesUI.borderColor; } else { GUI.backgroundColor = Color.clear; } if (GUI.Button(rect, "")) { onClick(); } GUI.backgroundColor = guiBGColor; if (cg.Count > 0) { rect.width -= 2; rect.height -= 2; rect.x += 1; rect.y += 1; if (cg.Count == 1) { EditorGUI.DrawRect(rect, cg[0].color); } else { Rect r = rect; r.width = r.width * 0.7f; EditorGUI.DrawRect(r, cg[0].color); r.x += r.width; r.width = rect.width * 0.3f; r.width = r.width / (cg.Count - 1); for (int i = 1; i < cg.Count; i++) { EditorGUI.DrawRect(r, cg[i].color); r.x += r.width; } } } GUIStyle textStyle = StylesUI.ColoredLabel; if (cg.Count > 0) { if (EditorHelper.IsColorDark(cg[0].color)) { textStyle.normal.textColor = Color.white; } else { textStyle.normal.textColor = Color.black; } } else { textStyle.normal.textColor = StylesUI.CenteredLabel.normal.textColor; } rect.width *= 0.7f; rect.x += 5; EditorGUI.LabelField(rect, cg.name, textStyle); GUI.color = guiColor; }
private void OnColorModeSelected() { if (!EditMode) { elementsRListSP = EditorGUILayout.BeginScrollView(elementsRListSP); elementsRList.DoLayoutList(); EditorGUILayout.EndScrollView(); return; } GUILayout.BeginHorizontal(); StylesUI.LeftColumn.fixedWidth = Mathf.Clamp(position.width * 0.3f, 50f, 300f); GUILayout.BeginVertical(StylesUI.LeftColumn); elementsRListSP = EditorGUILayout.BeginScrollView(elementsRListSP); elementsRList.DoLayoutList(); EditorGUILayout.EndScrollView(); GUILayout.EndVertical(); if (!EditMode) { return; } GUILayout.BeginVertical(); if (elementsRList.index != -1 && SelectedCG != null) { GUILayout.Space(15f); GUILayout.BeginVertical("Box"); GUILayout.Label("Element " + SelectedCG.name, StylesUI.TitleLabel); GUILayout.Space(10f); GUILayout.BeginHorizontal(); SelectedCG.name = EditorGUILayout.TextField("Name", SelectedCG.name); if (EditorHelper.DrawButton(false, StylesUI.Icon, () => { return(GUILayout.Button(StylesUI.DuplicateButton, StylesUI.IconButton)); })) { Theme.colors.Add(new ColorGroup(SelectedCG)); UpdateColorNames(); } GUILayout.EndHorizontal(); GUILayout.Space(5f); GUILayout.Label("Filter Properties", StylesUI.TitleLabel); GUILayout.Space(5f); // #if UNITY_2017_4_OR_NEWER EUIType t = (EUIType)EditorGUILayout.EnumFlagsField("Type", (EUIType)SelectedCG.uiMask, StylesUI.Popup); if (t != SelectedCG.uiMask) { SelectedCG.uiMask = t; UpdateColors(SelectedCG); } // #endif GUILayout.BeginHorizontal(); SelectedCG.tag = EditorGUILayout.TagField("Tag", SelectedCG.tag, StylesUI.Popup); if (EditorHelper.DrawButton(false, StylesUI.Icon, () => { return(GUILayout.Button(StylesUI.DeleteTextButton, StylesUI.IconButton)); })) { SelectedCG.tag = ""; } GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); SelectedCG.regex = EditorGUILayout.TextField("Regex", SelectedCG.regex); if (EditorHelper.DrawButton(false, StylesUI.Icon, () => { return(GUILayout.Button(StylesUI.HelpButton, StylesUI.IconButton)); })) { Application.OpenURL("https://msdn.microsoft.com/en-us/library/az24scfc(v=vs.110).aspx"); } GUILayout.EndHorizontal(); GUILayout.Space(10f); GUILayout.EndVertical(); GUILayout.Space(10f); elementRListSP = EditorGUILayout.BeginScrollView(elementRListSP); if (colorsList != null) { colorsList.DoLayoutList(); GUILayout.Space(15f); } if (palleteList != null) { palleteList.DoLayoutList(); GUILayout.Space(15f); } if (elementModifierList != null) { elementModifierList.DoLayoutList(); GUILayout.Space(15f); } if (elementDescendantsRList != null) { elementDescendantsRList.DoLayoutList(); } EditorGUILayout.EndScrollView(); GUILayout.BeginHorizontal(); GameObject prefab = null; if (Selection.activeGameObject) { #if UNITY_2018_3_OR_NEWER prefab = PrefabUtility.GetOutermostPrefabInstanceRoot(Selection.activeGameObject); #else prefab = PrefabUtility.FindPrefabRoot(Selection.activeGameObject); #endif } string smartSelection = "Scene"; if (prefab && AssetDatabase.Contains(prefab)) { smartSelection = "Prefab"; } else if (Selection.gameObjects.Length > 0) { smartSelection = "Selection"; } if (GUILayout.Button("Apply to " + smartSelection)) { AssignColorGroup(SelectedCG); } GUILayout.EndHorizontal(); GUILayout.Space(3f); } GUILayout.EndVertical(); GUILayout.EndHorizontal(); }