#if UNITY_EDITOR using System.Collections.Generic; using Mountools.Tools; using UnityEditor; using UnityEngine; using UnityEngine.SceneManagement; namespace Mountools.LoadingScreen { public class LoadingScreenManager : EditorWindow { #if MT_L_CHINESE private static readonly string WindowName = "加载画面管理器"; #endif #if MT_L_ENGLISH private static readonly string WindowName = "Loading Screen Manager"; #endif private static readonly Vector2 WindowMinSize = new(200, 400); private static readonly Vector2 WindowMaxSize = new(400, 800); private LoadingScreenPresets _presets; private Vector2 _scroll; private string _search = ""; private int _select; private void OnDrawWindow() { // 加载画面 var loadingScreen = LoadingScreen.GetLoadingScreen(); EditorGUI.BeginDisabledGroup( loadingScreen != null && loadingScreen.isLoading // 若正在加载 ); { // 搜索 _search = EditorGUILayout.TextField("", _search, "SearchTextField"); // 转场列表 _scroll = EditorGUILayout.BeginScrollView(_scroll, "OL box NoExpand"); { foreach (var screen in _presets.loadingScreens) { if (string.IsNullOrEmpty(_search.Trim()) || screen.name.Trim().ToLower().Contains(_search.Trim().ToLower()) ) { if (GUILayout.Button(screen.name, "TE toolbarbutton")) LoadingScreenPresets.ChangePreset(screen); EditorGUILayout.Space(3); } } } EditorGUILayout.EndScrollView(); } EditorGUI.EndDisabledGroup(); // 场景跳转 var sceneCount = SceneManager.sceneCountInBuildSettings; var scenePathList = new List(); for (var i = 0; i < sceneCount; i ++) { scenePathList.Add(SceneUtility.GetScenePathByBuildIndex(i)); } if (loadingScreen != null) { EditorGUI.BeginDisabledGroup( ! Application.isPlaying // 不在游玩 ); { EditorGUILayout.BeginHorizontal(); { _select = EditorGUILayout.Popup("", _select, scenePathList.ToArray()); // 加载场景 EditorGUI.BeginDisabledGroup( SceneManager.GetActiveScene().path == scenePathList[_select] || // 需要跳转的为当前场景 loadingScreen.isLoading // 当前场景正在加载 ); { if (GUILayout.Button(MountoolsLanguage.Lang("加载场景", "Load Scene"), "TE toolbarbutton")) { LoadingScreen.LoadScene(scenePathList[_select]); } } EditorGUI.EndDisabledGroup(); // 复制代码 var copyText = $"LoadingScreen.LoadScene(\"{scenePathList[_select]}\");"; EditorGUI.BeginDisabledGroup(copyText == EditorGUIUtility.systemCopyBuffer); { if (GUILayout.Button(MountoolsLanguage.Lang("复制代码", "Copy Code"), "TE toolbarbutton")) { EditorGUIUtility.systemCopyBuffer = copyText; } } EditorGUI.EndDisabledGroup(); } EditorGUILayout.EndHorizontal(); } EditorGUI.EndDisabledGroup(); } } public static void OpenWindow() { var window = GetWindow(WindowName); window.minSize = WindowMinSize; window.maxSize = WindowMaxSize; window._presets = LoadingScreenPresets.GetPresets(); window.Show(); } private void OnGUI() { OnDrawWindow(); } } } #endif