private static ReorderableList GenerateReordableList <T>(PrefItem <T> preferenceItem) where T : IList { var result = new ReorderableList(preferenceItem.Value, typeof(T), true, true, true, true); result.elementHeight = 18f; result.drawHeaderCallback = rect => { rect.xMin -= EditorGUI.indentLevel * 16f; EditorGUI.LabelField(rect, preferenceItem, EditorStyles.boldLabel); }; result.onChangedCallback += list => preferenceItem.ForceSave(); result.drawElementCallback = (rect, index, focused, active) => { var icon = result.list[index] as IconBase; if (icon == null) { EditorGUI.LabelField(rect, "INVALID ICON"); return; } var content = Utility.GetTempGUIContent(icon.Name, icon.PreferencesTooltip, icon.PreferencesPreview); var whiteTexture = content.image ? content.image.name.Contains("eh_icon_white") : true; using (new GUIColor((whiteTexture && !EditorGUIUtility.isProSkin) ? Styles.backgroundColorEnabled : Color.white)) EditorGUI.LabelField(rect, content); }; onResetPreferences += () => result.list = preferenceItem.Value; return(result); }
private static void DoGUI(this PrefItem <IconData> prefItem) { if (!prefItem.Drawing) { return; } var icons = IconBase.AllLeftOfNameIcons; var index = Array.IndexOf(icons, prefItem.Value.Icon); var labels = (from icon in icons select new GUIContent(icon)).ToArray(); index = EditorGUILayout.Popup(prefItem, index, labels); if (index < 0 || index >= icons.Length) { return; } if (prefItem.Value.Icon.Name == icons[index].Name) { return; } prefItem.Value.Icon = icons[index]; prefItem.ForceSave(); }
static Preferences() { InitializePreferences(); Enabled.Label.text = string.Format("Enabled ({0}+H)", Utility.CtrlKey); #if UNITY_2018_3_OR_NEWER LeftSideButtonPref.DefaultValue = new IconData() { Icon = new Icons.None() }; #else LeftSideButtonPref.DefaultValue = new IconData() { Icon = new Icons.GameObjectIcon() }; #endif LineColor.DefaultValue = DefaultLineColor; OddRowColor.DefaultValue = DefaultOddSortColor; EvenRowColor.DefaultValue = DefaultEvenSortColor; HoverTintColor.DefaultValue = DefaultHoverTint; var defaultLeftIcons = new IconList { new Icons.MonoBehaviourIcon(), new Icons.Warnings(), new Icons.SoundIcon() }; var defaultRightIcons = new IconList { new Icons.Active(), new Icons.Lock(), new Icons.Static(), new Icons.PrefabApply() }; var defaultLayerColors = new List <LayerColor> { new LayerColor(5, new Color(0f, 0f, 1f, 0.3019608f)) }; LeftIcons.DefaultValue = defaultLeftIcons; RightIcons.DefaultValue = defaultRightIcons; PerLayerRowColors.DefaultValue = defaultLayerColors; leftIconsList = GenerateReordableList(LeftIcons); rightIconsList = GenerateReordableList(RightIcons); leftIconsList.onAddDropdownCallback = (rect, newList) => LeftIconsMenu.DropDown(rect); rightIconsList.onAddDropdownCallback = (rect, newList) => RightIconsMenu.DropDown(rect); rowColorsList = GenerateReordableList(PerLayerRowColors); rowColorsList.onAddDropdownCallback = (rect, newList) => RowColorsMenu.DropDown(rect); rowColorsList.drawElementCallback = (rect, index, focused, active) => { GUI.changed = false; rect.xMin -= EditorGUI.indentLevel * 16f; PerLayerRowColors.Value[index] = LayerColorField(rect, PerLayerRowColors.Value[index]); if (GUI.changed) { PerLayerRowColors.ForceSave(); } }; }
private static ReorderableList GenerateReordableList <T>(PrefItem <T> preferenceItem) where T : IList { var result = new ReorderableList(preferenceItem.Value, typeof(T), true, true, true, true); result.elementHeight = 18f; result.drawHeaderCallback = rect => { rect.xMin -= EditorGUI.indentLevel * 16f; EditorGUI.LabelField(rect, preferenceItem, EditorStyles.boldLabel); }; result.drawElementCallback = (rect, index, focused, active) => EditorGUI.LabelField(rect, result.list[index].ToString()); result.onChangedCallback += list => preferenceItem.ForceSave(); onResetPreferences += () => result.list = preferenceItem.Value; return(result); }
private static GenericMenu GetGenericMenuForIcons <T>(PrefItem <T> preferenceItem, IconBase[] icons) where T : IList { var menu = new GenericMenu(); foreach (var i in icons) { var icon = i; if (!preferenceItem.Value.Contains(icon) && icon != IconBase.none && icon != IconBase.none) { menu.AddItem(new GUIContent(icon.Name), false, () => { preferenceItem.Value.Add(icon); preferenceItem.ForceSave(); }); } } return(menu); }
public static void ForceDisableButton(IconBase button) { if (button == null) { Debug.LogError("Removing null button"); } else { Debug.LogWarning("Disabling \"" + button.Name + "\", most likely because it threw an exception"); } if (LeftSideButton == button) { LeftSideButton = IconBase.none; } RightIcons.Value.Remove(button); LeftIcons.Value.Remove(button); RightIcons.ForceSave(); LeftIcons.ForceSave(); }
static Preferences() { InitializePreferences(); Enabled.Label.text = string.Format("Enabled ({0}+H)", Utility.CtrlKey); #if UNITY_2018_3_OR_NEWER LeftSideButtonPref.DefaultValue = new IconData() { Icon = new Icons.None() }; #else LeftSideButtonPref.DefaultValue = new IconData() { Icon = new Icons.GameObjectIcon() }; #endif LineColor.DefaultValue = DefaultLineColor; OddRowColor.DefaultValue = DefaultOddSortColor; EvenRowColor.DefaultValue = DefaultEvenSortColor; HoverTintColor.DefaultValue = DefaultHoverTint; var defaultLeftIcons = new IconList { new Icons.MonoBehaviourIcon(), new Icons.Warnings(), new Icons.SoundIcon() }; var defaultRightIcons = new IconList { new Icons.Active(), new Icons.Lock(), new Icons.Static(), new Icons.PrefabApply() }; var defaultLayerColors = new List <LayerColor> { new LayerColor(5, new Color(0f, 0f, 1f, 0.3019608f)) }; LeftIcons.DefaultValue = defaultLeftIcons; RightIcons.DefaultValue = defaultRightIcons; PerLayerRowColors.DefaultValue = defaultLayerColors; MiniLabels.DefaultValue = new [] { Array.IndexOf(MiniLabelProvider.MiniLabelsTypes, typeof(LayerMiniLabel)), Array.IndexOf(MiniLabelProvider.MiniLabelsTypes, typeof(TagMiniLabel)) }; minilabelsNames = MiniLabelProvider.MiniLabelsTypes .Select(ml => ml == null? "None": ObjectNames.NicifyVariableName(ml.Name.Replace("MiniLabel", ""))) .ToArray(); leftIconsList = GenerateReordableList(LeftIcons); rightIconsList = GenerateReordableList(RightIcons); leftIconsList.onAddDropdownCallback = (rect, newList) => LeftIconsMenu.DropDown(rect); rightIconsList.onAddDropdownCallback = (rect, newList) => RightIconsMenu.DropDown(rect); rowColorsList = GenerateReordableList(PerLayerRowColors); rowColorsList.onAddDropdownCallback = (rect, newList) => RowColorsMenu.DropDown(rect); rowColorsList.drawElementCallback = (rect, index, focused, active) => { GUI.changed = false; rect.xMin -= EditorGUI.indentLevel * 16f; PerLayerRowColors.Value[index] = LayerColorField(rect, PerLayerRowColors.Value[index]); if (GUI.changed) { PerLayerRowColors.ForceSave(); } }; rowColorsNamedList = GenerateReordableList(PerNameRowColors); rowColorsNamedList.onAddDropdownCallback = (rect, newList) => RowNameColorsMenu.DropDown(rect); rowColorsNamedList.drawElementCallback = (rect, index, focused, active) => { GUI.changed = false; rect.xMin -= EditorGUI.indentLevel * 16f; PerNameRowColors.Value[index] = NameColorField(rect, PerNameRowColors.Value[index]); if (GUI.changed) { PerNameRowColors.ForceSave(); } }; RecreateMiniLabelProviders(); }