diff options
| author | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
|---|---|---|
| committer | Andrew Lee <alee14498@protonmail.com> | 2020-04-19 17:19:32 -0400 |
| commit | c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78 (patch) | |
| tree | ee4d51c7c1d633e11f46453ef1edd3c77c4ef9f7 /Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Editor/DropdownOptionListDrawer.cs | |
| download | Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.gz Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.tar.bz2 Project-Sandbox-c55fba8ab2a1c9d3df65eda4a5a1e957f4aa1f78.zip | |
Inital commit
Diffstat (limited to 'Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Editor/DropdownOptionListDrawer.cs')
| -rw-r--r-- | Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Editor/DropdownOptionListDrawer.cs | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Editor/DropdownOptionListDrawer.cs b/Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Editor/DropdownOptionListDrawer.cs new file mode 100644 index 0000000..d082b5f --- /dev/null +++ b/Library/PackageCache/com.unity.textmeshpro@2.0.1/Scripts/Editor/DropdownOptionListDrawer.cs @@ -0,0 +1,60 @@ +using UnityEditorInternal;
+using UnityEngine;
+using UnityEngine.UI;
+using UnityEditor;
+
+namespace TMPro.EditorUtilities
+{
+ [CustomPropertyDrawer(typeof(TMP_Dropdown.OptionDataList), true)]
+ class DropdownOptionListDrawer : PropertyDrawer
+ {
+ private ReorderableList m_ReorderableList;
+
+ private void Init(SerializedProperty property)
+ {
+ if (m_ReorderableList != null)
+ return;
+
+ SerializedProperty array = property.FindPropertyRelative("m_Options");
+
+ m_ReorderableList = new ReorderableList(property.serializedObject, array);
+ m_ReorderableList.drawElementCallback = DrawOptionData;
+ m_ReorderableList.drawHeaderCallback = DrawHeader;
+ m_ReorderableList.elementHeight += 16;
+ }
+
+ public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
+ {
+ Init(property);
+
+ m_ReorderableList.DoList(position);
+ }
+
+ private void DrawHeader(Rect rect)
+ {
+ GUI.Label(rect, "Options");
+ }
+
+ private void DrawOptionData(Rect rect, int index, bool isActive, bool isFocused)
+ {
+ SerializedProperty itemData = m_ReorderableList.serializedProperty.GetArrayElementAtIndex(index);
+ SerializedProperty itemText = itemData.FindPropertyRelative("m_Text");
+ SerializedProperty itemImage = itemData.FindPropertyRelative("m_Image");
+
+ RectOffset offset = new RectOffset(0, 0, -1, -3);
+ rect = offset.Add(rect);
+ rect.height = EditorGUIUtility.singleLineHeight;
+
+ EditorGUI.PropertyField(rect, itemText, GUIContent.none);
+ rect.y += EditorGUIUtility.singleLineHeight;
+ EditorGUI.PropertyField(rect, itemImage, GUIContent.none);
+ }
+
+ public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
+ {
+ Init(property);
+
+ return m_ReorderableList.GetHeight();
+ }
+ }
+}
|
