private static void DrawComponentType(Rect rect, int index, bool isActive, bool isFocused) { float w = rect.width; rect.width = 60F; if (GUI.Button(rect, "Type") == true) { pickTypeIndex = index; GenericTypesSelectorWizard.Start("Pick Type", typeof(Component), OnCreate, true, true); } rect.x += rect.width; rect.width = w - 180F; GUI.Label(rect, NGHierarchyEnhancer.colors[index].type == null ? "None" : NGHierarchyEnhancer.colors[index].type.Name, GeneralStyles.VerticalCenterLabel); rect.x += rect.width; rect.width = 60F; EditorGUI.BeginChangeCheck(); NGHierarchyEnhancer.colors[pickTypeIndex].color = EditorGUI.ColorField(rect, NGHierarchyEnhancer.colors[pickTypeIndex].color); if (EditorGUI.EndChangeCheck() == true) { NGHierarchyEnhancer.SerializeComponentColors(); } rect.x += rect.width; EditorGUI.BeginChangeCheck(); NGHierarchyEnhancer.colors[pickTypeIndex].icon = EditorGUI.ObjectField(rect, NGHierarchyEnhancer.colors[pickTypeIndex].icon, typeof(Texture2D), false) as Texture2D; if (EditorGUI.EndChangeCheck() == true) { NGHierarchyEnhancer.SerializeComponentColors(); } }
private static void OnCreate(Type type) { NGHierarchyEnhancer.colors[pickTypeIndex].type = type; NGHierarchyEnhancer.SerializeComponentColors(); }
private static void OnGUISettings() { if (HQ.Settings == null) { return; } HierarchyEnhancerSettings settings = HQ.Settings.Get <HierarchyEnhancerSettings>(); EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); using (BgColorContentRestorer.Get(settings.enable == true ? Color.green : Color.red)) { EditorGUILayout.BeginVertical("ButtonLeft"); { EditorGUILayout.BeginHorizontal(); { settings.enable = NGEditorGUILayout.Switch(LC.G("Enable"), settings.enable); } EditorGUILayout.EndHorizontal(); EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_EnableDescription"), GeneralStyles.WrapLabel); } EditorGUILayout.EndVertical(); } if (EditorGUI.EndChangeCheck() == true) { if (settings.enable == false) { EditorApplication.hierarchyWindowItemOnGUI -= NGHierarchyEnhancer.DrawOverlay; } else { EditorApplication.hierarchyWindowItemOnGUI += NGHierarchyEnhancer.DrawOverlay; } HQ.InvalidateSettings(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_MarginDescription"), GeneralStyles.WrapLabel); settings.margin = EditorGUILayout.FloatField(LC.G("NGHierarchyEnhancer_Margin"), settings.margin); EditorGUILayout.Space(); EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_HoldModifiersDescription"), GeneralStyles.WrapLabel); settings.holdModifiers = (EventModifiers)EditorGUILayout.MaskField(new GUIContent(LC.G("NGHierarchyEnhancer_HoldModifiers")), (int)settings.holdModifiers, NGHierarchyEnhancer.eventModifierNames); EditorGUILayout.Space(); EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_SelectionHoldModifiersDescription"), GeneralStyles.WrapLabel); settings.selectionHoldModifiers = (EventModifiers)EditorGUILayout.MaskField(new GUIContent(LC.G("NGHierarchyEnhancer_SelectionHoldModifiers")), (int)settings.selectionHoldModifiers, NGHierarchyEnhancer.eventModifierNames); if (EditorGUI.EndChangeCheck() == true) { HQ.InvalidateSettings(); } EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_LayersDescription"), GeneralStyles.WrapLabel); float maxLabelWidth = NGHierarchyEnhancer.width; for (int i = 0; i < HierarchyEnhancerSettings.TotalLayers; i++) { string layerName = LayerMask.LayerToName(i); if (layerName == string.Empty) { layerName = "Layer " + i; } Utility.content.text = layerName; float width = GUI.skin.label.CalcSize(Utility.content).x; if (maxLabelWidth < width + 20F) // Add width for the icon. { maxLabelWidth = width + 20F; } } using (LabelWidthRestorer.Get(maxLabelWidth)) { for (int i = 0; i < HierarchyEnhancerSettings.TotalLayers; i++) { string layerName = LayerMask.LayerToName(i); if (layerName == string.Empty) { layerName = "Layer " + i; } EditorGUILayout.BeginHorizontal(); // (Label + icon) + color picker Rect r = GUILayoutUtility.GetRect(maxLabelWidth + 40F, 16F, GUI.skin.label); Utility.content.text = layerName; float width = GUI.skin.label.CalcSize(Utility.content).x; settings.layers[i] = EditorGUI.ColorField(r, layerName, settings.layers[i]); r.width = maxLabelWidth; EditorGUI.DrawRect(r, settings.layers[i]); if (settings.layersIcon[i] != null) { r.x += width + 2F; // Little space before the icon. r.width = 16F; GUI.DrawTexture(r, settings.layersIcon[i], ScaleMode.ScaleToFit); } settings.layersIcon[i] = EditorGUILayout.ObjectField(settings.layersIcon[i], typeof(Texture2D), false) as Texture2D; EditorGUILayout.EndHorizontal(); } } if (EditorGUI.EndChangeCheck() == true) { HQ.InvalidateSettings(); if (NGHierarchyEnhancer.instance != null) { NGHierarchyEnhancer.instance.Repaint(); } } EditorGUI.BeginChangeCheck(); EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_WidthPerComponentDescription"), GeneralStyles.WrapLabel); settings.widthPerComponent = EditorGUILayout.FloatField(LC.G("NGHierarchyEnhancer_WidthPerComponent"), settings.widthPerComponent); if (EditorGUI.EndChangeCheck() == true) { if (settings.widthPerComponent < -1F) { settings.widthPerComponent = -1F; } HQ.InvalidateSettings(); if (NGHierarchyEnhancer.instance != null) { NGHierarchyEnhancer.instance.Repaint(); } } EditorGUI.BeginChangeCheck(); EditorGUILayout.Space(); EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_DrawUnityComponentsDescription"), GeneralStyles.WrapLabel); settings.drawUnityComponents = EditorGUILayout.Toggle(LC.G("NGHierarchyEnhancer_DrawUnityComponents"), settings.drawUnityComponents); if (EditorGUI.EndChangeCheck() == true) { HQ.InvalidateSettings(); if (NGHierarchyEnhancer.instance != null) { NGHierarchyEnhancer.instance.Repaint(); } } EditorGUILayout.Space(); EditorGUILayout.LabelField(LC.G("NGHierarchyEnhancer_ComponentColorsDescription"), GeneralStyles.WrapLabel); if (reorder == null) { NGHierarchyEnhancer.colors = new List <HierarchyEnhancerSettings.ComponentColor>(settings.componentData); NGHierarchyEnhancer.reorder = new ReorderableList(NGHierarchyEnhancer.colors, typeof(HierarchyEnhancerSettings.ComponentColor), true, false, true, true); NGHierarchyEnhancer.reorder.headerHeight = 0F; NGHierarchyEnhancer.reorder.drawElementCallback += NGHierarchyEnhancer.DrawComponentType; NGHierarchyEnhancer.reorder.onReorderCallback += (r) => NGHierarchyEnhancer.SerializeComponentColors(); NGHierarchyEnhancer.reorder.onRemoveCallback += (r) => { r.list.RemoveAt(r.index); NGHierarchyEnhancer.SerializeComponentColors(); }; NGHierarchyEnhancer.reorder.onAddCallback += (r) => { colors.Add(new HierarchyEnhancerSettings.ComponentColor()); NGHierarchyEnhancer.SerializeComponentColors(); }; } reorder.DoLayoutList(); }