private static void DoGUI <T>(this PrefItem <T> prefItem) where T : struct, IConvertible { if (prefItem.Drawing) { prefItem.Value = (T)(object)EditorGUILayout.EnumPopup(prefItem, (Enum)(object)prefItem.Value); } }
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(); }
private static void DoGUI(this PrefItem <string> prefItem) { if (prefItem.Drawing) { prefItem.Value = EditorGUILayout.TextField(prefItem.Label, prefItem); } }
private static void DoGUI(this PrefItem <Color> prefItem) { if (prefItem.Drawing) { prefItem.Value = EditorGUILayout.ColorField(prefItem, prefItem); } }
private static void DoGUISlider(this PrefItem <float> prefItem, float min, float max) { if (prefItem.Drawing) { prefItem.Value = EditorGUILayout.Slider(prefItem, prefItem, min, max); } }
private static void DoGUI(this PrefItem <bool> prefItem) { if (prefItem.Drawing) { prefItem.Value = EditorGUILayout.Toggle(prefItem, prefItem); } }
private static void DoGUISlider(this PrefItem <int> prefItem, int min, int max) { if (prefItem.Drawing) { prefItem.Value = EditorGUILayout.IntSlider(prefItem, prefItem, min, max); } }
private static void DoGUI(this PrefItem <float> prefItem) { if (prefItem.Drawing) { prefItem.Value = EditorGUILayout.FloatField(prefItem, prefItem); } }
private static ReorderableList GenerateReordableListForIcons <T>(PrefItem <T[]> preferenceItem) { var result = new ReorderableList(preferenceItem.Value.ToList(), 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.onAddDropdownCallback = (rect, newList) => (typeof(T) == typeof(RightSideIcon) ? RightIconsMenu : LeftIconsMenu).DropDown(rect); return(result); }
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 void ReloadPrefs() { Enabled = new PrefItem <bool>("HierarchyEnabled", true, "Enabled (Ctrl+H)", "Enable or disable the entire plugin, it will be automatically disabled if any error occurs"); Offset = new PrefItem <int>("HierarchyOffset", 2, "Offset", "Offset for icons, useful if you have more extensions that also uses hierarchy"); Tree = new PrefItem <bool>("HierarchyTree", true, "Hierarchy tree", "Shows lines connecting child transforms to their parent, useful if you have multiple childs inside childs"); Warnings = new PrefItem <bool>("HierarchyWarning", true, "Warnings", "Shows icons next to the GameObject if any error, warning or log is referencing it"); Tooltips = new PrefItem <bool>("HierarchyTooltip", true, "Tooltips", "Shows tooltips, like this one"); Selection = new PrefItem <bool>("HierarchySelection", true, "Enhanced selection", "Allow selecting GameObjects by dragging over them with right mouse button"); LeftSideButton = new PrefItem <DrawType>("HierarchyLeftSideButton", DrawType.Icon, "Left side button", "The button that will appear in the left side of the hierarchy\nLooks better with \"Hierarchy Tree\" disabled"); LeftmostButton = new PrefItem <bool>("HierarchyLeftMostSideButton", true, "Left side button at leftmost", "Put the left button to the leftmost side of the hierachy, if disabled it will be next to the game object name"); Separators = new PrefItem <StripType>("HierarchyStrips", StripType.ColorAndLines, "Separators", string.Empty); LabelType = new PrefItem <MiniLabelType>("HierarchyMiniLabel", MiniLabelType.TagOrLayer, "Mini label", "The little label next to the GameObject name"); Trailing = new PrefItem <bool>("HierarchyTrailing", true, "Trailing", "Append ... when names are bigger than the view area"); AllowSelectingLocked = new PrefItem <bool>("HierarchySelectLocked", true, "Allow locked selection (Hierarchy)", "Allow selecting objects that are locked"); AllowSelectingLockedSceneView = new PrefItem <bool>("HierarchySelectLockedSV", false, "Allow locked selection (Scene View)", "Allow selecting objects that are locked on scene view\nObjects locked before you change this option will have the previous behaviour, you need to unlock and lock them again to apply this setting"); ChangeAllSelected = new PrefItem <bool>("HierarchyChangeAllLocked", true, "Change all selected", "This will make the enable, lock, layer, tag and static buttons affect all selected objects in the hierarchy"); ReplaceToggle = new PrefItem <bool>("HierachyReplaceToggle", false, "Replace default child toggle", "Replace the default toggle for expanding children for a new one that shows the child count"); SmallerMiniLabel = new PrefItem <bool>("HierarchySmallerMiniLabel", true, "Smaller mini label font", "Use a smaller font on the minilabel for narrow hierarchies"); StaticAskMode = new PrefItem <ChildrenChangeMode>("HierarchyStaticMode", ChildrenChangeMode.Ask, "Static change mode", "Which flags will be changed when you click on the static toggle"); LockAskMode = new PrefItem <ChildrenChangeMode>("HierarchyLockMode", ChildrenChangeMode.ObjectAndChildren, "Lock change mode", "Which objects will be locked when you click on the lock toggle"); LayerAskMode = new PrefItem <ChildrenChangeMode>("HierarchyLayerMode", ChildrenChangeMode.Ask, "Layer change mode", "Which objects will have their layer changed when you click on the layer button or on the mini label"); TagAskMode = new PrefItem <ChildrenChangeMode>("HierarchyTagMode", ChildrenChangeMode.ObjectOnly, "Tag change mode", "Which objects will have their tag changed when you click on the tag button or on the mini label"); var list = new List <DrawType>(); if (!EditorPrefs.HasKey(allKeys[currentKeyIndex++] = "HierarchyDrawOrderCount")) { //list.Add(DrawType.Icon); list.Add(DrawType.Enable); list.Add(DrawType.Lock); list.Add(DrawType.Static); list.Add(DrawType.ApplyPrefab); list.Add(DrawType.Tag); list.Add(DrawType.Layer); } else { for (var i = 0; i < EditorPrefs.GetInt("HierarchyDrawOrderCount"); i++) { list.Add((DrawType)EditorPrefs.GetInt("HierarchyDrawOrder" + i)); } } _drawOrder = list; rList = new ReorderableList(DrawOrder, typeof(DrawType), true, true, true, true); rList.drawHeaderCallback += rect => EditorGUI.LabelField(rect, listContent, EditorStyles.boldLabel); rList.drawElementCallback += (rect, index, focused, active) => EditorGUI.LabelField(rect, ObjectNames.NicifyVariableName(rList.list[index].ToString())); rList.onAddDropdownCallback += (rect, newList) => Menu.DropDown(rect); }
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); }
private static void ReloadPrefs() { Enabled = new PrefItem <bool>("HierarchyEnabled", true, "Enabled (Ctrl+H)", "Enable or disable the entire plugin, it will be automatically disabled if any error occurs"); Offset = new PrefItem <int>("HierarchyOffset", 2, "Offset", "Offset for icons, useful if you have more extensions that also uses hierarchy"); Tree = new PrefItem <bool>("HierarchyTree", true, "Hierarchy tree", "Shows lines connecting child transforms to their parent, useful if you have multiple childs inside childs"); Warnings = new PrefItem <bool>("HierarchyWarning", true, "Warnings", "Shows icons next to the GameObject if any error, warning or log is referencing it"); Tooltips = new PrefItem <bool>("HierarchyTooltip", true, "Tooltips", "Shows tooltips, like this one"); Selection = new PrefItem <bool>("HierarchySelection", true, "Enhanced Selection", "Allow selecting GameObjects by dragging over them with right mouse button"); Separators = new PrefItem <StripType>("HierarchyStrips", StripType.ColorAndLines, "Separators", string.Empty); LabelType = new PrefItem <MiniLabelType>("HierarchyMiniLabel", MiniLabelType.TagOrLayer, "Mini label", "The little label next to the GameObject _buildingName"); StaticAskMode = new PrefItem <StaticMode>("HierarchyStaticMode", StaticMode.Ask, "Static change mode", "How children of objects should react when changing you click on the static toggle"); Trailing = new PrefItem <bool>("HierarchyTrailing", true, "Trailing", "Append ... when names are bigger than the view area"); AllowSelectingLocked = new PrefItem <bool>("HierarchySelectLocked", true, "Allow locked selection", "Allow selecting objects that are locked"); var list = new List <DrawType>(); if (!EditorPrefs.HasKey(allKeys[currentKeyIndex++] = "HierarchyDrawOrderCount")) { list.Add(DrawType.Icon); list.Add(DrawType.Enabled); list.Add(DrawType.Lock); list.Add(DrawType.Static); list.Add(DrawType.ApplyPrefab); list.Add(DrawType.Tag); list.Add(DrawType.Layer); } else { for (var i = 0; i < EditorPrefs.GetInt("HierarchyDrawOrderCount"); i++) { list.Add((DrawType)EditorPrefs.GetInt("HierarchyDrawOrder" + i)); } } _drawOrder = list; rList = new ReorderableList(DrawOrder, typeof(DrawType), true, true, true, true); rList.drawHeaderCallback += rect => EditorGUI.LabelField(rect, listContent, EditorStyles.boldLabel); rList.drawElementCallback += (rect, index, focused, active) => EditorGUI.LabelField(rect, ObjectNames.NicifyVariableName(rList.list[index].ToString())); rList.onAddDropdownCallback += (rect, newList) => Menu.DropDown(rect); }
public static void ReloadPrefs() { Enabled = new PrefItem <bool>("Enabled", true, string.Format("Enabled ({0}+H)", Utility.CtrlKey), "Enable or disable the entire plugin, it will be automatically disabled if any error occurs"); Offset = new PrefItem <int>("Offset", 2, "Offset", "Offset for icons, useful if you have more extensions that also uses hierarchy"); Tree = new PrefItem <bool>("Tree", true, "Hierarchy tree", "Shows lines connecting child transforms to their parent, useful if you have multiple childs inside childs"); Tooltips = new PrefItem <bool>("Tooltip", true, "Tooltips", "Shows tooltips, like this one"); RelevantTooltipsOnly = new PrefItem <bool>("RelevantTooltips", true, "Relevant Tooltips", "Show only tooltips with relevant informations"); EnhancedSelection = new PrefItem <bool>("Selection", true, "Enhanced selection", "Allow selecting GameObjects by dragging over them with right mouse button"); LeftSideButton = new PrefItem <RightSideIcon>("LeftSideButton", new Icons.GameObjectIcon(), "Left side button", "The button that will appear in the left side of the hierarchy\nLooks better with \"Hierarchy Tree\" disabled"); LeftmostButton = new PrefItem <bool>("LeftmostSideButton", true, "Left side button at leftmost", "Put the left button to the leftmost side of the hierachy, if disabled it will be next to the game object name"); MiniLabelType = new PrefItem <MiniLabelType>("MiniLabel", global::EnhancedHierarchy.MiniLabelType.TagAndLayer, "Mini label", "The little label next to the GameObject name"); Trailing = new PrefItem <bool>("Trailing", true, "Trailing", "Append ... when names are bigger than the view area"); AllowSelectingLocked = new PrefItem <bool>("SelectLocked", true, "Allow locked selection (Hierarchy)", "Allow selecting objects that are locked"); AllowSelectingLockedSceneView = new PrefItem <bool>("SelectLockedSV", false, "Allow locked selection (Scene View)", "Allow selecting objects that are locked on scene view\nObjects locked before you change this option will have the previous behaviour, you need to unlock and lock them again to apply this setting"); ChangeAllSelected = new PrefItem <bool>("ChangeAllLocked", true, "Change all selected", "This will make the enable, lock, layer, tag and static buttons affect all selected objects in the hierarchy"); NumericChildExpand = new PrefItem <bool>("ReplaceToggle", false, "Replace default child toggle", "Replace the default toggle for expanding children for a new one that shows the child count"); SmallerMiniLabel = new PrefItem <bool>("SmallerMiniLabel", true, "Smaller font", "Use a smaller font on the minilabel for narrow hierarchies"); CentralizeMiniLabelWhenPossible = new PrefItem <bool>("CentralizeWhenPossible", true, "Centralize when possible", "Centralize minilabel when there's only tag or only layer on it"); HideDefaultLayer = new PrefItem <bool>("HideDefaultLayer", true, "Hide \"Default\" layer", "Hide default layer on minilabel"); HideDefaultTag = new PrefItem <bool>("HideDefaultTag", true, "Hide \"Untagged\" tag", "Hide default tag on minilabel"); HideDefaultIcon = new PrefItem <bool>("HideDefaultIcon", false, "Hide default icon", "Hide the default game object icon"); StaticAskMode = new PrefItem <ChildrenChangeMode>("StaticMode", ChildrenChangeMode.Ask, "Static", "Which flags will be changed when you click on the static toggle"); IconAskMode = new PrefItem <ChildrenChangeMode>("IconAskMode", ChildrenChangeMode.ObjectOnly, "Icon", "Which objects will have their icon changed when you click on the icon button"); LockAskMode = new PrefItem <ChildrenChangeMode>("LockMode", ChildrenChangeMode.ObjectAndChildren, "Lock", "Which objects will be locked when you click on the lock toggle"); LayerAskMode = new PrefItem <ChildrenChangeMode>("LayerMode", ChildrenChangeMode.Ask, "Layer", "Which objects will have their layer changed when you click on the layer button or on the mini label"); TagAskMode = new PrefItem <ChildrenChangeMode>("TagMode", ChildrenChangeMode.ObjectOnly, "Tag", "Which objects will have their tag changed when you click on the tag button or on the mini label"); LineSize = new PrefItem <int>("LineSize", 1, "Line thickness", "Separator line thickness"); LineColor = new PrefItem <Color>("LineColor", DefaultLineColor, "Line color", "The color used on separators line"); OddRowColor = new PrefItem <Color>("OddRow", DefaultOddSortColor, "Odd row color", "The color used on odd rows"); EvenRowColor = new PrefItem <Color>("EvenRow", DefaultEvenSortColor, "Even row color", "The color used on even rows"); var defaultLeftIcons = new LeftSideIcon[] { new Icons.MonoBehaviourIcon(), new Icons.Warnings(), new Icons.SoundIcon() }; var defaultRightIcons = new RightSideIcon[] { new Icons.Active(), new Icons.Lock(), new Icons.Static(), new Icons.PrefabApply() }; var defaultLayerColors = new LayerColor[] { new LayerColor(5, new Color(0.8f, 0f, 1f, EditorGUIUtility.isProSkin ? 0.1f : 0.145f)) }; LeftIcons = new PrefItem <LeftSideIcon[]>("LeftIcons", defaultLeftIcons, "Left Side Icons", "The icons that appear next to the game object name"); RightIcons = new PrefItem <RightSideIcon[]>("RightIcons", defaultRightIcons, "Right Side Icons", "The icons that appear to the rightmost of the hierarchy"); PerLayerRowColors = new PrefItem <LayerColor[]>("PerLayerRowColors", defaultLayerColors, "Per layer row color", "Set a row color for each different layer"); leftIconsList = GenerateReordableListForIcons(LeftIcons); rightIconsList = GenerateReordableListForIcons(RightIcons); rowColorsList = GenerateReordableListForIcons(PerLayerRowColors); rowColorsList.draggable = false; rowColorsList.onAddDropdownCallback = null; rowColorsList.drawElementCallback = (rect, index, focused, active) => { rect.xMin -= EditorGUI.indentLevel * 16f; var value = (LayerColor)rowColorsList.list[index]; var rect1 = rect; var rect2 = rect; var rect3 = rect; rect1.xMax = rect1.xMin + 175f; rect2.xMin = rect1.xMax; rect2.xMax = rect2.xMin + 80f; rect3.xMin = rect2.xMax; value.layer = EditorGUI.LayerField(rect1, value.layer); value.layer = EditorGUI.IntField(rect2, value.layer); value.color = EditorGUI.ColorField(rect3, value.color); if (value.layer > 31 || value.layer < 0) { value.layer = 0; } rowColorsList.list[index] = value; }; }