namespace labelUtility { using System; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEngine; [CustomPropertyDrawer(typeof(LabelSet))] public class LabelSetDrawer : PropertyDrawer { #region Config private float LineSpan = 2; private float LineHeight = 16; private float ButtonSpan = 4; private float ButtonHeight = 32; private LabelSet Instance; private SerializedProperty Name; private SerializedProperty LabelScriptPath; private SerializedProperty LabelScriptName; private SerializedProperty LabePrefix; private SerializedProperty LabelScript; private SerializedProperty ComponentScriptPath; private SerializedProperty ComponentScriptName; private SerializedProperty ComponentPrefix; private SerializedProperty NameExcludeString; private SerializedProperty ComponentScript; private SerializedProperty Languages; private SerializedProperty Prefabs; private SerializedProperty ComponentPurviews; #endregion public override float GetPropertyHeight(SerializedProperty property, GUIContent label) { Instance = (LabelSet) InstanceUtility.GetObject(fieldInfo, property); return Instance.TotalHeight; } public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Instance = (LabelSet) InstanceUtility.GetObject(fieldInfo, property); Name = property.FindPropertyRelative("Name"); LabelScriptPath = property.FindPropertyRelative("LabelScriptPath"); LabelScriptName = property.FindPropertyRelative("LabelScriptName"); LabePrefix = property.FindPropertyRelative("LabePrefix"); LabelScript = property.FindPropertyRelative("LabelScript"); ComponentScriptPath = property.FindPropertyRelative("ComponentScriptPath"); ComponentScriptName = property.FindPropertyRelative("ComponentScriptName"); ComponentPrefix = property.FindPropertyRelative("ComponentPrefix"); NameExcludeString = property.FindPropertyRelative("NameExcludeString"); ComponentScript = property.FindPropertyRelative("ComponentScript"); Languages = property.FindPropertyRelative("Languages"); Prefabs = property.FindPropertyRelative("Prefabs"); ComponentPurviews = property.FindPropertyRelative("ComponentPurviews"); float originY = position.y; position.height = LineHeight; Instance.FoldOut = EditorGUI.Foldout(position, Instance.FoldOut, new GUIContent(Instance.Name)); position.y += LineHeight + LineSpan; if (Instance.FoldOut) { EditorGUI.indentLevel++; position = DrawProperty(position, Name); position = DrawProperty(position, LabelScriptPath); position = DrawProperty(position, LabelScriptName); position = DrawProperty(position, LabePrefix); position = DrawProperty(position, LabelScript); position = DrawProperty(position, ComponentScriptPath); position = DrawProperty(position, ComponentScriptName); position = DrawProperty(position, ComponentPrefix); position = DrawProperty(position, NameExcludeString); position = DrawProperty(position, ComponentScript); position = DrawPropertys(position, Languages); position = DrawPropertys(position, Prefabs); position = DrawButton(position, "Create Label Script", ()=> {LabelUtility.CreateLabelScript(Instance);}); position = DrawButton(position, "Create Component Script", ()=> { LabelUtility.CreateComponentScript(Instance); }); position = DrawButton(position, "Create Label From Prefab", ()=> { LabelUtility.CreateLabelFromPrefab(Instance); }); position = DrawButton(position, "Create Label From LanguageXml", ()=> { LabelUtility.CreateLabelFromLanguageXml(Instance); }); //todo Ôö¼Ó position = DrawPropertys(position, ComponentPurviews); position = DrawButton(position, "Create Components From Prefab", ()=> { LabelUtility.CreateComponentsFromPrefab(Instance); }); } Instance.TotalHeight = position.y - originY; } private Rect DrawButton(Rect position, string name, Action OnClick) { Rect contentPosition = position; contentPosition.height = ButtonHeight; if (GUI.Button(contentPosition, name)) { OnClick.Invoke(); } position.y += ButtonHeight + ButtonSpan; return position; } private Rect DrawProperty(Rect position, SerializedProperty property) { Rect contentPosition = position; contentPosition.height = LineHeight; contentPosition = EditorGUI.PrefixLabel(contentPosition, new GUIContent(property.displayName)); EditorGUI.PropertyField(contentPosition, property, GUIContent.none); position.y += LineHeight + LineSpan; return position; } private Rect DrawPropertys(Rect position, SerializedProperty property) { Rect contentPosition = position; contentPosition.height = LineHeight; contentPosition = EditorGUI.PrefixLabel(contentPosition, new GUIContent(property.displayName)); EditorGUI.PropertyField(contentPosition, property, GUIContent.none, true); if (property.isExpanded) { position.y += (LineHeight + LineSpan)*(property.arraySize + 2); } else { position.y += LineHeight + LineSpan; } return position; } } }