private static SceneList BuildList(SceneList list) { if (list.Paths == null) { // Removed scenes still show up in build settings as deleted and are thus still listed here. // Unfortunate but that is better than the alternative (enumerating the scenes) which would allow // selection of scenes that aren't in build settings. list.Paths = new List <string>(SceneManager.sceneCountInBuildSettings); list.Names = new GUIContent[SceneManager.sceneCountInBuildSettings + (list.HasNone ? 1 : 0)]; for (var i = 0; i < SceneManager.sceneCountInBuildSettings; i++) { list.Paths.Add(SceneUtility.GetScenePathByBuildIndex(i)); } var index = 0; var prefix = AssetHelper.FindCommonPath(list.Paths); if (list.HasNone) { list.Names[index++] = new GUIContent("None"); } var thumbnail = AssetPreview.GetMiniTypeThumbnail(typeof(SceneAsset)); foreach (var path in list.Paths) { var scene = path.Substring(prefix.Length, path.Length - prefix.Length - 6); // remove the ".unity" extension list.Names[index++] = new GUIContent(scene, thumbnail); } list.Tree = new SelectionTree(); list.Tree.Add("Scene", list.Names); if (list.HasCreate) { list.Tree.Add("Create", new GUIContent[] { new GUIContent("New Scene", thumbnail) }); } } return(list); }
private static SceneList BuildList(SceneList list) { if (list.Paths == null) { // Removed scenes still show up in build settings as deleted and are thus still listed here. // Unfortunate but that is better than the alternative (enumerating the scenes) which would allow // selection of scenes that aren't in build settings. list.Paths = new List <string>(SceneManager.sceneCountInBuildSettings); list.Names = new GUIContent[SceneManager.sceneCountInBuildSettings + (list.HasNone ? 2 : 0) + (list.HasCreate ? 2 : 0)]; for (var i = 0; i < SceneManager.sceneCountInBuildSettings; i++) { list.Paths.Add(SceneUtility.GetScenePathByBuildIndex(i)); } var index = 0; var prefix = AssetHelper.FindCommonPath(list.Paths); if (list.HasNone) { list.Names[index++] = new GUIContent("None"); list.Names[index++] = new GUIContent(""); } foreach (var path in list.Paths) { var scene = path.Substring(prefix.Length); list.Names[index++] = new GUIContent(scene); } if (list.HasCreate) { list.Names[index++] = new GUIContent(""); list.Names[index++] = new GUIContent("Create Scene"); } } return(list); }
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); }