Advertisement
Muk99

ComponentSorter

Jul 30th, 2015
280
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.81 KB | None | 0 0
  1. using UnityEditor;
  2. using UnityEditorInternal;
  3. using UnityEngine;
  4.  
  5. internal sealed class Reorder : EditorWindow {
  6.  
  7.     [MenuItem("Window/Reorder")]
  8.     private static void Init() {
  9.         GetWindow<Reorder>().Show();
  10.     }
  11.  
  12.     private GameObject selected;
  13.     private Vector2 scroll;
  14.  
  15.     private void OnGUI() {
  16.  
  17.         EditorGUILayout.BeginVertical("HelpBox");
  18.         EditorGUILayout.LabelField("Select Gameobject", EditorStyles.boldLabel);
  19.         selected = (GameObject)EditorGUILayout.ObjectField(selected, typeof(GameObject),true);
  20.         EditorGUILayout.Separator();
  21.         EditorGUILayout.EndVertical();
  22.  
  23.         scroll = EditorGUILayout.BeginScrollView(scroll, false, false);
  24.         if(selected != null)
  25.             for(int i = 0; i < selectionComponents.Length; i++) {
  26.  
  27.                 EditorGUILayout.BeginHorizontal("HelpBox");
  28.  
  29.                 GUI.enabled = i >= 2;
  30.                 if(GUILayout.Button("", "OL Plus", GUILayout.Width(15f)))
  31.                     ComponentUtility.MoveComponentUp(selectionComponents[i]);
  32.  
  33.                 GUI.enabled = i < selectionComponents.Length - 1 && i >= 1;
  34.                 if(GUILayout.Button("", "OL Minus", GUILayout.Width(15f)))
  35.                     ComponentUtility.MoveComponentDown(selectionComponents[i]);
  36.  
  37.                 GUI.enabled = true;
  38.                 var contend = EditorGUIUtility.ObjectContent(selectionComponents[i], typeof(Component));
  39.                 contend.text = selectionComponents[i].GetType().Name;
  40.                 EditorGUILayout.LabelField(contend, EditorStyles.boldLabel);
  41.  
  42.                 EditorGUILayout.EndHorizontal();
  43.             }
  44.         EditorGUILayout.EndScrollView();
  45.     }
  46.  
  47.     private Component[] selectionComponents {
  48.         get {
  49.             return selected.GetComponents<Component>();
  50.         }
  51.     }
  52. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement