コード例 #1
0
 public static void SetLayout(float width, float height, float maxWidth, float maxHeight, bool autoWidth, bool autoHeight)
 {
     EditorGUILayoutExtension.SetLayout(width, height, maxWidth, maxHeight, (bool?)autoWidth, (bool?)autoHeight);
 }
コード例 #2
0
        public static void DrawColors()
        {
            var  theme          = Theme.active;
            bool hasPalettes    = ThemePalette.all.Count > 0;
            bool paletteAltered = !theme.palette.Matches(ThemePalette.all[Theme.paletteIndex]);

            if (theme.customizablePalette && hasPalettes)
            {
                bool open = "Colors".ToLabel().DrawFoldout("Theme.Colors");
                if (EditorGUIExtension.lastChanged)
                {
                    GUI.changed = false;
                }
                if (!open)
                {
                    return;
                }
                EditorGUI.indentLevel += 1;
                Theme.showAdvanced     = Theme.showAdvanced.Draw("Advanced");
                if (Theme.showAdvanced)
                {
                    RelativeColor.autoBalance = RelativeColor.autoBalance.Draw("Autobalance").As <AutoBalance>();
                }
                foreach (var group in theme.palette.colors.Where(x => x.Key != "*"))
                {
                    var groupName  = group.Key;
                    var isGroup    = groupName != "Default";
                    var colorCount = theme.palette.colors[groupName].Count(x => x.Value.source.IsNull());
                    var canExpand  = Theme.showAdvanced || colorCount > 3;
                    if (!Theme.showAdvanced && colorCount < 1)
                    {
                        continue;
                    }
                    if (canExpand)
                    {
                        var drawFoldout = groupName.ToLabel().DrawFoldout("Theme.Colors." + groupName);
                        if (EditorGUIExtension.lastChanged)
                        {
                            GUI.changed = false;
                        }
                        if (isGroup && !drawFoldout)
                        {
                            continue;
                        }
                        if (isGroup)
                        {
                            EditorGUI.indentLevel += 1;
                        }
                    }
                    var names = theme.palette.colors["*"].Keys.ToList();
                    if (Application.platform == RuntimePlatform.WindowsEditor)
                    {
                        names = "@System".AsArray().Concat(names).ToList();
                    }
                    foreach (var item in theme.palette.colors[groupName])
                    {
                        var  color = item.Value;
                        Rect area  = new Rect(1, 1, 1, 1);
                        if (!color.sourceName.IsEmpty())
                        {
                            if (!Theme.showAdvanced)
                            {
                                continue;
                            }
                            var index         = names.IndexOf(color.sourceName);
                            var offsetStyle   = EditorStyles.numberField.FixedWidth(35).Margin(0, 0, 2, 0);
                            var dropdownStyle = EditorStyles.popup.FixedWidth(100);
                            EditorGUILayout.BeginHorizontal();
                            if (index == -1)
                            {
                                var message = "[" + color.sourceName + " not found]";
                                index = names.Unshift(message).Draw(0, item.Key.ToTitleCase());
                                if (index != 0)
                                {
                                    color.sourceName = names[index];
                                }
                            }
                            else
                            {
                                color.sourceName = names[names.Draw(index, color.name.ToTitleCase())];
                                GUILayout.Space(2);
                                if (color.blendMode == ColorBlend.Normal)
                                {
                                    color.offset = color.offset.Draw("", offsetStyle, false);
                                }
                                color.Assign(theme.palette, color.sourceName);
                                GUILayout.Space(color.blendMode != ColorBlend.Normal ? 2 : 4);
                                if (color.blendMode != ColorBlend.Normal)
                                {
                                    color.blendMode = color.blendMode.Draw("", dropdownStyle, false).As <ColorBlend>();
                                    GUILayout.Space(2);
                                    color.offset = color.offset.Draw("", offsetStyle, false).Clamp(0, 1);
                                    GUILayout.Space(2);
                                    EditorGUILayoutExtension.SetLayout(0, 0, 150);
                                    color.blend = color.blend.Draw("", false);
                                    EditorGUILayoutExtension.SetLayout();
                                }
                            }
                            EditorGUILayout.EndHorizontal();
                            area = GUILayoutUtility.GetLastRect();
                            GUILayout.Space(2);
                        }
                        else
                        {
                            color.value = color.value.Draw(color.name.ToTitleCase());
                            area        = GUILayoutUtility.GetLastRect();
                        }
                        if (area.Clicked(1))
                        {
                            GenericMenu menu = new GenericMenu();
                            menu.AddItem(new GUIContent("Normal"), color.sourceName.IsEmpty(), () => {
                                color.blendMode  = ColorBlend.Normal;
                                color.sourceName = "";
                            });
                            menu.AddItem(new GUIContent("Inherited"), !color.sourceName.IsEmpty() && color.blendMode == ColorBlend.Normal, () => {
                                color.blendMode = ColorBlend.Normal;
                                if (color.sourceName.IsEmpty())
                                {
                                    color.sourceName = names[0];
                                }
                            });
                            menu.AddItem(new GUIContent("Blended"), color.blendMode != ColorBlend.Normal, () => {
                                color.blendMode = ColorBlend.Lighten;
                                if (color.sourceName.IsEmpty())
                                {
                                    color.sourceName = names[0];
                                }
                            });
                            menu.ShowAsContext();
                            UnityEvent.current.Use();
                        }
                    }
                    if (canExpand && isGroup)
                    {
                        EditorGUI.indentLevel -= 1;
                    }
                }
                if (paletteAltered)
                {
                    EditorGUILayout.BeginHorizontal();
                    GUILayout.Space(15);
                    if (GUILayout.Button("Save", GUILayout.Width(100)))
                    {
                        theme.palette.Export();
                    }
                    if (GUILayout.Button("Reset", GUILayout.Width(100)))
                    {
                        Theme.LoadColors(true);
                    }
                    if (GUILayout.Button("Apply", GUILayout.Width(100)))
                    {
                        theme.palette.Export(theme.palette.path);
                    }
                    EditorGUILayout.EndHorizontal();
                }
                if (GUI.changed)
                {
                    Theme.SaveColors();
                    EditorPrefs.SetInt("EditorTheme-AutobalanceColors", RelativeColor.autoBalance.ToInt());
                    EditorPrefs.SetBool("EditorTheme-ShowAdvancedColors", Theme.showAdvanced);
                }
                EditorGUI.indentLevel -= 1;
            }
        }