public static void Show(int id, Rect position, SelectionState state, SelectionTree tree) { if (_instance != null) { _instance.Close(); } _selectionId = id; _selectionMade = false; _selectionState = state; _instance = CreateInstance <SelectionPopup>(); _instance.Setup(state, tree); _instance.ShowAsDropDown(position, new Vector2(Mathf.Max(_minimumWidth, position.width), _windowHeight)); _instance.position = new Rect(GUIUtility.GUIToScreenPoint(new Vector2(position.x, position.yMax)), position.size); }
public static Type Draw(Rect position, GUIContent label, Type type, Type rootType, bool showNoneOption, bool showAbstractOptions) { var rect = EditorGUI.PrefixLabel(position, label); var list = TypeHelper.GetTypeList(rootType, showNoneOption, showAbstractOptions); var index = list.GetIndex(type); var thumbnail = type != null ? (AssetPreview.GetMiniTypeThumbnail(type) ?? _defaultTypeIcon.Content) : null; var popupLabel = type != null ? new GUIContent(type.Name, thumbnail) : new GUIContent("None"); var selection = SelectionPopup.Draw(rect, popupLabel, new SelectionState { Tab = 0, Index = index }, list.Tree); if (DragAndDrop.objectReferences.Length > 0 && rect.Contains(Event.current.mousePosition)) { var obj = DragAndDrop.objectReferences[0]; if (obj != null) { var drag = DragAndDrop.objectReferences[0].GetType(); if (rootType.IsAssignableFrom(drag)) { if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; Event.current.Use(); } if (Event.current.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); return(drag); } } } } return(list.GetType(selection.Index)); }
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); }
public static void Draw(Rect position, SceneReference scene, GUIContent label, AssetLocation location, string newSceneName, Action creator) { var rect = EditorGUI.PrefixLabel(position, label); var refreshRect = RectHelper.TakeTrailingIcon(ref rect); if (GUI.Button(refreshRect, _refreshScenesButton.Content, GUIStyle.none)) { SceneHelper.RefreshLists(); } var list = SceneHelper.GetSceneList(true, location != AssetLocation.None); var index = list.GetIndex(scene.Path); if (index != 0 && scene.IsAssigned) { var loadRect = RectHelper.TakeTrailingIcon(ref rect); var s = scene.Scene; using (ColorScope.ContentColor(Color.black)) { if (s.IsValid() && s.isLoaded) { if (GUI.Button(loadRect, _unloadSceneButton.Content, GUIStyle.none)) { if (EditorSceneManager.SaveModifiedScenesIfUserWantsTo(new Scene[] { s })) { EditorSceneManager.CloseScene(s, true); } } } else { if (GUI.Button(loadRect, _loadSceneButton.Content, GUIStyle.none)) { s = EditorSceneManager.OpenScene(scene.Path, OpenSceneMode.Additive); SceneManager.SetActiveScene(s); } } } } var thumbnail = AssetPreview.GetMiniTypeThumbnail(typeof(SceneAsset)); var start = scene.Path.LastIndexOf('/') + 1; var popupLabel = index != 0 && scene.IsAssigned ? new GUIContent(scene.Path.Substring(start, scene.Path.Length - start - 6), thumbnail) : new GUIContent("None"); var selection = SelectionPopup.Draw(rect, popupLabel, new SelectionState { Tab = 0, Index = index }, list.Tree); if (selection.Tab == 0 && selection.Index != index) { scene.Path = list.GetPath(selection.Index); } else if (selection.Tab == 1) { var newScene = SceneHelper.CreateScene(location, newSceneName, creator); scene.Path = newScene.path; } if (DragAndDrop.objectReferences.Length > 0 && rect.Contains(Event.current.mousePosition)) { var obj = DragAndDrop.objectReferences[0]; if (obj is SceneAsset asset) { if (Event.current.type == EventType.DragUpdated) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; Event.current.Use(); } if (Event.current.type == EventType.DragPerform) { scene.Path = AssetDatabase.GetAssetPath(asset); DragAndDrop.AcceptDrag(); } } } }
void OnDestroy() { _instance = null; }