public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { dataList = DataListLoader.GetDataList(dataListAttribute.identifier); // Rect headerPosition = position; headerPosition.height = 16f; SerializedProperty list = property.FindPropertyRelative("list"); // Draw array header if (list == null || list.arraySize == 0) { Color previousGUIColor = GUI.color; Rect buttonPosition = EditorGUI.PrefixLabel(headerPosition, label); buttonPosition.width = 32; GUI.color = Color.green; if (GUI.Button(buttonPosition, duplicateButtonContent, EditorStyles.miniButton)) { if (list != null) { list.InsertArrayElementAtIndex(0); // Auto expand on first add list.isExpanded = true; } } GUI.color = previousGUIColor; } else { list.isExpanded = EditorGUI.Foldout(headerPosition, list.isExpanded, label.text + "\t (" + list.arraySize + ")", true); // Go on to next line headerPosition.y += 18f; ShowList(headerPosition, list); } }
// Draw the property inside the given rect public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { // Using BeginProperty / EndProperty on the parent property means that // prefab override logic works on the entire property. EditorGUI.BeginProperty(position, label, property); // Draw label Rect firstLineRect = EditorGUI.PrefixLabel(position, GUIUtility.GetControlID(FocusType.Passive), label); // - line 1 : selected value Rect valueRect = new Rect(firstLineRect.x, position.y, firstLineRect.width - 32, position.height); Rect buttonRect = new Rect(firstLineRect.x + firstLineRect.width - 32, position.y, 32, position.height); // NEW : list can be a list of list names string[] identifierList = (attribute as SelectAttribute).identifier.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries); List <string> list = new List <string>(); for (int i = 0; i < identifierList.Length; i++) { list.AddRange(DataListLoader.GetDataList(identifierList[i].Trim())); } // 2. result list if (list.Count > 0) { int selectedIndex = -1; selectedIndex = list.FindIndex(element => element.Equals(property.stringValue, StringComparison.InvariantCulture)); int previousIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; EditorGUI.BeginChangeCheck(); int newSelectedIndex = EditorGUI.Popup(valueRect, selectedIndex, list.ToArray()); if (EditorGUI.EndChangeCheck()) { property.stringValue = list[newSelectedIndex]; } Color previousGuiColor = GUI.color; GUI.color = Color.red; if (GUI.Button(buttonRect, "0")) { property.stringValue = null; } GUI.color = previousGuiColor; EditorGUI.indentLevel = previousIndentLevel; } property.serializedObject.ApplyModifiedProperties(); // */ EditorGUI.EndProperty(); }