using UnityEditor; using UnityEngine; public class PrefabGroupSettingsWindow : EditorWindow { private PrefabGroup targetGroup; private PrefabBrowserDatabase database; private string tempGroupName; private Color tempGroupColor; private bool tempUseLightText; // NOWA METODA: Tworzy okno jako elegancki dropdown pod przyciskiem. public static void ShowAsDropDown(Rect buttonRect, PrefabGroup groupToEdit, PrefabBrowserDatabase db) { PrefabGroupSettingsWindow window = CreateInstance(); // Ustawiamy docelową grupę dla tej konkretnej instancji okna window.SetTarget(groupToEdit, db); // Ustawiamy rozmiar naszego dropdownu Vector2 windowSize = new Vector2(250, 150); window.position = new Rect(buttonRect.x, buttonRect.yMax, 0, 0); // Pozycja początkowa // Wyświetlamy okno window.ShowAsDropDown(buttonRect, windowSize); } // Metoda, która inicjalizuje dane dla tego konkretnego okna. private void SetTarget(PrefabGroup group, PrefabBrowserDatabase db) { targetGroup = group; database = db; if (targetGroup != null) { tempGroupName = targetGroup.groupName; tempGroupColor = targetGroup.groupColor; tempUseLightText = targetGroup.useLightText; } } private void OnGUI() { if (targetGroup == null) { Close(); return; } // Dodajemy trochę marginesu, żeby kontrolki nie były przyklejone do krawędzi EditorGUILayout.BeginVertical(new GUIStyle { padding = new RectOffset(10, 10, 10, 10) }); EditorGUILayout.LabelField("Edit Group", EditorStyles.boldLabel); EditorGUILayout.Space(5); tempGroupName = EditorGUILayout.TextField("Group Name", tempGroupName); tempGroupColor = EditorGUILayout.ColorField("Group Color", tempGroupColor); tempUseLightText = EditorGUILayout.Toggle("Use Light Text", tempUseLightText); EditorGUILayout.Space(10); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Save")) { targetGroup.groupName = tempGroupName; targetGroup.groupColor = tempGroupColor; targetGroup.useLightText = tempUseLightText; EditorUtility.SetDirty(database); AssetDatabase.SaveAssets(); Close(); } if (GUILayout.Button("Delete")) { if (EditorUtility.DisplayDialog("Delete Group", $"Are you sure you want to permanently delete the group '{targetGroup.groupName}'?", "Yes, Delete", "Cancel")) { database.groups.Remove(targetGroup); EditorUtility.SetDirty(database); AssetDatabase.SaveAssets(); Close(); } } EditorGUILayout.EndHorizontal(); EditorGUILayout.EndVertical(); } }