Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEditor;
- /**
- * Hierarchy Section Creator
- * Created by Jack Davenport (@memedealer#6607) 2019
- * Updated: 16/9/2020
- *
- * HOW TO USE:
- * 1) Create a folder in your Assets called "Editor"
- * 2) Download this script, save it as "HierarchySection.cs"
- * 3) Place it in the Editor folder you created
- * 4) Go to "Window > General > Create Hierarchy Section" to use
- */
- namespace JackDavenport.Editor {
- public class HierarchySection : EditorWindow
- {
- string spacerName = "New Section";
- int width = 30;
- void OnGUI()
- {
- spacerName = EditorGUILayout.TextField("Section Name", spacerName);
- width = Mathf.Max(1, EditorGUILayout.IntField("Width", width));
- EditorGUILayout.Space();
- string shortName = spacerName.Trim();
- string error = null;
- if(shortName.Length <= 0) {
- error = "Please enter a name!";
- } else if(shortName.Length > width) {
- error = "Name is longer than allowed width!";
- }
- if (error != null) {
- EditorGUILayout.HelpBox(error, MessageType.Error);
- } else {
- shortName = GenerateText(shortName);
- EditorGUILayout.LabelField("Preview", EditorStyles.boldLabel);
- EditorGUILayout.LabelField(shortName);
- }
- EditorGUILayout.Space();
- EditorGUI.BeginDisabledGroup(error != null);
- if (GUILayout.Button("Create")) {
- CreateItem(shortName);
- }
- EditorGUI.EndDisabledGroup();
- }
- void CreateItem(string objectName)
- {
- GameObject obj = new GameObject(objectName);
- obj.tag = "EditorOnly";
- obj.isStatic = true;
- }
- string GenerateText(string name)
- {
- int padding = (width - name.Length) / 2;
- string text = "|";
- for (int i = 0; i < padding; i++) {
- text += "-";
- }
- text += name;
- for (int i = 0; i < padding; i++) {
- text += "-";
- }
- return text + "|";
- }
- [MenuItem("Window/General/Create Hierarchy Section")]
- static void OpenWindow()
- {
- GetWindow<HierarchySection>("Create Hierarchy Section").Show();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement