diff --git a/Editor/ToolBarExtension/BuildSettingWindow.cs b/Editor/ToolBarExtension/BuildSettingWindow.cs deleted file mode 100644 index 75a8529..0000000 --- a/Editor/ToolBarExtension/BuildSettingWindow.cs +++ /dev/null @@ -1,26 +0,0 @@ -// using Paps.UnityToolbarExtenderUIToolkit; -// using UnityEditor; -// using UnityEngine; -// using UnityEngine.UIElements; -// -// [MainToolbarElement(id: "BuildSettingWindow", alignment: ToolbarAlign.Right, order: 3)] -// public class BuildSettingWindow : IMGUIContainer -// { -// private GUIContent buildBtContent; -// -// public void InitializeElement() -// { -// buildBtContent = EditorGUIUtility.TrTextContentWithIcon("Build App/Hotfix", "打新包/打热更", EditorGUIUtility.IconContent("d_BuildSettings.Standalone").image); -// onGUIHandler = MyGUIMethod; -// } -// -// private void MyGUIMethod() -// { -// GUILayout.BeginHorizontal(); -// -// if (GUILayout.Button(buildBtContent, EditorStyles.toolbarButton, GUILayout.MaxWidth(125))) -// Debug.Log("GUI Button clicked"); -// -// GUILayout.EndHorizontal(); -// } -// } diff --git a/Editor/ToolBarExtension/BuildSettingWindow.cs.meta b/Editor/ToolBarExtension/BuildSettingWindow.cs.meta deleted file mode 100644 index 6931208..0000000 --- a/Editor/ToolBarExtension/BuildSettingWindow.cs.meta +++ /dev/null @@ -1,3 +0,0 @@ -fileFormatVersion: 2 -guid: b7b9f8865a200e04b81804580b6d1de1 -timeCreated: 1741240351 \ No newline at end of file diff --git a/Editor/ToolBarExtension/EditorToolFunctionAttribute.cs b/Editor/ToolBarExtension/EditorToolFunctionAttribute.cs new file mode 100644 index 0000000..a9cd9b8 --- /dev/null +++ b/Editor/ToolBarExtension/EditorToolFunctionAttribute.cs @@ -0,0 +1,24 @@ +using System; +using System.Reflection; + +namespace AlicizaX.Editor.Extension +{ + [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] + public class EditorToolFunctionAttribute : Attribute + { + public string ToolMenuPath { get; private set; } + public int MenuOrder { get; private set; } + public MethodInfo MethodInfo { get; private set; } + + public EditorToolFunctionAttribute(string menu, int menuOrder = 0) + { + this.ToolMenuPath = menu; + MenuOrder = menuOrder; + } + + public void SetMethodInfo(MethodInfo methodInfo) + { + MethodInfo = methodInfo; + } + } +} diff --git a/Editor/ToolBarExtension/EditorToolFunctionAttribute.cs.meta b/Editor/ToolBarExtension/EditorToolFunctionAttribute.cs.meta new file mode 100644 index 0000000..f60168e --- /dev/null +++ b/Editor/ToolBarExtension/EditorToolFunctionAttribute.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: b242a864126249459c576ae04b84bd3c +timeCreated: 1775562565 \ No newline at end of file diff --git a/Editor/ToolBarExtension/New.meta b/Editor/ToolBarExtension/New.meta new file mode 100644 index 0000000..b678c4e --- /dev/null +++ b/Editor/ToolBarExtension/New.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 826b6ceb6b80b0e4da54e2d8c6178bfd +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ToolBarExtension/New/EditorQuickToolbarDropdown.cs b/Editor/ToolBarExtension/New/EditorQuickToolbarDropdown.cs new file mode 100644 index 0000000..92a262b --- /dev/null +++ b/Editor/ToolBarExtension/New/EditorQuickToolbarDropdown.cs @@ -0,0 +1,161 @@ +#if UNITY_6000_3_OR_NEWER +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using UnityEditor; +using UnityEditor.Toolbars; +using UnityEngine; + +namespace AlicizaX.Editor.Extension +{ + [InitializeOnLoad] + public static class EditorQuickToolbarDropdown + { + private const string ElementPath = "AlicizaX/EditorQuickTools"; + private const string Tooltip = "Open editor quick tools"; + + private static readonly Texture2D ToolIcon; + private static readonly List ToolEntries; + + private sealed class ToolEntry + { + public string MenuPath; + public int MenuOrder; + public MethodInfo MethodInfo; + } + + static EditorQuickToolbarDropdown() + { + ToolIcon = GetIcon("CustomTool") ?? GetIcon("Settings"); + ToolEntries = CollectToolEntries(); + } + + [MainToolbarElement(ElementPath, defaultDockPosition = MainToolbarDockPosition.Right, defaultDockIndex = 1)] + public static MainToolbarElement CreateElement() + { + return new MainToolbarDropdown( + new MainToolbarContent("Tools", ToolIcon, Tooltip), + ShowDropdownMenu); + } + + private static void ShowDropdownMenu(Rect dropdownRect) + { + var menu = new GenericMenu(); + + if (ToolEntries.Count == 0) + { + menu.AddDisabledItem(new GUIContent("No tools found")); + menu.DropDown(dropdownRect); + return; + } + + foreach (var toolEntry in ToolEntries) + { + var capturedToolEntry = toolEntry; + menu.AddItem( + new GUIContent(capturedToolEntry.MenuPath), + false, + () => InvokeTool(capturedToolEntry)); + } + + menu.DropDown(dropdownRect); + } + + private static List CollectToolEntries() + { + var toolEntries = new List(); + + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + if (assembly.FullName.Contains("Sirenix", StringComparison.Ordinal)) + { + continue; + } + + Type[] types; + try + { + types = assembly.GetTypes(); + } + catch (ReflectionTypeLoadException exception) + { + types = exception.Types.Where(type => type != null).ToArray(); + } + catch + { + continue; + } + + foreach (var type in types) + { + MethodInfo[] methods; + try + { + methods = type.GetMethods(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic); + } + catch + { + continue; + } + + foreach (var method in methods) + { + var attribute = method.GetCustomAttribute(); + if (attribute == null) + { + continue; + } + + toolEntries.Add(new ToolEntry + { + MenuPath = attribute.ToolMenuPath, + MenuOrder = attribute.MenuOrder, + MethodInfo = method + }); + } + } + } + + toolEntries.Sort((left, right) => + { + var orderCompare = left.MenuOrder.CompareTo(right.MenuOrder); + return orderCompare != 0 + ? orderCompare + : string.Compare(left.MenuPath, right.MenuPath, StringComparison.OrdinalIgnoreCase); + }); + + return toolEntries; + } + + private static void InvokeTool(ToolEntry toolEntry) + { + if (toolEntry.MethodInfo == null || !toolEntry.MethodInfo.IsStatic) + { + Debug.LogError("Tool method is not static or could not be found."); + return; + } + + if (toolEntry.MethodInfo.GetParameters().Length != 0) + { + Debug.LogError($"Tool method '{toolEntry.MethodInfo.Name}' must be parameterless."); + return; + } + + try + { + toolEntry.MethodInfo.Invoke(null, null); + } + catch (Exception exception) + { + Debug.LogException(exception); + } + } + + private static Texture2D GetIcon(string iconName) + { + return EditorGUIUtility.IconContent(iconName).image as Texture2D; + } + } +} +#endif diff --git a/Editor/ToolBarExtension/New/EditorQuickToolbarDropdown.cs.meta b/Editor/ToolBarExtension/New/EditorQuickToolbarDropdown.cs.meta new file mode 100644 index 0000000..1013349 --- /dev/null +++ b/Editor/ToolBarExtension/New/EditorQuickToolbarDropdown.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 219127dd6a8ebe143996214d98d2b475 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ToolBarExtension/New/LocalizationToolbarDropdown.cs b/Editor/ToolBarExtension/New/LocalizationToolbarDropdown.cs new file mode 100644 index 0000000..f3218fe --- /dev/null +++ b/Editor/ToolBarExtension/New/LocalizationToolbarDropdown.cs @@ -0,0 +1,161 @@ +#if UNITY_6000_3_OR_NEWER +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using AlicizaX.Localization.Editor; +using AlicizaX.Localization.Runtime; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEditor.Toolbars; +using UnityEngine; + +namespace AlicizaX.Editor.Extension +{ + [InitializeOnLoad] + public static class LocalizationToolbarDropdown + { + private const string ElementPath = "AlicizaX/Localization"; + private const string Tooltip = "Switch editor localization preview language"; + + private static readonly Texture2D SettingsIcon; + private static string s_LastKnownLanguage; + + static LocalizationToolbarDropdown() + { + SettingsIcon = GetIcon("Settings"); + s_LastKnownLanguage = GetSelectedLanguage(); + EditorApplication.update += RefreshWhenLanguageChanges; + } + + [MainToolbarElement(ElementPath, defaultDockPosition = MainToolbarDockPosition.Right, defaultDockIndex = 0)] + public static MainToolbarElement CreateElement() + { + return new MainToolbarDropdown( + new MainToolbarContent(GetToolbarLabel(), SettingsIcon, Tooltip), + ShowDropdownMenu); + } + + private static void RefreshWhenLanguageChanges() + { + var selectedLanguage = GetSelectedLanguage(); + if (selectedLanguage == s_LastKnownLanguage) + { + return; + } + + s_LastKnownLanguage = selectedLanguage; + MainToolbar.Refresh(ElementPath); + } + + private static void ShowDropdownMenu(Rect dropdownRect) + { + var selectedLanguage = GetSelectedLanguage(); + var menu = new GenericMenu(); + var languageNames = GetLanguageTypeNames(); + + if (languageNames.Count == 0) + { + menu.AddDisabledItem(new GUIContent("No language options")); + menu.DropDown(dropdownRect); + return; + } + + foreach (var languageName in languageNames) + { + var capturedLanguageName = languageName; + menu.AddItem( + new GUIContent(capturedLanguageName), + string.Equals(selectedLanguage, capturedLanguageName, StringComparison.Ordinal), + () => SetSelectedLanguage(capturedLanguageName)); + } + + menu.DropDown(dropdownRect); + } + + private static void SetSelectedLanguage(string languageName) + { + EditorPrefs.SetString(LocalizationComponent.PrefsKey, languageName); + s_LastKnownLanguage = languageName; + InvokeOnValidateInScene(); + MainToolbar.Refresh(ElementPath); + } + + private static IReadOnlyList GetLanguageTypeNames() + { + return LocalizationConfiguration.Instance != null + ? LocalizationConfiguration.Instance.LanguageTypeNames + : Array.Empty(); + } + + private static string GetSelectedLanguage() + { + return EditorPrefs.GetString(LocalizationComponent.PrefsKey, "None"); + } + + private static string GetToolbarLabel() + { + return GetSelectedLanguage(); + } + + private static void InvokeOnValidateInScene() + { + var targetType = FindType("UnityEngine.UI.UXTextMeshPro"); + if (targetType == null) + { + Debug.LogWarning("Could not find type UnityEngine.UI.UXTextMeshPro."); + return; + } + + var onValidateMethod = targetType.GetMethod( + "OnValidate", + BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); + + if (onValidateMethod == null) + { + Debug.LogWarning($"Could not find OnValidate on {targetType.Name}."); + return; + } + + var components = GameObject.FindObjectsOfType(targetType) + .OfType() + .ToList(); + + if (components.Count == 0) + { + return; + } + + var sceneToMarkDirty = EditorSceneManager.GetActiveScene(); + + foreach (var component in components) + { + Undo.RecordObject(component, "Invoke OnValidate"); + onValidateMethod.Invoke(component, null); + EditorUtility.SetDirty(component); + } + + EditorSceneManager.MarkSceneDirty(sceneToMarkDirty); + } + + private static Type FindType(string fullName) + { + foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) + { + var type = assembly.GetType(fullName); + if (type != null) + { + return type; + } + } + + return null; + } + + private static Texture2D GetIcon(string iconName) + { + return EditorGUIUtility.IconContent(iconName).image as Texture2D; + } + } +} +#endif diff --git a/Editor/ToolBarExtension/New/LocalizationToolbarDropdown.cs.meta b/Editor/ToolBarExtension/New/LocalizationToolbarDropdown.cs.meta new file mode 100644 index 0000000..1f9716a --- /dev/null +++ b/Editor/ToolBarExtension/New/LocalizationToolbarDropdown.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13ca60a407539344ba0c7fed723066cf +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ToolBarExtension/New/ResourceModeToolbarDropdown.cs b/Editor/ToolBarExtension/New/ResourceModeToolbarDropdown.cs new file mode 100644 index 0000000..e228a93 --- /dev/null +++ b/Editor/ToolBarExtension/New/ResourceModeToolbarDropdown.cs @@ -0,0 +1,90 @@ +#if UNITY_6000_3_OR_NEWER +using AlicizaX.Resource.Runtime; +using UnityEditor; +using UnityEditor.Toolbars; +using UnityEngine; + +namespace AlicizaX.Editor.Extension +{ + [InitializeOnLoad] + public static class ResourceModeToolbarDropdown + { + private const string ElementPath = "AlicizaX/ResourceMode"; + private const string Tooltip = "配置 App 运行时资源模式"; + + private static readonly string[] ResourceModeNames = + { + "Editor", + "Offline", + "Host", + "Webgl" + }; + + private static readonly Texture2D SettingsIcon; + private static int s_LastKnownModeIndex; + + static ResourceModeToolbarDropdown() + { + SettingsIcon = EditorGUIUtility.IconContent("Settings").image as Texture2D; + s_LastKnownModeIndex = GetSelectedModeIndex(); + EditorApplication.update += RefreshWhenModeChanged; + } + + [MainToolbarElement(ElementPath, defaultDockPosition = MainToolbarDockPosition.Middle, defaultDockIndex = 101)] + public static MainToolbarElement CreateElement() + { + return new MainToolbarDropdown( + new MainToolbarContent(GetToolbarLabel(), SettingsIcon, Tooltip), + ShowDropdownMenu); + } + + private static void RefreshWhenModeChanged() + { + var selectedModeIndex = GetSelectedModeIndex(); + if (selectedModeIndex == s_LastKnownModeIndex) + { + return; + } + + s_LastKnownModeIndex = selectedModeIndex; + MainToolbar.Refresh(ElementPath); + } + + private static void ShowDropdownMenu(Rect dropdownRect) + { + var currentIndex = GetSelectedModeIndex(); + var menu = new GenericMenu(); + + for (var i = 0; i < ResourceModeNames.Length; i++) + { + var modeIndex = i; + menu.AddItem( + new GUIContent(ResourceModeNames[modeIndex]), + currentIndex == modeIndex, + () => SetSelectedMode(modeIndex)); + } + + menu.DropDown(dropdownRect); + } + + private static void SetSelectedMode(int modeIndex) + { + var safeModeIndex = Mathf.Clamp(modeIndex, 0, ResourceModeNames.Length - 1); + EditorPrefs.SetInt(ResourceComponent.PrefsKey, safeModeIndex); + s_LastKnownModeIndex = safeModeIndex; + MainToolbar.Refresh(ElementPath); + } + + private static int GetSelectedModeIndex() + { + var storedIndex = EditorPrefs.GetInt(ResourceComponent.PrefsKey, 0); + return Mathf.Clamp(storedIndex, 0, ResourceModeNames.Length - 1); + } + + private static string GetToolbarLabel() + { + return $"Res:{ResourceModeNames[GetSelectedModeIndex()]}"; + } + } +} +#endif diff --git a/Editor/ToolBarExtension/New/ResourceModeToolbarDropdown.cs.meta b/Editor/ToolBarExtension/New/ResourceModeToolbarDropdown.cs.meta new file mode 100644 index 0000000..17a5b90 --- /dev/null +++ b/Editor/ToolBarExtension/New/ResourceModeToolbarDropdown.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ec58d6908c969b848a6fcb2637e7f0a5 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ToolBarExtension/New/SwitchSceneToolbarDropdown.cs b/Editor/ToolBarExtension/New/SwitchSceneToolbarDropdown.cs new file mode 100644 index 0000000..4d298d3 --- /dev/null +++ b/Editor/ToolBarExtension/New/SwitchSceneToolbarDropdown.cs @@ -0,0 +1,183 @@ +#if UNITY_6000_3_OR_NEWER +using System; +using System.Collections.Generic; +using System.IO; +using UnityEditor; +using UnityEditor.SceneManagement; +using UnityEditor.Toolbars; +using UnityEngine; + +namespace AlicizaX.Editor.Extension +{ + [InitializeOnLoad] + public static class SwitchSceneToolbarDropdown + { + private const string ElementPath = "AlicizaX/SwitchScene"; + private const string Tooltip = "Switch the active scene"; + + private static readonly string[] SearchRoots = + { + "Assets/Bundles/", + "Assets/Scenes/" + }; + + private static readonly Texture2D UnityLogoIcon; + + private struct SceneEntry + { + public string ScenePath; + public string DisplayName; + } + + static SwitchSceneToolbarDropdown() + { + UnityLogoIcon = GetIcon("UnityLogo"); + EditorSceneManager.sceneOpened += OnSceneOpened; + EditorSceneManager.activeSceneChangedInEditMode += OnActiveSceneChanged; + } + + [MainToolbarElement(ElementPath, defaultDockPosition = MainToolbarDockPosition.Left, defaultDockIndex = 1)] + public static MainToolbarElement CreateElement() + { + return new MainToolbarDropdown( + new MainToolbarContent(GetToolbarLabel(), UnityLogoIcon, Tooltip), + ShowDropdownMenu); + } + + private static void OnSceneOpened(UnityEngine.SceneManagement.Scene scene, OpenSceneMode mode) + { + MainToolbar.Refresh(ElementPath); + } + + private static void OnActiveSceneChanged(UnityEngine.SceneManagement.Scene previousScene, UnityEngine.SceneManagement.Scene newScene) + { + MainToolbar.Refresh(ElementPath); + } + + private static void ShowDropdownMenu(Rect dropdownRect) + { + var menu = new GenericMenu + { + allowDuplicateNames = true + }; + + var scenes = CollectScenes(); + var activeScenePath = EditorSceneManager.GetActiveScene().path; + + if (scenes.Count == 0) + { + menu.AddDisabledItem(new GUIContent("No scenes found")); + menu.DropDown(dropdownRect); + return; + } + + for (var i = 0; i < scenes.Count; i++) + { + var sceneEntry = scenes[i]; + menu.AddItem( + new GUIContent(sceneEntry.DisplayName), + string.Equals(sceneEntry.ScenePath, activeScenePath, StringComparison.OrdinalIgnoreCase), + () => SwitchScene(sceneEntry.ScenePath)); + } + + menu.DropDown(dropdownRect); + } + + private static List CollectScenes() + { + var sceneEntries = new List(); + var sceneGuids = AssetDatabase.FindAssets("t:Scene", SearchRoots); + + foreach (var sceneGuid in sceneGuids) + { + var scenePath = AssetDatabase.GUIDToAssetPath(sceneGuid); + sceneEntries.Add(new SceneEntry + { + ScenePath = scenePath, + DisplayName = BuildDisplayName(scenePath) + }); + } + + sceneEntries.Sort((left, right) => string.Compare(left.DisplayName, right.DisplayName, StringComparison.OrdinalIgnoreCase)); + return sceneEntries; + } + + private static string BuildDisplayName(string scenePath) + { + var sceneName = Path.GetFileNameWithoutExtension(scenePath); + var sceneDirectory = NormalizePath(Path.GetDirectoryName(scenePath)); + + foreach (var searchRoot in SearchRoots) + { + var normalizedRoot = NormalizePath(searchRoot).TrimEnd('/'); + if (!sceneDirectory.StartsWith(normalizedRoot, StringComparison.OrdinalIgnoreCase)) + { + continue; + } + + if (string.Equals(sceneDirectory, normalizedRoot, StringComparison.OrdinalIgnoreCase)) + { + return sceneName; + } + + var relativeDirectory = Path.GetRelativePath(normalizedRoot, sceneDirectory) + .Replace('\\', '/') + .Trim('/'); + + return string.IsNullOrEmpty(relativeDirectory) + ? sceneName + : $"{relativeDirectory}/{sceneName}"; + } + + return sceneName; + } + + private static string NormalizePath(string path) + { + return string.IsNullOrEmpty(path) + ? string.Empty + : path.Replace('\\', '/'); + } + + private static void SwitchScene(string scenePath) + { + var currentScene = EditorSceneManager.GetActiveScene(); + if (currentScene.IsValid() && currentScene.isDirty) + { + var optionIndex = EditorUtility.DisplayDialogComplex( + "Warning", + $"Current scene '{currentScene.name}' has unsaved changes. Save before switching?", + "Save", + "Cancel", + "Don't Save"); + + switch (optionIndex) + { + case 0: + if (!EditorSceneManager.SaveOpenScenes()) + { + return; + } + + break; + case 1: + return; + } + } + + EditorSceneManager.OpenScene(scenePath, OpenSceneMode.Single); + } + + private static string GetToolbarLabel() + { + var activeSceneName = EditorSceneManager.GetActiveScene().name; + return string.IsNullOrEmpty(activeSceneName) ? "Switch Scene" : activeSceneName; + } + + private static Texture2D GetIcon(string iconName) + { + return EditorGUIUtility.IconContent(iconName).image as Texture2D; + } + } +} +#endif diff --git a/Editor/ToolBarExtension/New/SwitchSceneToolbarDropdown.cs.meta b/Editor/ToolBarExtension/New/SwitchSceneToolbarDropdown.cs.meta new file mode 100644 index 0000000..b237d9a --- /dev/null +++ b/Editor/ToolBarExtension/New/SwitchSceneToolbarDropdown.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c78e30693afdf094c84a1f7097ba4a3a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ToolBarExtension/Old.meta b/Editor/ToolBarExtension/Old.meta new file mode 100644 index 0000000..5484df8 --- /dev/null +++ b/Editor/ToolBarExtension/Old.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 9fb5e37d60c0d9544b4ca58a3e2c7b52 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Editor/ToolBarExtension/EditorQuickToolBar.cs b/Editor/ToolBarExtension/Old/EditorQuickToolBar.cs similarity index 92% rename from Editor/ToolBarExtension/EditorQuickToolBar.cs rename to Editor/ToolBarExtension/Old/EditorQuickToolBar.cs index aeba904..f9646ec 100644 --- a/Editor/ToolBarExtension/EditorQuickToolBar.cs +++ b/Editor/ToolBarExtension/Old/EditorQuickToolBar.cs @@ -1,3 +1,4 @@ +#if !UNITY_6000_3_OR_NEWER using System; using System.Collections.Generic; using System.Linq; @@ -9,7 +10,7 @@ using UnityEngine.UIElements; namespace AlicizaX.Editor.Extension { - [Paps.UnityToolbarExtenderUIToolkit.MainToolbarElement("EditorQuickToolBar", alignment: Paps.UnityToolbarExtenderUIToolkit.ToolbarAlign.Right, order: 1)] + [MainToolbarElement("EditorQuickToolBar", alignment: ToolbarAlign.Right, order: 1)] public class EditorQuickToolBar : IMGUIContainer { private GUIContent toolsDropBtContent; @@ -60,3 +61,5 @@ namespace AlicizaX.Editor.Extension } } } + +#endif diff --git a/Editor/ToolBarExtension/EditorQuickToolBar.cs.meta b/Editor/ToolBarExtension/Old/EditorQuickToolBar.cs.meta similarity index 100% rename from Editor/ToolBarExtension/EditorQuickToolBar.cs.meta rename to Editor/ToolBarExtension/Old/EditorQuickToolBar.cs.meta diff --git a/Editor/EditorToolFunctionAttribute.cs b/Editor/ToolBarExtension/Old/EditorToolFunctionAttribute.cs similarity index 79% rename from Editor/EditorToolFunctionAttribute.cs rename to Editor/ToolBarExtension/Old/EditorToolFunctionAttribute.cs index 4e57c95..3b77398 100644 --- a/Editor/EditorToolFunctionAttribute.cs +++ b/Editor/ToolBarExtension/Old/EditorToolFunctionAttribute.cs @@ -1,3 +1,4 @@ +#if !UNITY_6000_3_OR_NEWER using System; using System.Collections.Generic; using System.Linq; @@ -7,25 +8,6 @@ using UnityEngine; namespace AlicizaX.Editor.Extension { - [AttributeUsage(AttributeTargets.Method, AllowMultiple = false, Inherited = false)] - public class EditorToolFunctionAttribute : Attribute - { - public string ToolMenuPath { get; private set; } - public int MenuOrder { get; private set; } - public MethodInfo MethodInfo { get; private set; } - - public EditorToolFunctionAttribute(string menu, int menuOrder = 0) - { - this.ToolMenuPath = menu; - MenuOrder = menuOrder; - } - - public void SetMethodInfo(MethodInfo methodInfo) - { - MethodInfo = methodInfo; - } - } - internal static class EditorToolFunctionAttributeCollector { public static List Attributes = new List(); @@ -49,7 +31,7 @@ namespace AlicizaX.Editor.Extension { try { - if(assembly.FullName.Contains("Sirenix")) continue; + if (assembly.FullName.Contains("Sirenix")) continue; // 获取程序集中的所有类型 var types = assembly.GetTypes(); @@ -89,3 +71,5 @@ namespace AlicizaX.Editor.Extension } } } + +#endif diff --git a/Editor/EditorToolFunctionAttribute.cs.meta b/Editor/ToolBarExtension/Old/EditorToolFunctionAttribute.cs.meta similarity index 100% rename from Editor/EditorToolFunctionAttribute.cs.meta rename to Editor/ToolBarExtension/Old/EditorToolFunctionAttribute.cs.meta diff --git a/Editor/ToolBarExtension/LocalizationDropdownField.cs b/Editor/ToolBarExtension/Old/LocalizationDropdownField.cs similarity index 92% rename from Editor/ToolBarExtension/LocalizationDropdownField.cs rename to Editor/ToolBarExtension/Old/LocalizationDropdownField.cs index c5224af..39e183e 100644 --- a/Editor/ToolBarExtension/LocalizationDropdownField.cs +++ b/Editor/ToolBarExtension/Old/LocalizationDropdownField.cs @@ -1,3 +1,4 @@ +#if !UNITY_6000_3_OR_NEWER using System; using System.Collections.Generic; using System.Linq; @@ -11,7 +12,7 @@ using UnityEditor.SceneManagement; using UnityEngine; using UnityEngine.UIElements; -[Paps.UnityToolbarExtenderUIToolkit.MainToolbarElement("LocalizationDropdownField", alignment: Paps.UnityToolbarExtenderUIToolkit.ToolbarAlign.Right, order: 0)] +[MainToolbarElement("LocalizationDropdownField", alignment: ToolbarAlign.Right, order: 0)] public class LocalizationDropdownField : IMGUIContainer { private GUIContent appConfigBtContent; @@ -71,8 +72,7 @@ public class LocalizationDropdownField : IMGUIContainer public static void InvokeOnValidateInScene() { - - System.Type targetType = AlicizaX.Utility.Assembly.GetType("UnityEngine.UI.UXTextMeshPro"); + Type targetType = Utility.Assembly.GetType("UnityEngine.UI.UXTextMeshPro"); MethodInfo onValidateMethod = targetType.GetMethod("OnValidate", BindingFlags.Instance | BindingFlags.NonPublic | BindingFlags.Public); if (onValidateMethod == null) @@ -109,3 +109,5 @@ public class LocalizationDropdownField : IMGUIContainer } } } + +#endif diff --git a/Editor/ToolBarExtension/LocalizationDropdownField.cs.meta b/Editor/ToolBarExtension/Old/LocalizationDropdownField.cs.meta similarity index 100% rename from Editor/ToolBarExtension/LocalizationDropdownField.cs.meta rename to Editor/ToolBarExtension/Old/LocalizationDropdownField.cs.meta diff --git a/Editor/ToolBarExtension/ResourceModeDropdownField.cs b/Editor/ToolBarExtension/Old/ResourceModeDropdownField.cs similarity index 90% rename from Editor/ToolBarExtension/ResourceModeDropdownField.cs rename to Editor/ToolBarExtension/Old/ResourceModeDropdownField.cs index 884c3f9..05f7062 100644 --- a/Editor/ToolBarExtension/ResourceModeDropdownField.cs +++ b/Editor/ToolBarExtension/Old/ResourceModeDropdownField.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +#if !UNITY_6000_3_OR_NEWER +using System.Collections.Generic; using System.Linq; using AlicizaX.Resource.Runtime; using Paps.UnityToolbarExtenderUIToolkit; @@ -9,7 +10,7 @@ using UnityEngine.UIElements; namespace AlicizaX.Editor.Extension { - [Paps.UnityToolbarExtenderUIToolkit.MainToolbarElement("ResourceModeDropdownField", alignment: Paps.UnityToolbarExtenderUIToolkit.ToolbarAlign.Right, order: 0)] + [MainToolbarElement("ResourceModeDropdownField", alignment: ToolbarAlign.Right, order: 0)] public class ResourceModeDropdownField : IMGUIContainer { private GUIContent appConfigBtContent; @@ -62,3 +63,5 @@ namespace AlicizaX.Editor.Extension } } } + +#endif diff --git a/Editor/ToolBarExtension/ResourceModeDropdownField.cs.meta b/Editor/ToolBarExtension/Old/ResourceModeDropdownField.cs.meta similarity index 100% rename from Editor/ToolBarExtension/ResourceModeDropdownField.cs.meta rename to Editor/ToolBarExtension/Old/ResourceModeDropdownField.cs.meta diff --git a/Editor/ToolBarExtension/SwitchSceneToolBar.cs b/Editor/ToolBarExtension/Old/SwitchSceneToolBar.cs similarity index 83% rename from Editor/ToolBarExtension/SwitchSceneToolBar.cs rename to Editor/ToolBarExtension/Old/SwitchSceneToolBar.cs index b380268..9a43d49 100644 --- a/Editor/ToolBarExtension/SwitchSceneToolBar.cs +++ b/Editor/ToolBarExtension/Old/SwitchSceneToolBar.cs @@ -1,4 +1,7 @@ -using System.Collections.Generic; +#if !UNITY_6000_3_OR_NEWER +using System.Collections.Generic; +using System.IO; +using AlicizaX; using Paps.UnityToolbarExtenderUIToolkit; using UnityEditor; using UnityEditor.SceneManagement; @@ -6,7 +9,7 @@ using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UIElements; -[Paps.UnityToolbarExtenderUIToolkit.MainToolbarElement(id: "SwitchSceneToolBar", alignment: Paps.UnityToolbarExtenderUIToolkit.ToolbarAlign.Left, order: 1)] +[MainToolbarElement(id: "SwitchSceneToolBar", alignment: ToolbarAlign.Left, order: 1)] public class SwitchSceneToolBar : IMGUIContainer { private GUIContent switchSceneBtContent; @@ -54,14 +57,14 @@ public class SwitchSceneToolBar : IMGUIContainer { var scenePath = AssetDatabase.GUIDToAssetPath(sceneGuids[i]); sceneAssetList.Add(scenePath); - string fileDir = System.IO.Path.GetDirectoryName(scenePath); - bool isInRootDir = AlicizaX.Utility.Path.GetRegularPath(BundleScenePath).TrimEnd('/') == - AlicizaX.Utility.Path.GetRegularPath(fileDir).TrimEnd('/'); - var sceneName = System.IO.Path.GetFileNameWithoutExtension(scenePath); + string fileDir = Path.GetDirectoryName(scenePath); + bool isInRootDir = Utility.Path.GetRegularPath(BundleScenePath).TrimEnd('/') == + Utility.Path.GetRegularPath(fileDir).TrimEnd('/'); + var sceneName = Path.GetFileNameWithoutExtension(scenePath); string displayName = sceneName; if (!isInRootDir) { - var sceneDir = System.IO.Path.GetRelativePath(RootScenePath, fileDir); + var sceneDir = Path.GetRelativePath(RootScenePath, fileDir); displayName = $"{sceneDir}/{sceneName}"; } @@ -99,3 +102,5 @@ public class SwitchSceneToolBar : IMGUIContainer } } } + +#endif diff --git a/Editor/ToolBarExtension/SwitchSceneToolBar.cs.meta b/Editor/ToolBarExtension/Old/SwitchSceneToolBar.cs.meta similarity index 100% rename from Editor/ToolBarExtension/SwitchSceneToolBar.cs.meta rename to Editor/ToolBarExtension/Old/SwitchSceneToolBar.cs.meta