private void DrawEditorPreview(ref Rect rect, ScriptableObjectCollectionItem scriptableObjectCollectionItem) { if (scriptableObjectCollectionItem == null) { return; } if (!CollectionUtility.IsFoldoutOpen(scriptableObjectCollectionItem, currentObject)) { return; } rect.y += EditorGUIUtility.singleLineHeight + EditorGUIUtility.standardVerticalSpacing; rect.width -= 10; rect.y += 10; float beginPositionY = rect.y; SerializedObject collectionItemSerializedObject = new SerializedObject(scriptableObjectCollectionItem); EditorGUI.indentLevel++; rect = EditorGUI.IndentedRect(rect); SerializedProperty iterator = collectionItemSerializedObject.GetIterator(); using (EditorGUI.ChangeCheckScope changeCheck = new EditorGUI.ChangeCheckScope()) { for (bool enterChildren = true; iterator.NextVisible(enterChildren); enterChildren = false) { bool guiEnabled = GUI.enabled; if (iterator.displayName.Equals("Script")) { GUI.enabled = false; } EditorGUI.PropertyField(rect, iterator, true); GUI.enabled = guiEnabled; rect.y += EditorGUI.GetPropertyHeight(iterator, true) + EditorGUIUtility.standardVerticalSpacing; } if (changeCheck.changed) { iterator.serializedObject.ApplyModifiedProperties(); } } EditorGUI.indentLevel--; rect = EditorGUI.IndentedRect(rect); Rect boxPosition = rect; boxPosition.y = beginPositionY - 5; boxPosition.height = (rect.y - beginPositionY) + 10; boxPosition.width += 10; boxPosition.x += 5; rect.y += 10; GUI.Box(boxPosition, GUIContent.none, EditorStyles.helpBox); }
private void DrawItem(int index) { CollectableScriptableObject collectionItem = filteredItemList[index]; using (new EditorGUILayout.VerticalScope("Box")) { using (new EditorGUILayout.HorizontalScope()) { CollectionUtility.SetFoldoutOpen(collectionItem, EditorGUILayout.Toggle(GUIContent.none, CollectionUtility.IsFoldoutOpen(collectionItem), EditorStyles.foldout, GUILayout.Width(13))); using (EditorGUI.ChangeCheckScope changeCheck = new EditorGUI.ChangeCheckScope()) { string newName = EditorGUILayout.DelayedTextField(collectionItem.name, CollectionEditorGUI.ItemNameStyle, GUILayout.ExpandWidth(true)); if (changeCheck.changed) { AssetDatabaseUtils.RenameAsset(collectionItem, newName); } } DrawSelectItem(collectionItem); DrawMoveItemDownButton(collectionItem); DrawMoveItemUpButton(collectionItem); DrawDeleteButton(collectionItem); } if (CollectionUtility.IsFoldoutOpen(collectionItem)) { EditorGUI.indentLevel++; Editor editor = CollectionUtility.GetEditorForItem(collectionItem); using (EditorGUI.ChangeCheckScope changeCheck = new EditorGUI.ChangeCheckScope()) { GUILayout.Space(10); editor.OnInspectorGUI(); EditorGUILayout.Space(); if (changeCheck.changed) { if (index > filteredSerializedList.Count - 1 || filteredSerializedList[index] == null) { filteredItemListDirty = true; } else { filteredSerializedList[index].ApplyModifiedProperties(); } } } EditorGUI.indentLevel--; } } }
private void DrawGotoButton(ref Rect popupRect) { Rect buttonRect = popupRect; buttonRect.width = 30; buttonRect.height = 18; popupRect.width -= buttonRect.width; buttonRect.x += popupRect.width; if (GUI.Button(buttonRect, CollectionEditorGUI.ARROW_RIGHT_CHAR)) { Selection.activeObject = item.Collection; CollectionUtility.SetFoldoutOpen(true, item, item.Collection); } }
private void DrawEditFoldoutButton(ref Rect popupRect) { Rect buttonRect = popupRect; buttonRect.width = 30; buttonRect.height = 18; popupRect.width -= buttonRect.width; buttonRect.x += popupRect.width; GUIContent guiContent = CollectionEditorGUI.EditGUIContent; if (CollectionUtility.IsFoldoutOpen(foldoutObject)) { guiContent = CollectionEditorGUI.CloseGUIContent; } if (GUI.Button(buttonRect, guiContent)) { CollectionUtility.SetFoldoutOpen(foldoutObject, !CollectionUtility.IsFoldoutOpen(foldoutObject)); ObjectUtility.SetDirty(collectableItem); } }
private void DrawEditFoldoutButton(ref Rect popupRect, ScriptableObjectCollectionItem targetItem) { Rect buttonRect = popupRect; buttonRect.width = 30; buttonRect.height = 18; popupRect.width -= buttonRect.width; buttonRect.x += popupRect.width; GUIContent guiContent = CollectionEditorGUI.EditGUIContent; if (CollectionUtility.IsFoldoutOpen(targetItem, currentObject)) { guiContent = CollectionEditorGUI.CloseGUIContent; } if (GUI.Button(buttonRect, guiContent)) { CollectionUtility.SetFoldoutOpen(!CollectionUtility.IsFoldoutOpen(targetItem, currentObject), targetItem, currentObject); ObjectUtility.SetDirty(targetItem); } }
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { Initialize(property); collectableItem = property.objectReferenceValue as CollectableScriptableObject; if (optionsAttribute.DrawType == DrawType.AsReference) { EditorGUI.PropertyField(position, property, label, true); return; } Rect popupRect = position; popupRect.height = 15; if (collectableItem != null) { DrawEditFoldoutButton(ref popupRect); DrawGotoButton(collection, ref popupRect); } using (new EditorGUI.PropertyScope(position, label, property)) { popupRect = EditorGUI.PrefixLabel(popupRect, label); int indent = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; bool showMixedValue = EditorGUI.showMixedValue; switch (optionsAttribute.DrawType) { case DrawType.Dropdown: { EditorGUI.showMixedValue = property.hasMultipleDifferentValues; DrawDropDown(popupRect, property); break; } default: throw new ArgumentOutOfRangeException("DrawType: " + optionsAttribute.DrawType); } if (collectableItem != null) { if (CollectionUtility.IsFoldoutOpen(foldoutObject)) { EditorGUI.indentLevel++; using (new EditorGUILayout.VerticalScope("Box")) { Editor editor = CollectionUtility.GetEditorForItem(collectableItem); using (EditorGUI.ChangeCheckScope changedCheck = new EditorGUI.ChangeCheckScope()) { GUILayout.Space(10); using (new EditorGUILayout.VerticalScope()) { editor.OnInspectorGUI(); } EditorGUILayout.Space(); if (changedCheck.changed) { property.serializedObject.ApplyModifiedProperties(); } } } EditorGUI.indentLevel--; } } EditorGUI.showMixedValue = showMixedValue; EditorGUI.indentLevel = indent; } }