folders fix
This commit is contained in:
161
Assets/Scripts/Editor/CustomHierarchyDecorator.cs
Normal file
161
Assets/Scripts/Editor/CustomHierarchyDecorator.cs
Normal file
@@ -0,0 +1,161 @@
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
using System.Linq;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public static class CustomHierarchyDecorator
|
||||
{
|
||||
private static HierarchyDecoratorSettings settings;
|
||||
|
||||
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("="))
|
||||
{
|
||||
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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Funkcja rysuj¹ca niestandardowy nag³ówek
|
||||
private static void DrawCustomHeader(Rect rect, GameObject obj)
|
||||
{
|
||||
if (obj.name.Trim().StartsWith("= Clean")) // <-- ZMIANA TUTAJ
|
||||
{
|
||||
// Jeœli nazwa zaczyna siê od "Clean", rysujemy tylko t³o
|
||||
EditorGUI.DrawRect(rect, settings.cleanBackgroundColor);
|
||||
return;
|
||||
}
|
||||
|
||||
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
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
Color backgroundColor = obj.activeSelf ? settings.defaultBackgroundColor : settings.defaultInactiveBackgroundColor;
|
||||
Color textColor = obj.activeSelf ? settings.defaultTextColor : settings.defaultInactiveTextColor;
|
||||
Color descriptionTextColor = settings.descriptionTextColor;
|
||||
|
||||
if (hasIdentifier)
|
||||
{
|
||||
// Sprawdzamy identyfikator koloru i przypisujemy odpowiednie kolory
|
||||
ColorScheme scheme = settings.colorSchemes.FirstOrDefault(s => s.identifier == colorIdentifier);
|
||||
if (scheme != null)
|
||||
{
|
||||
backgroundColor = obj.activeSelf ? scheme.activeBackgroundColor : scheme.inactiveBackgroundColor;
|
||||
textColor = obj.activeSelf ? scheme.activeTextColor : scheme.inactiveTextColor;
|
||||
descriptionTextColor = scheme.activeTextColor;
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
fontStyle = FontStyle.Bold,
|
||||
normal = { textColor = textColor },
|
||||
wordWrap = false // Wy³¹czenie zawijania tekstu
|
||||
};
|
||||
|
||||
Rect mainTextRect = new Rect(rect.x + settings.mainTextOffset, rect.y, rect.width - 10, rect.height); // Zmniejszamy szerokoϾ
|
||||
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
|
||||
normal = { textColor = descriptionTextColor },
|
||||
wordWrap = false // Wy³¹czenie zawijania tekstu
|
||||
};
|
||||
|
||||
// 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
|
||||
|
||||
EditorGUI.LabelField(descriptionRect, new GUIContent(descriptionText), descriptionStyle);
|
||||
}
|
||||
}
|
||||
|
||||
// Funkcja monitoruj¹ca zmiany w hierarchii (np. zablokowanie dodawania dzieci do separatorów)
|
||||
private static void OnHierarchyChanged()
|
||||
{
|
||||
EditorApplication.delayCall += () =>
|
||||
{
|
||||
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}");
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -1,11 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8c30c8eec324efa4da95a4c6290af0c9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
guid: ab24c60b91e1a52408877997339ec28f
|
||||
15
Assets/Scripts/Editor/HeaderWithBackgroundAttribute.cs
Normal file
15
Assets/Scripts/Editor/HeaderWithBackgroundAttribute.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using UnityEngine;
|
||||
|
||||
// Atrybut, który bêdzie u¿ywany do oznaczania nag³ówków z t³em
|
||||
public class HeaderWithBackgroundAttribute : PropertyAttribute
|
||||
{
|
||||
public string HeaderText; // Tekst nag³ówka
|
||||
public Color BackgroundColor; // Kolor t³a
|
||||
|
||||
// Konstruktor, który ustawia tekst i kolor t³a
|
||||
public HeaderWithBackgroundAttribute(string headerText, float r, float g, float b)
|
||||
{
|
||||
HeaderText = headerText;
|
||||
BackgroundColor = new Color(r, g, b, 1f); // Kolor z pe³n¹ przezroczystoœci¹
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b62518d902db2fb4191ed45c85857660
|
||||
Reference in New Issue
Block a user