123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- 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 RegistString;
- //private SerializedProperty RegistPrefix;
- // private SerializedProperty RegistSuffix;
- private SerializedProperty RegistExtraLines;
- 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");
- RegistString = property.FindPropertyRelative("RegistString");
- //RegistPrefix = property.FindPropertyRelative("RegistPrefix");
- //RegistSuffix = property.FindPropertyRelative("RegistSuffix");
- RegistExtraLines = property.FindPropertyRelative("RegistExtraLines");
- 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, RegistString);
- // position = DrawProperty(position, RegistPrefix);
- //position = DrawProperty(position, RegistSuffix);
- position = DrawPropertys(position, RegistExtraLines);
- 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;
- }
- }
- }
|