AssetBundleGroupDrawer.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. namespace assetBundleUtility
  2. {
  3. using System;
  4. using UnityEditor;
  5. using UnityEngine;
  6. [CustomPropertyDrawer(typeof(AssetBundleGroup))]
  7. public class AssetBundleGroupDrawer : PropertyDrawer
  8. {
  9. #region Config
  10. private float LineSpan = 2;
  11. private float LineHeight = 16;
  12. private float ButtonSpan = 4;
  13. private float ButtonHeight = 32;
  14. private AssetBundleGroup Instance;
  15. private SerializedProperty MD5FileName;
  16. private SerializedProperty MD5DictionaryFileName;
  17. private SerializedProperty OutputPath;
  18. private SerializedProperty AssetBundleSets;
  19. #endregion
  20. public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
  21. {
  22. Instance = (AssetBundleGroup)InstanceUtility.GetObject(fieldInfo, property);
  23. return Instance.TotalHeight;
  24. }
  25. public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
  26. {
  27. Instance = (AssetBundleGroup) InstanceUtility.GetObject(fieldInfo, property);
  28. MD5FileName = property.FindPropertyRelative("MD5FileName");
  29. MD5DictionaryFileName = property.FindPropertyRelative("MD5DictionaryFileName");
  30. OutputPath = property.FindPropertyRelative("OutputPath");
  31. AssetBundleSets = property.FindPropertyRelative("AssetBundleSets");
  32. float originY = position.y;
  33. position.height = LineHeight;
  34. EditorGUI.indentLevel++;
  35. position = DrawProperty(position, MD5FileName);
  36. position = DrawProperty(position, MD5DictionaryFileName);
  37. position = DrawProperty(position, OutputPath);
  38. position = DrawPropertys(position, AssetBundleSets);
  39. position = DrawButton(position, "Create MD5File And MD5DictionaryFile", Instance.CreateMD5FileAndMD5DictionaryFile);
  40. Instance.TotalHeight = position.y - originY;
  41. }
  42. private Rect DrawButton(Rect position, string name, Action OnClick)
  43. {
  44. Rect contentPosition = position;
  45. contentPosition.height = ButtonHeight;
  46. if (GUI.Button(contentPosition, name))
  47. {
  48. OnClick.Invoke();
  49. }
  50. position.y += ButtonHeight + ButtonSpan;
  51. return position;
  52. }
  53. private Rect DrawProperty(Rect position, SerializedProperty property)
  54. {
  55. Rect contentPosition = position;
  56. contentPosition.height = LineHeight;
  57. contentPosition = EditorGUI.PrefixLabel(contentPosition, new GUIContent(property.displayName));
  58. EditorGUI.PropertyField(contentPosition, property, GUIContent.none);
  59. position.y += LineHeight + LineSpan;
  60. return position;
  61. }
  62. private Rect DrawPropertys(Rect position, SerializedProperty property)
  63. {
  64. Rect contentPosition = position;
  65. contentPosition.height = LineHeight;
  66. contentPosition = EditorGUI.PrefixLabel(contentPosition, new GUIContent(property.displayName));
  67. EditorGUI.PropertyField(contentPosition, property, GUIContent.none, true);
  68. if (property.isExpanded)
  69. {
  70. position.y += (LineHeight + LineSpan) * (property.arraySize + 2);
  71. position.y += (LineHeight + LineSpan) * (2 * property.arraySize); //todo
  72. }
  73. else
  74. {
  75. position.y += LineHeight + LineSpan;
  76. }
  77. return position;
  78. }
  79. }
  80. }