RectTransform Inspector扩展
1 #if UNITY_EDITOR 2 3 using System.Collections.Generic; 4 using System.Reflection; 5 using UnityEditor; 6 using UnityEngine; 7 8 [CustomEditor(typeof(RectTransform))] 9 [CanEditMultipleObjects] 10 public class CustomRectTransformEditor : UnityEditor.Editor 11 { 12 UnityEditor.Editor _editorInstance; 13 14 List<RectTransform> _rtfList = new List<RectTransform>(); 15 16 private void OnEnable() 17 { 18 if (null != _editorInstance) 19 return; 20 21 var assembly = Assembly.GetAssembly(typeof(UnityEditor.Editor)); 22 if (null == assembly) return; 23 var editor = assembly.GetType("UnityEditor.RectTransformEditor"); 24 if (null == editor) return; 25 if (null != targets) 26 { 27 _editorInstance = CreateEditor(targets, editor); 28 29 AllTargetsCheck(); 30 } 31 } 32 33 void AllTargetsCheck() 34 { 35 for (var i = 0; i < targets.Length; ++i) 36 { 37 var t = targets[i]; 38 //Debug.Log(t.GetType().Name); 39 var rtf = ((RectTransform) t); 40 _rtfList.Add(rtf); 41 } 42 } 43 44 private void OnDisable() 45 { 46 if (null != _editorInstance) 47 { 48 DestroyImmediate(_editorInstance); 49 _editorInstance = null; 50 51 _rtfList.Clear(); 52 } 53 } 54 55 public override void OnInspectorGUI() 56 { 57 if (null != _editorInstance) 58 { 59 _editorInstance.OnInspectorGUI(); 60 } 61 62 //add custom editor gui 63 EditorGUILayout.LabelField("自定义内容"); 64 GUILayout.Button("自定义按钮"); 65 } 66 67 } 68 69 #endif