diff --git a/Assets/YooAsset/Editor/EditorDefine.cs b/Assets/YooAsset/Editor/EditorDefine.cs
index 1cff7da..97de1de 100644
--- a/Assets/YooAsset/Editor/EditorDefine.cs
+++ b/Assets/YooAsset/Editor/EditorDefine.cs
@@ -13,8 +13,7 @@ namespace YooAsset.Editor
typeof(AssetBundleBuilderWindow),
typeof(AssetBundleCollectorWindow),
typeof(AssetBundleDebuggerWindow),
- typeof(AssetBundleReporterWindow),
- typeof(ShaderVariantCollectorWindow)
+ typeof(AssetBundleReporterWindow)
};
#endif
}
diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectionHelper.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectionHelper.cs
deleted file mode 100644
index 816079a..0000000
--- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectionHelper.cs
+++ /dev/null
@@ -1,40 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using UnityEngine;
-using UnityEngine.Rendering;
-using UnityEditor;
-
-namespace YooAsset.Editor
-{
- public static class ShaderVariantCollectionHelper
- {
- public static void ClearCurrentShaderVariantCollection()
- {
- EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "ClearCurrentShaderVariantCollection");
- }
- public static void SaveCurrentShaderVariantCollection(string savePath)
- {
- EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "SaveCurrentShaderVariantCollection", savePath);
- }
- public static int GetCurrentShaderVariantCollectionShaderCount()
- {
- return (int)EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionShaderCount");
- }
- public static int GetCurrentShaderVariantCollectionVariantCount()
- {
- return (int)EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetCurrentShaderVariantCollectionVariantCount");
- }
-
- ///
- /// 获取着色器的变种总数量
- ///
- public static string GetShaderVariantCount(string assetPath)
- {
- Shader shader = AssetDatabase.LoadAssetAtPath(assetPath);
- var variantCount = EditorTools.InvokeNonPublicStaticMethod(typeof(ShaderUtil), "GetVariantCount", shader, true);
- return variantCount.ToString();
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectionManifest.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectionManifest.cs
deleted file mode 100644
index 472638e..0000000
--- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectionManifest.cs
+++ /dev/null
@@ -1,149 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using UnityEngine;
-using UnityEngine.Rendering;
-using UnityEditor;
-
-namespace YooAsset.Editor
-{
- [Serializable]
- public class ShaderVariantCollectionManifest
- {
- [Serializable]
- public class ShaderVariantElement
- {
- ///
- /// Pass type to use in this variant.
- ///
- public PassType PassType;
-
- ///
- /// Array of shader keywords to use in this variant.
- ///
- public string[] Keywords;
- }
-
- [Serializable]
- public class ShaderVariantInfo
- {
- ///
- /// 着色器资源路径.
- ///
- public string AssetPath;
-
- ///
- /// 着色器名称
- ///
- public string ShaderName;
-
- ///
- /// 着色器变种总数
- ///
- public int ShaderVariantCount = 0;
-
- ///
- /// 着色器变种列表
- ///
- public List ShaderVariantElements = new List(1000);
- }
-
-
- ///
- /// Number of shaders in this collection
- ///
- public int ShaderTotalCount;
-
- ///
- /// Number of total varians in this collection
- ///
- public int VariantTotalCount;
-
- ///
- /// Shader variants info list.
- ///
- public List ShaderVariantInfos = new List(1000);
-
- ///
- /// 添加着色器变种信息
- ///
- public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords)
- {
- var info = GetOrCreateShaderVariantInfo(assetPath, shaderName);
- ShaderVariantElement element = new ShaderVariantElement();
- element.PassType = passType;
- element.Keywords = keywords;
- info.ShaderVariantElements.Add(element);
- info.ShaderVariantCount++;
- }
- private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName)
- {
- var selectList = ShaderVariantInfos.Where(t => t.ShaderName == shaderName && t.AssetPath == assetPath).ToList();
- if (selectList.Count == 0)
- {
- ShaderVariantInfo newInfo = new ShaderVariantInfo();
- newInfo.AssetPath = assetPath;
- newInfo.ShaderName = shaderName;
- ShaderVariantInfos.Add(newInfo);
- return newInfo;
- }
-
- if (selectList.Count != 1)
- throw new Exception("Should never get here !");
-
- return selectList[0];
- }
-
-
- ///
- /// 解析SVC文件并将数据写入到清单
- ///
- public static ShaderVariantCollectionManifest Extract(ShaderVariantCollection svc)
- {
- var manifest = new ShaderVariantCollectionManifest();
- manifest.ShaderTotalCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount();
- manifest.VariantTotalCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionVariantCount();
-
- using (var so = new SerializedObject(svc))
- {
- var shaderArray = so.FindProperty("m_Shaders.Array");
- if (shaderArray != null && shaderArray.isArray)
- {
- for (int i = 0; i < shaderArray.arraySize; ++i)
- {
- var shaderRef = shaderArray.FindPropertyRelative($"data[{i}].first");
- var shaderVariantsArray = shaderArray.FindPropertyRelative($"data[{i}].second.variants");
- if (shaderRef != null && shaderRef.propertyType == SerializedPropertyType.ObjectReference && shaderVariantsArray != null && shaderVariantsArray.isArray)
- {
- var shader = shaderRef.objectReferenceValue as Shader;
- if (shader == null)
- {
- throw new Exception("Invalid shader in ShaderVariantCollection file.");
- }
-
- string shaderAssetPath = AssetDatabase.GetAssetPath(shader);
- string shaderName = shader.name;
-
- // 添加变种信息
- for (int j = 0; j < shaderVariantsArray.arraySize; ++j)
- {
- var propKeywords = shaderVariantsArray.FindPropertyRelative($"Array.data[{j}].keywords");
- var propPassType = shaderVariantsArray.FindPropertyRelative($"Array.data[{j}].passType");
- if (propKeywords != null && propPassType != null && propKeywords.propertyType == SerializedPropertyType.String)
- {
- string[] keywords = propKeywords.stringValue.Split(' ');
- PassType pathType = (PassType)propPassType.intValue;
- manifest.AddShaderVariant(shaderAssetPath, shaderName, pathType, keywords);
- }
- }
- }
- }
- }
- }
-
- return manifest;
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollector.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollector.cs
deleted file mode 100644
index 420e7e4..0000000
--- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollector.cs
+++ /dev/null
@@ -1,258 +0,0 @@
-using System;
-using System.Collections.Generic;
-using System.Diagnostics;
-using System.Linq;
-using System.IO;
-using UnityEngine;
-using UnityEditor;
-using UnityEditor.SceneManagement;
-using Debug = UnityEngine.Debug;
-
-namespace YooAsset.Editor
-{
- public static class ShaderVariantCollector
- {
- private enum ESteps
- {
- None,
- Prepare,
- CollectAllMaterial,
- CollectVariants,
- CollectSleeping,
- WaitingDone,
- }
-
- private const float WaitMilliseconds = 1000f;
- private const float SleepMilliseconds = 100f;
- private static string _savePath;
- private static string _packageName;
- private static int _processMaxNum;
- private static Action _completedCallback;
-
- private static ESteps _steps = ESteps.None;
- private static Stopwatch _elapsedTime;
- private static List _allMaterials;
- private static List _allSpheres = new List(1000);
-
-
- ///
- /// 开始收集
- ///
- public static void Run(string savePath, string packageName, int processMaxNum, Action completedCallback)
- {
- if (_steps != ESteps.None)
- return;
-
- if (Path.HasExtension(savePath) == false)
- savePath = $"{savePath}.shadervariants";
- if (Path.GetExtension(savePath) != ".shadervariants")
- throw new System.Exception("Shader variant file extension is invalid.");
- if (string.IsNullOrEmpty(packageName))
- throw new System.Exception("Package name is null or empty !");
-
- // 注意:先删除再保存,否则ShaderVariantCollection内容将无法及时刷新
- AssetDatabase.DeleteAsset(savePath);
- EditorTools.CreateFileDirectory(savePath);
- _savePath = savePath;
- _packageName = packageName;
- _processMaxNum = processMaxNum;
- _completedCallback = completedCallback;
-
- // 聚焦到游戏窗口
- EditorTools.FocusUnityGameWindow();
-
- // 创建临时测试场景
- CreateTempScene();
-
- _steps = ESteps.Prepare;
- EditorApplication.update += EditorUpdate;
- }
-
- private static void EditorUpdate()
- {
- if (_steps == ESteps.None)
- return;
-
- if (_steps == ESteps.Prepare)
- {
- ShaderVariantCollectionHelper.ClearCurrentShaderVariantCollection();
- _steps = ESteps.CollectAllMaterial;
- return; //等待一帧
- }
-
- if (_steps == ESteps.CollectAllMaterial)
- {
- _allMaterials = GetAllMaterials();
- _steps = ESteps.CollectVariants;
- return; //等待一帧
- }
-
- if (_steps == ESteps.CollectVariants)
- {
- int count = Mathf.Min(_processMaxNum, _allMaterials.Count);
- List range = _allMaterials.GetRange(0, count);
- _allMaterials.RemoveRange(0, count);
- CollectVariants(range);
-
- if (_allMaterials.Count > 0)
- {
- _elapsedTime = Stopwatch.StartNew();
- _steps = ESteps.CollectSleeping;
- }
- else
- {
- _elapsedTime = Stopwatch.StartNew();
- _steps = ESteps.WaitingDone;
- }
- }
-
- if (_steps == ESteps.CollectSleeping)
- {
- if (_elapsedTime.ElapsedMilliseconds > SleepMilliseconds)
- {
- DestroyAllSpheres();
- _elapsedTime.Stop();
- _steps = ESteps.CollectVariants;
- }
- }
-
- if (_steps == ESteps.WaitingDone)
- {
- // 注意:一定要延迟保存才会起效
- if (_elapsedTime.ElapsedMilliseconds > WaitMilliseconds)
- {
- _elapsedTime.Stop();
- _steps = ESteps.None;
-
- // 保存结果并创建清单
- ShaderVariantCollectionHelper.SaveCurrentShaderVariantCollection(_savePath);
- CreateManifest();
-
- Debug.Log($"搜集SVC完毕!");
- EditorApplication.update -= EditorUpdate;
- _completedCallback?.Invoke();
- }
- }
- }
- private static void CreateTempScene()
- {
- EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
- }
- private static List GetAllMaterials()
- {
- int progressValue = 0;
- List allAssets = new List(1000);
-
- // 获取所有打包的资源
- CollectResult collectResult = AssetBundleCollectorSettingData.Setting.GetPackageAssets(EBuildMode.DryRunBuild, _packageName);
- foreach (var assetInfo in collectResult.CollectAssets)
- {
- string[] depends = AssetDatabase.GetDependencies(assetInfo.AssetPath, true);
- foreach (var dependAsset in depends)
- {
- if (allAssets.Contains(dependAsset) == false)
- allAssets.Add(dependAsset);
- }
- EditorTools.DisplayProgressBar("获取所有打包资源", ++progressValue, collectResult.CollectAssets.Count);
- }
- EditorTools.ClearProgressBar();
-
- // 搜集所有材质球
- progressValue = 0;
- List allMaterial = new List(1000);
- foreach (var assetPath in allAssets)
- {
- System.Type assetType = AssetDatabase.GetMainAssetTypeAtPath(assetPath);
- if (assetType == typeof(UnityEngine.Material))
- {
- allMaterial.Add(assetPath);
- }
- EditorTools.DisplayProgressBar("搜集所有材质球", ++progressValue, allAssets.Count);
- }
- EditorTools.ClearProgressBar();
-
- // 返回结果
- return allMaterial;
- }
- private static void CollectVariants(List materials)
- {
- Camera camera = Camera.main;
- if (camera == null)
- throw new System.Exception("Not found main camera.");
-
- // 设置主相机
- float aspect = camera.aspect;
- int totalMaterials = materials.Count;
- float height = Mathf.Sqrt(totalMaterials / aspect) + 1;
- float width = Mathf.Sqrt(totalMaterials / aspect) * aspect + 1;
- float halfHeight = Mathf.CeilToInt(height / 2f);
- float halfWidth = Mathf.CeilToInt(width / 2f);
- camera.orthographic = true;
- camera.orthographicSize = halfHeight;
- camera.transform.position = new Vector3(0f, 0f, -10f);
-
- // 创建测试球体
- int xMax = (int)(width - 1);
- int x = 0, y = 0;
- int progressValue = 0;
- for (int i = 0; i < materials.Count; i++)
- {
- var material = materials[i];
- var position = new Vector3(x - halfWidth + 1f, y - halfHeight + 1f, 0f);
- var go = CreateSphere(material, position, i);
- if (go != null)
- _allSpheres.Add(go);
- if (x == xMax)
- {
- x = 0;
- y++;
- }
- else
- {
- x++;
- }
- EditorTools.DisplayProgressBar("照射所有材质球", ++progressValue, materials.Count);
- }
- EditorTools.ClearProgressBar();
- }
- private static GameObject CreateSphere(string assetPath, Vector3 position, int index)
- {
- var material = AssetDatabase.LoadAssetAtPath(assetPath);
- var shader = material.shader;
- if (shader == null)
- return null;
-
- var go = GameObject.CreatePrimitive(PrimitiveType.Sphere);
- go.GetComponent().sharedMaterial = material;
- go.transform.position = position;
- go.name = $"Sphere_{index} | {material.name}";
- return go;
- }
- private static void DestroyAllSpheres()
- {
- foreach(var go in _allSpheres)
- {
- GameObject.DestroyImmediate(go);
- }
- _allSpheres.Clear();
-
- // 尝试释放编辑器加载的资源
- EditorUtility.UnloadUnusedAssetsImmediate(true);
- }
- private static void CreateManifest()
- {
- AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
-
- ShaderVariantCollection svc = AssetDatabase.LoadAssetAtPath(_savePath);
- if (svc != null)
- {
- var wrapper = ShaderVariantCollectionManifest.Extract(svc);
- string jsonData = JsonUtility.ToJson(wrapper, true);
- string savePath = _savePath.Replace(".shadervariants", ".json");
- File.WriteAllText(savePath, jsonData);
- }
-
- AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs
deleted file mode 100644
index 135031b..0000000
--- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSetting.cs
+++ /dev/null
@@ -1,23 +0,0 @@
-using UnityEngine;
-
-namespace YooAsset.Editor
-{
- [CreateAssetMenu(fileName = "ShaderVariantCollectorSetting", menuName = "YooAsset/Create ShaderVariant Collector Settings")]
- public class ShaderVariantCollectorSetting : ScriptableObject
- {
- ///
- /// 文件存储路径
- ///
- public string SavePath = "Assets/MyShaderVariants.shadervariants";
-
- ///
- /// 收集的包裹名称
- ///
- public string CollectPackage = string.Empty;
-
- ///
- /// 容器值
- ///
- public int ProcessCapacity = 1000;
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs
deleted file mode 100644
index 7b097cf..0000000
--- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs
+++ /dev/null
@@ -1,49 +0,0 @@
-using System;
-using System.Collections;
-using System.Collections.Generic;
-using UnityEngine;
-using UnityEditor;
-
-namespace YooAsset.Editor
-{
- public class ShaderVariantCollectorSettingData
- {
- private static ShaderVariantCollectorSetting _setting = null;
- public static ShaderVariantCollectorSetting Setting
- {
- get
- {
- if (_setting == null)
- LoadSettingData();
- return _setting;
- }
- }
-
- ///
- /// 配置数据是否被修改
- ///
- public static bool IsDirty { set; get; } = false;
-
- ///
- /// 加载配置文件
- ///
- private static void LoadSettingData()
- {
- _setting = SettingLoader.LoadSettingData();
- }
-
- ///
- /// 存储文件
- ///
- public static void SaveFile()
- {
- if (Setting != null)
- {
- IsDirty = false;
- EditorUtility.SetDirty(Setting);
- AssetDatabase.SaveAssets();
- Debug.Log($"{nameof(ShaderVariantCollectorSetting)}.asset is saved!");
- }
- }
- }
-}
\ No newline at end of file
diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs.meta b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs.meta
deleted file mode 100644
index cfd2f74..0000000
--- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorSettingData.cs.meta
+++ /dev/null
@@ -1,11 +0,0 @@
-fileFormatVersion: 2
-guid: b3043e89ff35bd346b268c0e8d460067
-MonoImporter:
- externalObjects: {}
- serializedVersion: 2
- defaultReferences: []
- executionOrder: 0
- icon: {instanceID: 0}
- userData:
- assetBundleName:
- assetBundleVariant:
diff --git a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs b/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs
deleted file mode 100644
index a1f39c2..0000000
--- a/Assets/YooAsset/Editor/ShaderVariantCollector/ShaderVariantCollectorWindow.cs
+++ /dev/null
@@ -1,185 +0,0 @@
-#if UNITY_2019_4_OR_NEWER
-using System;
-using System.Linq;
-using System.Collections.Generic;
-using UnityEditor;
-using UnityEngine;
-using UnityEditor.UIElements;
-using UnityEngine.UIElements;
-
-namespace YooAsset.Editor
-{
- public class ShaderVariantCollectorWindow : EditorWindow
- {
- [MenuItem("YooAsset/ShaderVariant Collector", false, 201)]
- public static void OpenWindow()
- {
- ShaderVariantCollectorWindow window = GetWindow("着色器变种收集工具", true, WindowsDefine.DockedWindowTypes);
- window.minSize = new Vector2(800, 600);
- }
-
- private List _packageNames;
-
- private Button _saveButton;
- private Button _collectButton;
- private TextField _collectOutputField;
- private Label _currentShaderCountField;
- private Label _currentVariantCountField;
- private SliderInt _processCapacitySlider;
- private PopupField _packageField;
-
- public void CreateGUI()
- {
- try
- {
- VisualElement root = this.rootVisualElement;
-
- // 加载布局文件
- var visualAsset = UxmlLoader.LoadWindowUXML();
- if (visualAsset == null)
- return;
-
- visualAsset.CloneTree(root);
-
- // 配置保存按钮
- _saveButton = root.Q