浏览代码
"Editor window to quickly open scenes" task (#267)
"Editor window to quickly open scenes" task (#267)
* Added the Quick Scene Access Tool * removed unused file/main
GitHub
4 年前
当前提交
78c0f11a
共有 8 个文件被更改,包括 336 次插入 和 0 次删除
-
8UOP1_Project/Assets/ScriptableObjects/SceneData/Resources.meta
-
217UOP1_Project/Assets/Scripts/EditorTools/SceneAccessTool.cs
-
11UOP1_Project/Assets/Scripts/EditorTools/SceneAccessTool.cs.meta
-
51UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/SceneAccessHolderSO.cs
-
11UOP1_Project/Assets/Scripts/SceneManagement/ScriptableObjects/SceneAccessHolderSO.cs.meta
-
30UOP1_Project/Assets/ScriptableObjects/SceneData/Resources/SceneAccessHolder.asset
-
8UOP1_Project/Assets/ScriptableObjects/SceneData/Resources/SceneAccessHolder.asset.meta
|
|||
fileFormatVersion: 2 |
|||
guid: dd754fdc4b0731f4f9633351d8dcd5f3 |
|||
folderAsset: yes |
|||
DefaultImporter: |
|||
externalObjects: {} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using UnityEngine; |
|||
using UnityEditor; |
|||
using System.IO; |
|||
using UnityEditorInternal; |
|||
using UnityEditor.SceneManagement; |
|||
using System.Collections.Generic; |
|||
using System.Linq; |
|||
|
|||
public class SceneAccessTool : EditorWindow, IHasCustomMenu |
|||
{ |
|||
private SceneAccessHolderSO _inspected; |
|||
private SerializedObject _serializedObject; |
|||
private Editor _sceneAccessHolderSOEditor; |
|||
public enum Layout { List, Grid} |
|||
private Layout _layout; |
|||
private bool _showOptions = false; |
|||
private bool _editMode = false; |
|||
private ReorderableList list; |
|||
|
|||
private void OnEnable() |
|||
{ |
|||
|
|||
_inspected = Resources.Load<SceneAccessHolderSO>("SceneAccessHolder"); |
|||
SetUpList(); |
|||
} |
|||
private void SetUpList() |
|||
{ |
|||
_serializedObject = new SerializedObject(_inspected); |
|||
|
|||
if (_editMode) |
|||
{ |
|||
list = new ReorderableList(_serializedObject, |
|||
_serializedObject.FindProperty("sceneList"), |
|||
true, false, false, false); |
|||
list.drawElementCallback = |
|||
(Rect rect, int index, bool isActive, bool isFocused) => |
|||
{ |
|||
var element = list.serializedProperty.GetArrayElementAtIndex(index); |
|||
rect.y += 2; |
|||
EditorGUI.PropertyField( |
|||
new Rect(rect.x, rect.y, rect.width - 30, EditorGUIUtility.singleLineHeight), |
|||
element.FindPropertyRelative("name"), GUIContent.none); |
|||
|
|||
EditorGUI.PropertyField( |
|||
new Rect(rect.x + rect.width - 25, rect.y, 25, EditorGUIUtility.singleLineHeight), |
|||
element.FindPropertyRelative("visible"), GUIContent.none); |
|||
}; |
|||
} |
|||
} |
|||
[MenuItem("Tools/SceneAccessTool")] |
|||
public static void ShowWindow() |
|||
{ |
|||
GetWindow<SceneAccessTool>("SceneAccessTool"); |
|||
} |
|||
private void OnGUI() |
|||
{ |
|||
if (_inspected != null) |
|||
{ |
|||
if(_showOptions) |
|||
ShowOptions(); |
|||
ShowSceneList(); |
|||
} |
|||
} |
|||
|
|||
public void ShowOptions() |
|||
{ |
|||
GUILayout.BeginHorizontal(); |
|||
if (GUILayout.Button("Populate Scene List")) |
|||
{ |
|||
PopulateSceneList(); |
|||
} |
|||
if (GUILayout.Button("Clear List")) |
|||
{ |
|||
ClearSceneList(); |
|||
} |
|||
if (GUILayout.Button("Edit Mode")) |
|||
{ |
|||
ToggleEditMode(); |
|||
} |
|||
GUILayout.EndHorizontal(); |
|||
} |
|||
public void ShowSceneList() |
|||
{ |
|||
if (_editMode) |
|||
{ |
|||
_serializedObject.Update(); |
|||
list.DoLayoutList(); |
|||
_serializedObject.ApplyModifiedProperties(); |
|||
} |
|||
else |
|||
{ |
|||
if (_layout == Layout.List) |
|||
{ |
|||
for (int i = 0; i < _inspected.sceneList.Count; i++) |
|||
{ |
|||
var sceneItem = _inspected.sceneList[i]; |
|||
if (!sceneItem.visible) |
|||
{ |
|||
continue; |
|||
} |
|||
if (GUILayout.Button(sceneItem.name)) |
|||
{ |
|||
EditorSceneManager.OpenScene(sceneItem.path); |
|||
} |
|||
} |
|||
} |
|||
else |
|||
{ |
|||
int gridSize = 48; |
|||
int widthCount = gridSize; |
|||
GUILayout.BeginHorizontal(); |
|||
for (int i = 0; i < _inspected.sceneList.Count; i++) |
|||
{ |
|||
var sceneItem = _inspected.sceneList[i]; |
|||
if (!sceneItem.visible) |
|||
{ |
|||
continue; |
|||
} |
|||
|
|||
GUIStyle customButton = new GUIStyle("button"); |
|||
customButton.fontSize = 10; |
|||
customButton.alignment = TextAnchor.UpperLeft; |
|||
customButton.wordWrap = true; |
|||
GUIContent guiContent = new GUIContent(sceneItem.name); |
|||
if (GUILayout.Button( |
|||
guiContent, |
|||
customButton, |
|||
GUILayout.Width(gridSize), |
|||
GUILayout.Height(gridSize))) |
|||
{ |
|||
EditorSceneManager.OpenScene(sceneItem.path); |
|||
} |
|||
|
|||
widthCount += gridSize+4; |
|||
|
|||
if (widthCount > position.width) |
|||
{ |
|||
GUILayout.EndHorizontal(); |
|||
GUILayout.BeginHorizontal(); |
|||
widthCount = gridSize; |
|||
} |
|||
} |
|||
|
|||
GUILayout.EndHorizontal(); |
|||
} |
|||
|
|||
} |
|||
} |
|||
|
|||
/// <summary>
|
|||
/// Find all scenes in the project and put them in the list
|
|||
/// </summary>
|
|||
private void PopulateSceneList() |
|||
{ |
|||
EditorBuildSettingsScene[] currentScenes = EditorBuildSettings.scenes; |
|||
EditorBuildSettingsScene[] filteredScenes = currentScenes.Where(ebss => File.Exists(ebss.path)).ToArray(); |
|||
List<SceneAccessHolderSO.SceneInfo> allScene = new List<SceneAccessHolderSO.SceneInfo>(); |
|||
for (int i = 0; i < filteredScenes.Length; i++) |
|||
{ |
|||
allScene.Add( |
|||
new SceneAccessHolderSO.SceneInfo |
|||
{ |
|||
name = Path.GetFileNameWithoutExtension(filteredScenes[i].path), |
|||
path = Path.GetFullPath(filteredScenes[i].path), |
|||
visible = true |
|||
}); |
|||
} |
|||
//add the new scenes
|
|||
foreach(SceneAccessHolderSO.SceneInfo sceneInfo in allScene) |
|||
{ |
|||
if (!_inspected.sceneList.Contains(sceneInfo)) |
|||
{ |
|||
_inspected.sceneList.Add(sceneInfo); |
|||
} |
|||
} |
|||
//remove the deleted scenes
|
|||
foreach (SceneAccessHolderSO.SceneInfo sceneInfo in _inspected.sceneList.ToList()) |
|||
{ |
|||
if (!allScene.Contains(sceneInfo)) |
|||
{ |
|||
_inspected.sceneList.Remove(sceneInfo); |
|||
} |
|||
} |
|||
} |
|||
|
|||
private void ClearSceneList() |
|||
{ |
|||
_inspected.sceneList.Clear(); |
|||
} |
|||
|
|||
public void AddItemsToMenu(GenericMenu menu) |
|||
{ |
|||
menu.AddItem(new GUIContent("ToggleOptions"), false, ToggleOptions); |
|||
menu.AddItem(new GUIContent("ToggleLayout"), false, ToggleLayout); |
|||
} |
|||
|
|||
private void ToggleOptions() |
|||
{ |
|||
_showOptions = !_showOptions; |
|||
} |
|||
private void ToggleLayout() |
|||
{ |
|||
if (_layout == Layout.List) |
|||
{ |
|||
_layout = Layout.Grid; |
|||
} |
|||
else |
|||
{ |
|||
_layout = Layout.List; |
|||
} |
|||
} |
|||
private void ToggleEditMode() |
|||
{ |
|||
_editMode = !_editMode; |
|||
SetUpList(); |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: c8ba2b93ee72bce49aa87ecc1b52ea6f |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
using System; |
|||
using System.Collections.Generic; |
|||
using UnityEditor; |
|||
using UnityEngine; |
|||
|
|||
public class ReadOnlyAttribute : PropertyAttribute |
|||
{ |
|||
|
|||
} |
|||
|
|||
[CustomPropertyDrawer(typeof(ReadOnlyAttribute))] |
|||
public class ReadOnlyDrawer : PropertyDrawer |
|||
{ |
|||
public override float GetPropertyHeight(SerializedProperty property, |
|||
GUIContent label) |
|||
{ |
|||
return EditorGUI.GetPropertyHeight(property, label, true); |
|||
} |
|||
|
|||
public override void OnGUI(Rect position, |
|||
SerializedProperty property, |
|||
GUIContent label) |
|||
{ |
|||
GUI.enabled = false; |
|||
EditorGUI.PropertyField(position, property, label, true); |
|||
GUI.enabled = true; |
|||
} |
|||
} |
|||
/// <summary>
|
|||
/// It holds a list of scenes that's shown in the scene quick access tool
|
|||
/// </summary>
|
|||
[CreateAssetMenu(fileName = "SceneAccessHolder", menuName = "Scene Data/SceneAccessHolder")] |
|||
public class SceneAccessHolderSO : ScriptableObject |
|||
{ |
|||
[Serializable] |
|||
public struct SceneInfo : IEquatable<SceneInfo> |
|||
{ |
|||
[ReadOnly] public string name; |
|||
[ReadOnly] public string path; |
|||
public bool visible; |
|||
|
|||
public bool Equals(SceneInfo other) |
|||
{ |
|||
// Would still want to check for null etc. first.
|
|||
return this.path == other.path; |
|||
} |
|||
} |
|||
|
|||
[Header("List of Scenes")] |
|||
public List<SceneInfo> sceneList; |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 041bdbf27ff47ea4586c6b730fc5114c |
|||
MonoImporter: |
|||
externalObjects: {} |
|||
serializedVersion: 2 |
|||
defaultReferences: [] |
|||
executionOrder: 0 |
|||
icon: {instanceID: 0} |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
|
|||
%YAML 1.1 |
|||
%TAG !u! tag:unity3d.com,2011: |
|||
--- !u!114 &11400000 |
|||
MonoBehaviour: |
|||
m_ObjectHideFlags: 0 |
|||
m_CorrespondingSourceObject: {fileID: 0} |
|||
m_PrefabInstance: {fileID: 0} |
|||
m_PrefabAsset: {fileID: 0} |
|||
m_GameObject: {fileID: 0} |
|||
m_Enabled: 1 |
|||
m_EditorHideFlags: 0 |
|||
m_Script: {fileID: 11500000, guid: 041bdbf27ff47ea4586c6b730fc5114c, type: 3} |
|||
m_Name: SceneAccessHolder |
|||
m_EditorClassIdentifier: |
|||
sceneList: |
|||
- name: MainMenu |
|||
path: D:\indie\_OnGoing\open-project-Unity\UOP1_Project\Assets\Scenes\Menus\MainMenu.unity |
|||
visible: 1 |
|||
- name: Forest |
|||
path: D:\indie\_OnGoing\open-project-Unity\UOP1_Project\Assets\Scenes\Locations\Forest.unity |
|||
visible: 0 |
|||
- name: Beach |
|||
path: D:\indie\_OnGoing\open-project-Unity\UOP1_Project\Assets\Scenes\Locations\Beach.unity |
|||
visible: 1 |
|||
- name: TestingGround |
|||
path: D:\indie\_OnGoing\open-project-Unity\UOP1_Project\Assets\Scenes\TestingGround.unity |
|||
visible: 1 |
|||
- name: Initialization |
|||
path: D:\indie\_OnGoing\open-project-Unity\UOP1_Project\Assets\Scenes\Initialization.unity |
|||
visible: 1 |
|
|||
fileFormatVersion: 2 |
|||
guid: 40fa063512d1a5b46a597c15c6160a5e |
|||
NativeFormatImporter: |
|||
externalObjects: {} |
|||
mainObjectFileID: 0 |
|||
userData: |
|||
assetBundleName: |
|||
assetBundleVariant: |
撰写
预览
正在加载...
取消
保存
Reference in new issue