Ruined Town Sectors
This commit is contained in:
@@ -10,82 +10,114 @@ public static class CustomHierarchyDecorator
|
||||
static CustomHierarchyDecorator()
|
||||
{
|
||||
LoadSettings();
|
||||
|
||||
// Rejestracja funkcji odpowiedzialnej za rysowanie niestandardowych nag³ówków
|
||||
EditorApplication.hierarchyWindowItemOnGUI -= OnHierarchyGUI;
|
||||
EditorApplication.hierarchyWindowItemOnGUI += OnHierarchyGUI;
|
||||
|
||||
// Monitorowanie zmian w hierarchii
|
||||
EditorApplication.hierarchyChanged += OnHierarchyChanged;
|
||||
}
|
||||
|
||||
// Aktualizacja ustawieñ
|
||||
public static void UpdateSettings(HierarchyDecoratorSettings newSettings)
|
||||
{
|
||||
settings = newSettings;
|
||||
EditorApplication.RepaintHierarchyWindow();
|
||||
}
|
||||
|
||||
// £adowanie ustawieñ
|
||||
private static void LoadSettings()
|
||||
{
|
||||
settings = AssetDatabase.LoadAssetAtPath<HierarchyDecoratorSettings>("Assets/Scripts/Editor/HierarchyDecoratorSettings.asset");
|
||||
|
||||
if (settings == null)
|
||||
{
|
||||
Debug.LogWarning("HierarchyDecoratorSettings not found! Please create one in Assets/Scripts/Editor folder or check the path.");
|
||||
return;
|
||||
}
|
||||
|
||||
//Debug.Log("HierarchyDecoratorSettings loaded successfully.");
|
||||
}
|
||||
|
||||
// Rysowanie nag³ówka
|
||||
private static void OnHierarchyGUI(int instanceID, Rect selectionRect)
|
||||
{
|
||||
if (settings == null) return;
|
||||
|
||||
GameObject obj = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
|
||||
if (obj != null && obj.name.Contains("="))
|
||||
// 1. Rysowanie Linii Drzewa (Tree Lines) - DODATKOWY BAJER
|
||||
if (settings.showTreeLines)
|
||||
{
|
||||
DrawCustomHeader(selectionRect, obj);
|
||||
|
||||
// Ca³kowite zablokowanie zmiany nazwy w Hierarchii
|
||||
Event e = Event.current;
|
||||
if (e != null && e.type == EventType.MouseDown && e.clickCount == 2 && selectionRect.Contains(e.mousePosition))
|
||||
{
|
||||
// Zapobiegamy aktywacji trybu edycji nazwy
|
||||
GUIUtility.keyboardControl = 0; // Zapobiegamy edytowaniu nazwy
|
||||
e.Use();
|
||||
}
|
||||
DrawTreeLines(selectionRect);
|
||||
}
|
||||
}
|
||||
|
||||
// Funkcja rysuj¹ca niestandardowy nag³ówek
|
||||
private static void DrawCustomHeader(Rect rect, GameObject obj)
|
||||
{
|
||||
if (obj.name.Trim().StartsWith("= Clean")) // <-- ZMIANA TUTAJ
|
||||
GameObject obj = EditorUtility.InstanceIDToObject(instanceID) as GameObject;
|
||||
if (obj == null) return;
|
||||
|
||||
// 2. Sprawdzamy typ nag³ówka
|
||||
|
||||
// Typ: "= Clean" (Pusty separator)
|
||||
if (obj.name.Trim().StartsWith("= Clean"))
|
||||
{
|
||||
// Jeœli nazwa zaczyna siê od "Clean", rysujemy tylko t³o
|
||||
EditorGUI.DrawRect(rect, settings.cleanBackgroundColor);
|
||||
EditorGUI.DrawRect(selectionRect, settings.cleanBackgroundColor);
|
||||
return;
|
||||
}
|
||||
|
||||
// Typ: "# Nazwa" (Subtelny nag³ówek sekcji) - NOWOŒÆ
|
||||
if (obj.name.Trim().StartsWith("#"))
|
||||
{
|
||||
DrawSectionHeader(selectionRect, obj);
|
||||
PreventRename(selectionRect);
|
||||
return;
|
||||
}
|
||||
|
||||
// Typ: "1= Nazwa" (Kolorowy nag³ówek)
|
||||
if (obj.name.Contains("="))
|
||||
{
|
||||
DrawColoredHeader(selectionRect, obj);
|
||||
PreventRename(selectionRect);
|
||||
}
|
||||
}
|
||||
|
||||
// --- NOWOή: Rysowanie linii hierarchii ---
|
||||
private static void DrawTreeLines(Rect rect)
|
||||
{
|
||||
// Unity wciêcie to zazwyczaj 14 pikseli na poziom
|
||||
float indentWidth = 14f;
|
||||
// Obliczamy poziom zagnie¿d¿enia na podstawie pozycji X
|
||||
// (To trik, bo nie mamy dostêpu do obj.transform.parent w tym miejscu ³atwo bez obiektu)
|
||||
// Ale rect.x przesuwa siê w prawo.
|
||||
|
||||
// Rysujemy pionowe linie co 14 pikseli w lewo od rect.x
|
||||
for (float x = rect.x - indentWidth; x > 0; x -= indentWidth)
|
||||
{
|
||||
Rect lineRect = new Rect(x, rect.y, 1f, rect.height);
|
||||
EditorGUI.DrawRect(lineRect, settings.treeLineColor);
|
||||
}
|
||||
}
|
||||
|
||||
// --- NOWOŒÆ: Rysowanie subtelnego nag³ówka ---
|
||||
private static void DrawSectionHeader(Rect rect, GameObject obj)
|
||||
{
|
||||
// Rysujemy t³o
|
||||
EditorGUI.DrawRect(rect, settings.sectionBackgroundColor);
|
||||
|
||||
string text = obj.name.Replace("#", "").Trim();
|
||||
if (settings.sectionUpperCase) text = text.ToUpper();
|
||||
|
||||
GUIStyle style = new GUIStyle(EditorStyles.label)
|
||||
{
|
||||
alignment = TextAnchor.MiddleCenter, // Wyœrodkowanie!
|
||||
fontSize = settings.sectionFontSize,
|
||||
fontStyle = FontStyle.Bold,
|
||||
normal = { textColor = settings.sectionTextColor }
|
||||
};
|
||||
|
||||
// Dodajemy delikatne kreski obok tekstu (opcjonalnie, wygl¹da super)
|
||||
// ------- TEKST -------
|
||||
|
||||
EditorGUI.LabelField(rect, text, style);
|
||||
}
|
||||
|
||||
private static void DrawColoredHeader(Rect rect, GameObject obj)
|
||||
{
|
||||
string[] parts = obj.name.Split(new[] { '=' }, System.StringSplitOptions.RemoveEmptyEntries);
|
||||
if (parts.Length < 1) return;
|
||||
|
||||
string mainText = parts[0].Trim();
|
||||
string descriptionText = parts.Length > 1 ? parts[1].Trim() : ""; // Jeœli istnieje drugi `=`, traktujemy go jako opis
|
||||
string descriptionText = parts.Length > 1 ? parts[1].Trim() : "";
|
||||
|
||||
// Obs³uga identyfikatora koloru
|
||||
int colorIdentifier;
|
||||
bool hasIdentifier = int.TryParse(parts[0].Trim(), out colorIdentifier);
|
||||
|
||||
if (hasIdentifier)
|
||||
{
|
||||
// Jeœli jest identyfikator, przypisujemy g³ówny tekst i opis
|
||||
mainText = parts.Length > 1 ? parts[1].Trim() : parts[0].Trim();
|
||||
descriptionText = parts.Length > 2 ? parts[2].Trim() : ""; // Jeœli jest opis, przypisujemy go
|
||||
descriptionText = parts.Length > 2 ? parts[2].Trim() : "";
|
||||
}
|
||||
|
||||
Color backgroundColor = obj.activeSelf ? settings.defaultBackgroundColor : settings.defaultInactiveBackgroundColor;
|
||||
@@ -94,7 +126,6 @@ public static class CustomHierarchyDecorator
|
||||
|
||||
if (hasIdentifier)
|
||||
{
|
||||
// Sprawdzamy identyfikator koloru i przypisujemy odpowiednie kolory
|
||||
ColorScheme scheme = settings.colorSchemes.FirstOrDefault(s => s.identifier == colorIdentifier);
|
||||
if (scheme != null)
|
||||
{
|
||||
@@ -104,58 +135,42 @@ public static class CustomHierarchyDecorator
|
||||
}
|
||||
}
|
||||
|
||||
// Rysujemy t³o dla obiektu
|
||||
EditorGUI.DrawRect(rect, backgroundColor);
|
||||
|
||||
// Styl dla g³ównego tekstu (wycentrowany)
|
||||
GUIStyle mainTextStyle = new GUIStyle(EditorStyles.boldLabel)
|
||||
{
|
||||
alignment = TextAnchor.MiddleLeft, // Wyrównanie do lewej strony
|
||||
alignment = TextAnchor.MiddleLeft,
|
||||
fontStyle = FontStyle.Bold,
|
||||
normal = { textColor = textColor },
|
||||
wordWrap = false // Wy³¹czenie zawijania tekstu
|
||||
wordWrap = false
|
||||
};
|
||||
|
||||
Rect mainTextRect = new Rect(rect.x + settings.mainTextOffset, rect.y, rect.width - 10, rect.height); // Zmniejszamy szerokoϾ
|
||||
Rect mainTextRect = new Rect(rect.x + settings.mainTextOffset, rect.y, rect.width - 10, rect.height);
|
||||
EditorGUI.LabelField(mainTextRect, new GUIContent(mainText), mainTextStyle);
|
||||
|
||||
// Jeœli istnieje opis, wyœwietlamy go mniejsz¹ czcionk¹ po prawej stronie
|
||||
if (!string.IsNullOrEmpty(descriptionText))
|
||||
{
|
||||
GUIStyle descriptionStyle = new GUIStyle(EditorStyles.label)
|
||||
{
|
||||
alignment = TextAnchor.MiddleLeft, // Zmieniono na wyrównanie do lewej
|
||||
fontSize = settings.descriptionFontSize, // Sta³a czcionka
|
||||
alignment = TextAnchor.MiddleLeft,
|
||||
fontSize = settings.descriptionFontSize,
|
||||
normal = { textColor = descriptionTextColor },
|
||||
wordWrap = false // Wy³¹czenie zawijania tekstu
|
||||
wordWrap = false
|
||||
};
|
||||
|
||||
// Opis wyrównany do koñca g³ównego tekstu, zawsze w tej samej odleg³oœci
|
||||
float descriptionX = rect.x + settings.mainTextOffset + mainTextStyle.CalcSize(new GUIContent(mainText)).x + settings.descriptionOffset;
|
||||
Rect descriptionRect = new Rect(descriptionX, rect.y, rect.width - descriptionX, rect.height); // Dostosowanie szerokoœci do g³ównego tekstu
|
||||
|
||||
Rect descriptionRect = new Rect(descriptionX, rect.y, rect.width - descriptionX, rect.height);
|
||||
EditorGUI.LabelField(descriptionRect, new GUIContent(descriptionText), descriptionStyle);
|
||||
}
|
||||
}
|
||||
|
||||
// Funkcja monitoruj¹ca zmiany w hierarchii (np. zablokowanie dodawania dzieci do separatorów)
|
||||
private static void OnHierarchyChanged()
|
||||
private static void PreventRename(Rect rect)
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
Event e = Event.current;
|
||||
if (e != null && e.type == EventType.MouseDown && e.clickCount == 2 && rect.Contains(e.mousePosition))
|
||||
{
|
||||
GameObject[] cleanSeparators = Object.FindObjectsByType<GameObject>(FindObjectsInactive.Include, FindObjectsSortMode.None)
|
||||
.Where(obj => obj.name.Trim().StartsWith("= Clean")) // <-- ZMIANA TUTAJ
|
||||
.ToArray();
|
||||
|
||||
foreach (var cleanObj in cleanSeparators)
|
||||
{
|
||||
for (int i = cleanObj.transform.childCount - 1; i >= 0; i--)
|
||||
{
|
||||
Transform child = cleanObj.transform.GetChild(i);
|
||||
Undo.SetTransformParent(child, null, "Prevent Child to Clean Separator");
|
||||
Debug.Log($"Blocked child object {child.name} from being added to {cleanObj.name}");
|
||||
}
|
||||
}
|
||||
};
|
||||
GUIUtility.keyboardControl = 0;
|
||||
e.Use();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user