//--------------------------------------------------------------------- // Helpers //--------------------------------------------------------------------- private static void DrawCustomIcon(HierarchyItem hierarchyItem, Rect selectionRect) { if (hierarchyItem == null || !hierarchyItem.HasIcon()) { return; } DrawCustomIcon(hierarchyItem.Icon, selectionRect); }
//--------------------------------------------------------------------- // Messages //--------------------------------------------------------------------- public override void OnGUI() { base.OnGUI(); ChangeWindowSize(_currentHierarchyItem.IsIconCustom, _currentHierarchyItem.IsBackgroundCustom); var rect = _windowRect; // Window Background var borderColor = EditorGUIUtility.isProSkin ? new Color(0.13f, 0.13f, 0.13f) : new Color(0.51f, 0.51f, 0.51f); EditorGUI.DrawRect(_windowRect, borderColor); var backgroundColor = EditorGUIUtility.isProSkin ? new Color(0.18f, 0.18f, 0.18f) : new Color(0.83f, 0.83f, 0.83f); EditorGUI.DrawRect(_backgroundRect, backgroundColor); // Type rect.x += 0.5f * PADDING; rect.y += PADDING; rect.width = LABELS_WIDTH - PADDING; rect.height = LINE_HEIGHT; _currentHierarchyItem.Type = (KeyType)EditorGUI.EnumPopup(rect, _currentHierarchyItem.Type); rect.x += LABELS_WIDTH; rect.y = _windowRect.y + PADDING; rect.width = _windowRect.width - LABELS_WIDTH - PADDING; GUI.enabled = false; if (_selectedObjects.Count == 1) { if (_currentHierarchyItem.Type == KeyType.Object) { EditorGUI.ObjectField(rect, _currentObject, typeof(GameObject), true); } else { EditorGUI.TextField(rect, _currentObject.name); } } else { EditorGUI.TextField(rect, GUIContent.none, _selectedObjects.Count + " selected"); } GUI.enabled = true; // Icon rect.x = 0.5f * PADDING; rect.y += LINE_HEIGHT + SPACING * 4f; EditorGUI.LabelField(rect, "Icon"); rect.x += 0.5f * PADDING; rect.y += LINE_HEIGHT + SPACING; rect.width = ICON_WIDTH_SMALL; if (_currentHierarchyItem.HasIcon()) { GUI.DrawTexture(rect, _currentHierarchyItem.Icon); } rect.width = _windowRect.width - LABELS_WIDTH - PADDING; rect.x += LABELS_WIDTH - 0.5f * PADDING; rect.y -= LINE_HEIGHT + 1.5f * SPACING; DrawIconPopupMenu(rect); // Custom Icon Field if (_currentHierarchyItem.IsIconCustom) { rect.y += LINE_HEIGHT + 2f; _currentHierarchyItem.Icon = (Texture2D)EditorGUI.ObjectField(rect, _currentHierarchyItem.Icon, typeof(Texture2D), false); } rect.y += _currentHierarchyItem.IsIconCustom ? LINE_HEIGHT + 0.2f * SPACING : LINE_HEIGHT + SPACING; _currentHierarchyItem.IsIconRecursive = EditorGUI.Toggle(rect, _currentHierarchyItem.IsIconRecursive); rect.x += ICON_WIDTH_SMALL; EditorGUI.LabelField(rect, "Recursive"); // Background rect.x = 0.5f * PADDING; rect.y += LINE_HEIGHT + SPACING * 3; EditorGUI.LabelField(rect, "Background"); rect.x += 0.5f * PADDING; rect.y += LINE_HEIGHT + SPACING; rect.width = ICON_WIDTH_SMALL * 3f; if (_currentHierarchyItem.HasBackground()) { GUI.DrawTexture(rect, _currentHierarchyItem.Background); } rect.width = _windowRect.width - LABELS_WIDTH - PADDING; rect.x += LABELS_WIDTH - 0.5f * PADDING; rect.y -= LINE_HEIGHT + 1.5f * SPACING; DrawBackgroundPopupMenu(rect); // Custom Icon Field if (_currentHierarchyItem.IsBackgroundCustom) { rect.y += LINE_HEIGHT + 2f * SPACING; _currentHierarchyItem.Background = (Texture2D)EditorGUI.ObjectField(rect, _currentHierarchyItem.Background, typeof(Texture2D), false); } rect.y += _currentHierarchyItem.IsBackgroundCustom ? LINE_HEIGHT + 0.2f * SPACING : LINE_HEIGHT + SPACING; _currentHierarchyItem.IsBackgroundRecursive = EditorGUI.Toggle(rect, _currentHierarchyItem.IsBackgroundRecursive); rect.x += ICON_WIDTH_SMALL; EditorGUI.LabelField(rect, "Recursive"); // Buttons rect.x = PADDING; rect.y = position.height - LINE_HEIGHT - 0.75f * PADDING; rect.width = ICON_WIDTH_SMALL; ButtonSettings(rect); rect.x += ICON_WIDTH_SMALL + 0.75f * PADDING; ButtonDefault(rect); rect.x = WINDOW_WIDTH - 2f * (BUTTON_WIDTH + PADDING); rect.width = BUTTON_WIDTH; ButtonCancel(rect); rect.x = WINDOW_WIDTH - BUTTON_WIDTH - PADDING; ButtonApply(rect); }