LabelSetDrawer.cs 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. namespace labelUtility
  2. {
  3. using System;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using UnityEditor;
  7. using UnityEngine;
  8. [CustomPropertyDrawer(typeof(LabelSet))]
  9. public class LabelSetDrawer : PropertyDrawer
  10. {
  11. #region Config
  12. private float LineSpan = 2;
  13. private float LineHeight = 16;
  14. private float ButtonSpan = 4;
  15. private float ButtonHeight = 32;
  16. private LabelSet Instance;
  17. private SerializedProperty Name;
  18. private SerializedProperty LabelScriptPath;
  19. private SerializedProperty LabelScriptName;
  20. private SerializedProperty LabePrefix;
  21. private SerializedProperty LabelScript;
  22. private SerializedProperty ComponentScriptPath;
  23. private SerializedProperty ComponentScriptName;
  24. private SerializedProperty ComponentPrefix;
  25. private SerializedProperty NameExcludeString;
  26. private SerializedProperty RegistString;
  27. //private SerializedProperty RegistPrefix;
  28. // private SerializedProperty RegistSuffix;
  29. private SerializedProperty RegistExtraLines;
  30. private SerializedProperty ComponentScript;
  31. private SerializedProperty Languages;
  32. private SerializedProperty Prefabs;
  33. private SerializedProperty ComponentPurviews;
  34. #endregion
  35. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  36. {
  37. Instance = (LabelSet) InstanceUtility.GetObject(fieldInfo, property);
  38. return Instance.TotalHeight;
  39. }
  40. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  41. {
  42. Instance = (LabelSet) InstanceUtility.GetObject(fieldInfo, property);
  43. Name = property.FindPropertyRelative("Name");
  44. LabelScriptPath = property.FindPropertyRelative("LabelScriptPath");
  45. LabelScriptName = property.FindPropertyRelative("LabelScriptName");
  46. LabePrefix = property.FindPropertyRelative("LabePrefix");
  47. LabelScript = property.FindPropertyRelative("LabelScript");
  48. ComponentScriptPath = property.FindPropertyRelative("ComponentScriptPath");
  49. ComponentScriptName = property.FindPropertyRelative("ComponentScriptName");
  50. ComponentPrefix = property.FindPropertyRelative("ComponentPrefix");
  51. NameExcludeString = property.FindPropertyRelative("NameExcludeString");
  52. RegistString = property.FindPropertyRelative("RegistString");
  53. //RegistPrefix = property.FindPropertyRelative("RegistPrefix");
  54. //RegistSuffix = property.FindPropertyRelative("RegistSuffix");
  55. RegistExtraLines = property.FindPropertyRelative("RegistExtraLines");
  56. ComponentScript = property.FindPropertyRelative("ComponentScript");
  57. Languages = property.FindPropertyRelative("Languages");
  58. Prefabs = property.FindPropertyRelative("Prefabs");
  59. ComponentPurviews = property.FindPropertyRelative("ComponentPurviews");
  60. float originY = position.y;
  61. position.height = LineHeight;
  62. Instance.FoldOut = EditorGUI.Foldout(position, Instance.FoldOut, new GUIContent(Instance.Name));
  63. position.y += LineHeight + LineSpan;
  64. if (Instance.FoldOut)
  65. {
  66. EditorGUI.indentLevel++;
  67. position = DrawProperty(position, Name);
  68. position = DrawProperty(position, LabelScriptPath);
  69. position = DrawProperty(position, LabelScriptName);
  70. position = DrawProperty(position, LabePrefix);
  71. position = DrawProperty(position, LabelScript);
  72. position = DrawProperty(position, ComponentScriptPath);
  73. position = DrawProperty(position, ComponentScriptName);
  74. position = DrawProperty(position, ComponentPrefix);
  75. position = DrawProperty(position, NameExcludeString);
  76. position = DrawProperty(position, RegistString);
  77. // position = DrawProperty(position, RegistPrefix);
  78. //position = DrawProperty(position, RegistSuffix);
  79. position = DrawPropertys(position, RegistExtraLines);
  80. position = DrawProperty(position, ComponentScript);
  81. position = DrawPropertys(position, Languages);
  82. position = DrawPropertys(position, Prefabs);
  83. position = DrawButton(position, "Create Label Script", () => { LabelUtility.CreateLabelScript(Instance); });
  84. position = DrawButton(position, "Create Component Script", () => { LabelUtility.CreateComponentScript(Instance); });
  85. position = DrawButton(position, "Create Label From Prefab", () => { LabelUtility.CreateLabelFromPrefab(Instance); });
  86. position = DrawButton(position, "Create Label From LanguageXml", () => { LabelUtility.CreateLabelFromLanguageXml(Instance); }); //todo Ôö¼Ó
  87. position = DrawPropertys(position, ComponentPurviews);
  88. position = DrawButton(position, "Create Components From Prefab", () => { LabelUtility.CreateComponentsFromPrefab(Instance); });
  89. }
  90. Instance.TotalHeight = position.y - originY;
  91. }
  92. private Rect DrawButton(Rect position, string name, Action OnClick)
  93. {
  94. Rect contentPosition = position;
  95. contentPosition.height = ButtonHeight;
  96. if (GUI.Button(contentPosition, name))
  97. {
  98. OnClick.Invoke();
  99. }
  100. position.y += ButtonHeight + ButtonSpan;
  101. return position;
  102. }
  103. private Rect DrawProperty(Rect position, SerializedProperty property)
  104. {
  105. Rect contentPosition = position;
  106. contentPosition.height = LineHeight;
  107. contentPosition = EditorGUI.PrefixLabel(contentPosition, new GUIContent(property.displayName));
  108. EditorGUI.PropertyField(contentPosition, property, GUIContent.none);
  109. position.y += LineHeight + LineSpan;
  110. return position;
  111. }
  112. private Rect DrawPropertys(Rect position, SerializedProperty property)
  113. {
  114. Rect contentPosition = position;
  115. contentPosition.height = LineHeight;
  116. contentPosition = EditorGUI.PrefixLabel(contentPosition, new GUIContent(property.displayName));
  117. EditorGUI.PropertyField(contentPosition, property, GUIContent.none, true);
  118. if (property.isExpanded)
  119. {
  120. position.y += (LineHeight + LineSpan)*(property.arraySize + 2);
  121. }
  122. else
  123. {
  124. position.y += LineHeight + LineSpan;
  125. }
  126. return position;
  127. }
  128. }
  129. }