diff --git a/Assets/YooAsset/Editor/EditorTools.cs b/Assets/YooAsset/Editor/EditorTools.cs index fc1effd..f475b1c 100644 --- a/Assets/YooAsset/Editor/EditorTools.cs +++ b/Assets/YooAsset/Editor/EditorTools.cs @@ -214,6 +214,11 @@ namespace YooAsset.Editor { EditorWindow.FocusWindowIfItsOpen(); } + public static void CloseUnityGameWindow() + { + System.Type T = Assembly.Load("UnityEditor").GetType("UnityEditor.GameView"); + EditorWindow.GetWindow(T, false, "GameView", true).Close(); + } public static void FocusUnityGameWindow() { System.Type T = Assembly.Load("UnityEditor").GetType("UnityEditor.GameView"); diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollector.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollector.cs index d895e32..18e5301 100644 --- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollector.cs +++ b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollector.cs @@ -1,4 +1,4 @@ -using System.Collections; +using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; @@ -6,21 +6,18 @@ using System.IO; using UnityEngine; using UnityEditor; using UnityEditor.SceneManagement; +using Debug = UnityEngine.Debug; namespace YooAsset.Editor { - [InitializeOnLoad] public static class ShaderVariantCollector { private const float WaitMilliseconds = 1000f; private static string _saveFilePath; private static bool _isStarted = false; private static readonly Stopwatch _elapsedTime = new Stopwatch(); + public static Action OnCompletedCallback; - static ShaderVariantCollector() - { - EditorApplication.update += EditorUpdate; - } private static void EditorUpdate() { // 注意:一定要延迟保存才会起效 @@ -28,14 +25,21 @@ namespace YooAsset.Editor { _isStarted = false; _elapsedTime.Stop(); - + + EditorApplication.update -= EditorUpdate; + // 保存结果 SaveCurrentShaderVariantCollection(); // 创建说明文件 CreateReadme(); + + Debug.Log($"搜集SVC完毕"); + + OnCompletedCallback?.Invoke(); } } + private static void CreateReadme() { AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate); @@ -59,6 +63,8 @@ namespace YooAsset.Editor { if (_isStarted) return; + + EditorApplication.update += EditorUpdate; if (Path.HasExtension(saveFilePath) == false) saveFilePath = $"{saveFilePath}.shadervariants"; @@ -83,8 +89,6 @@ namespace YooAsset.Editor _isStarted = true; _elapsedTime.Reset(); _elapsedTime.Start(); - - UnityEngine.Debug.LogWarning("已经启动着色器变种收集工作,该工具只支持在编辑器下人工操作!"); } private static void CreateTemperScene()