123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- namespace assetBundleUtility
- {
- using System;
- using UnityEditor;
- using UnityEngine;
-
- [CustomPropertyDrawer(typeof(AssetBundleGroup))]
- public class AssetBundleGroupDrawer : PropertyDrawer
- {
- #region Config
-
- private float LineSpan = 2;
- private float LineHeight = 16;
- private float ButtonSpan = 4;
- private float ButtonHeight = 32;
-
- private AssetBundleGroup Instance;
- private SerializedProperty MD5FileName;
- private SerializedProperty MD5DictionaryFileName;
- private SerializedProperty OutputPath;
- private SerializedProperty AssetBundleSets;
-
- #endregion
-
- public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
- {
- Instance = (AssetBundleGroup)InstanceUtility.GetObject(fieldInfo, property);
- return Instance.TotalHeight;
- }
-
- public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
- {
- Instance = (AssetBundleGroup) InstanceUtility.GetObject(fieldInfo, property);
- MD5FileName = property.FindPropertyRelative("MD5FileName");
- MD5DictionaryFileName = property.FindPropertyRelative("MD5DictionaryFileName");
- OutputPath = property.FindPropertyRelative("OutputPath");
- AssetBundleSets = property.FindPropertyRelative("AssetBundleSets");
-
- float originY = position.y;
-
- position.height = LineHeight;
-
- EditorGUI.indentLevel++;
- position = DrawProperty(position, MD5FileName);
- position = DrawProperty(position, MD5DictionaryFileName);
- position = DrawProperty(position, OutputPath);
- position = DrawPropertys(position, AssetBundleSets);
- position = DrawButton(position, "Create MD5File And MD5DictionaryFile", Instance.CreateMD5FileAndMD5DictionaryFile);
-
- 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);
- position.y += (LineHeight + LineSpan) * (2 * property.arraySize); //todo
- }
- else
- {
- position.y += LineHeight + LineSpan;
- }
- return position;
- }
- }
- }
|