200 lines
6.7 KiB
C#
200 lines
6.7 KiB
C#
using UnityEditor;
|
|
using UnityEngine;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
|
|
public class HeaderCreatorWindow : EditorWindow
|
|
{
|
|
private string objectName = "New GameObject";
|
|
private string headerDescription = "";
|
|
private int selectedIdentifier = 1;
|
|
private bool resetTransform = true;
|
|
|
|
private static HierarchyDecoratorSettings settings;
|
|
private Vector2 scrollPosition;
|
|
private Dictionary<int, GUIStyle> colorStyles;
|
|
|
|
[MenuItem("GameObject/Create Custom Header", false, 0)]
|
|
[MenuItem("GameObject/Create Empty", false, 0)]
|
|
public static void ShowWindow()
|
|
{
|
|
HeaderCreatorWindow window = GetWindow<HeaderCreatorWindow>(true, "Create Object");
|
|
window.minSize = new Vector2(320, 400); // Jeszcze trochê wiêksze
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
settings = AssetDatabase.LoadAssetAtPath<HierarchyDecoratorSettings>("Assets/Scripts/Editor/HierarchyDecoratorSettings.asset");
|
|
|
|
if (settings == null)
|
|
{
|
|
Debug.LogError("Settings not found!");
|
|
Close();
|
|
return;
|
|
}
|
|
|
|
if (settings.colorSchemes.Count > 0)
|
|
{
|
|
selectedIdentifier = settings.colorSchemes.First().identifier;
|
|
InitializeButtonStyles();
|
|
}
|
|
}
|
|
|
|
private void OnGUI()
|
|
{
|
|
if (settings == null) return;
|
|
|
|
EditorGUILayout.LabelField("Create a new object", EditorStyles.boldLabel);
|
|
objectName = EditorGUILayout.TextField("Name", objectName);
|
|
|
|
EditorGUILayout.Space(10);
|
|
EditorGUILayout.LabelField("Description (Optional)", EditorStyles.miniBoldLabel);
|
|
headerDescription = EditorGUILayout.TextField(headerDescription);
|
|
|
|
EditorGUILayout.Space(5);
|
|
resetTransform = EditorGUILayout.ToggleLeft("Reset Transform (Pos 0, Scale 1)", resetTransform);
|
|
|
|
EditorGUILayout.Space(10);
|
|
EditorGUILayout.LabelField("Type 1: Colored Header", EditorStyles.boldLabel);
|
|
|
|
if (settings.colorSchemes.Count > 0)
|
|
{
|
|
DrawColorSelectionGrid();
|
|
EditorGUILayout.Space(2);
|
|
if (GUILayout.Button("Create Colored Header", GUILayout.Height(30)))
|
|
{
|
|
CreateHeaderObject();
|
|
Close();
|
|
}
|
|
}
|
|
|
|
EditorGUILayout.Space(10);
|
|
EditorGUILayout.LabelField("Type 2: Separators", EditorStyles.boldLabel);
|
|
|
|
// PRZYCISK SEKCJI (SUBTELNY TEKST)
|
|
GUI.backgroundColor = new Color(0.8f, 0.8f, 0.8f);
|
|
if (GUILayout.Button("Create Section Header (Subtle Text)", GUILayout.Height(25)))
|
|
{
|
|
CreateSectionHeader(); // Nowa funkcja
|
|
Close();
|
|
}
|
|
|
|
EditorGUILayout.Space(2);
|
|
|
|
// PRZYCISK CZYSTEGO SEPARATORA
|
|
GUI.backgroundColor = new Color(0.4f, 0.4f, 0.45f);
|
|
if (GUILayout.Button("Create Clean Separator (Empty)", GUILayout.Height(25)))
|
|
{
|
|
CreateCleanSeparator();
|
|
Close();
|
|
}
|
|
|
|
GUI.backgroundColor = Color.white;
|
|
|
|
EditorGUILayout.Space(10);
|
|
if (GUILayout.Button("Create Simple Empty", GUILayout.Height(20)))
|
|
{
|
|
CreateSimpleEmptyObject();
|
|
Close();
|
|
}
|
|
}
|
|
|
|
private void DrawColorSelectionGrid()
|
|
{
|
|
// ... (bez zmian) ...
|
|
scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition, GUILayout.Height(60));
|
|
int columns = 5;
|
|
int buttonsInRow = 0;
|
|
GUILayout.BeginHorizontal();
|
|
foreach (var scheme in settings.colorSchemes)
|
|
{
|
|
GUIStyle buttonStyle = colorStyles[scheme.identifier];
|
|
if (GUILayout.Button(scheme.identifier.ToString(), buttonStyle, GUILayout.MinWidth(40), GUILayout.Height(25)))
|
|
{
|
|
selectedIdentifier = scheme.identifier;
|
|
}
|
|
if (Event.current.type == EventType.Repaint && scheme.identifier == selectedIdentifier)
|
|
{
|
|
Rect buttonRect = GUILayoutUtility.GetLastRect();
|
|
EditorGUI.DrawRect(buttonRect, new Color(0.5f, 0.5f, 0.5f, 0.4f));
|
|
}
|
|
buttonsInRow++;
|
|
if (buttonsInRow >= columns) { GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(); buttonsInRow = 0; }
|
|
}
|
|
GUILayout.EndHorizontal();
|
|
EditorGUILayout.EndScrollView();
|
|
}
|
|
|
|
private void ApplyTransformReset(GameObject obj)
|
|
{
|
|
if (resetTransform)
|
|
{
|
|
obj.transform.localPosition = Vector3.zero;
|
|
obj.transform.localRotation = Quaternion.identity;
|
|
obj.transform.localScale = Vector3.one;
|
|
}
|
|
}
|
|
|
|
private void CreateHeaderObject()
|
|
{
|
|
string finalName = $"{selectedIdentifier}={objectName.Trim()}";
|
|
if (!string.IsNullOrEmpty(headerDescription.Trim())) finalName += $"={headerDescription.Trim()}";
|
|
CreateObject(finalName, "Create Custom Header");
|
|
}
|
|
|
|
private void CreateSimpleEmptyObject()
|
|
{
|
|
CreateObject(objectName, "Create Simple Empty");
|
|
}
|
|
|
|
private void CreateCleanSeparator()
|
|
{
|
|
CreateObject("= Clean", "Create Clean Separator");
|
|
}
|
|
|
|
// --- NOWA FUNKCJA: TWORZENIE SEKCJI # ---
|
|
private void CreateSectionHeader()
|
|
{
|
|
// Tworzymy nazwê zaczynaj¹c¹ siê od #
|
|
string name = objectName.Trim();
|
|
if (string.IsNullOrEmpty(name)) name = "SECTION";
|
|
|
|
string finalName = $"# {name}";
|
|
CreateObject(finalName, "Create Section Header");
|
|
}
|
|
|
|
private void CreateObject(string name, string undoName)
|
|
{
|
|
GameObject obj = new GameObject(name);
|
|
Undo.RegisterCreatedObjectUndo(obj, undoName);
|
|
GameObjectUtility.SetParentAndAlign(obj, Selection.activeObject as GameObject);
|
|
ApplyTransformReset(obj);
|
|
Selection.activeObject = obj;
|
|
}
|
|
|
|
private void InitializeButtonStyles()
|
|
{
|
|
colorStyles = new Dictionary<int, GUIStyle>();
|
|
foreach (var scheme in settings.colorSchemes)
|
|
{
|
|
GUIStyle style = new GUIStyle(EditorStyles.miniButton);
|
|
Texture2D backgroundTexture = MakeTex(1, 1, scheme.activeBackgroundColor);
|
|
style.normal.background = backgroundTexture;
|
|
style.active.background = backgroundTexture;
|
|
style.normal.textColor = scheme.activeTextColor;
|
|
style.alignment = TextAnchor.MiddleCenter;
|
|
style.fontStyle = FontStyle.Bold;
|
|
colorStyles.Add(scheme.identifier, style);
|
|
}
|
|
}
|
|
|
|
private Texture2D MakeTex(int width, int height, Color col)
|
|
{
|
|
Color[] pix = new Color[width * height];
|
|
for (int i = 0; i < pix.Length; ++i) pix[i] = col;
|
|
Texture2D result = new Texture2D(width, height);
|
|
result.SetPixels(pix);
|
|
result.Apply();
|
|
return result;
|
|
}
|
|
} |