private static ScriptableObject Draw(Rect position, GUIContent label, ScriptableObject asset, Type type, bool showNoneOption, bool showEditButton, bool showCreateOptions) { if (showEditButton) { var editRect = RectHelper.TakeTrailingIcon(ref position); if (asset != null) { if (GUI.Button(editRect, _editButton.Content, GUIStyle.none)) { Selection.activeObject = asset; } } } var list = AssetHelper.GetAssetList(type, showNoneOption, showCreateOptions); var index = list.GetIndex(asset); index = EditorGUI.Popup(position, label, index, list.Names); asset = list.GetAsset(index); if (asset == null) { var createType = list.GetType(index); if (createType != null) { asset = AssetHelper.CreateAsset(createType.Name, createType); } } return(asset); }
public static Object Draw(Rect position, GUIContent label, Object asset, Type assetType, bool showNoneOption, bool showEditButton, AssetLocation saveLocation, string defaultName) { if (showEditButton) { var editRect = RectHelper.TakeTrailingIcon(ref position); if (asset) { if (GUI.Button(editRect, _editButton.Content, GUIStyle.none)) { Selection.activeObject = asset; } } } var rect = EditorGUI.PrefixLabel(position, label); var creatable = saveLocation != AssetLocation.None && typeof(ScriptableObject).IsAssignableFrom(assetType); var list = AssetHelper.GetAssetList(assetType, showNoneOption, creatable); var index = list.GetIndex(asset); var thumbnail = asset != null?AssetPreview.GetMiniThumbnail(asset) ?? AssetPreview.GetMiniTypeThumbnail(asset.GetType()) : null; var popupLabel = asset ? new GUIContent(asset.name, thumbnail) : new GUIContent("None"); var selection = SelectionPopup.Draw(rect, popupLabel, new SelectionState { Tab = 0, Index = index }, list.Tree); if (selection.Tab == 0) { if (selection.Index != index) { return(list.GetAsset(selection.Index)); } } else if (selection.Tab == 1) { var type = list.GetType(selection.Index); return(AssetHelper.Create(type, saveLocation, defaultName)); } if (DragAndDrop.objectReferences.Length > 0 && rect.Contains(Event.current.mousePosition)) { var obj = DragAndDrop.objectReferences[0]; if (obj != null && assetType.IsAssignableFrom(obj.GetType())) { if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; Event.current.Use(); } if (Event.current.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); return(obj); } } } return(asset); }