Update ShaderVariantCollector
parent
c37b5e52ac
commit
9397a0ebae
|
@ -8,7 +8,14 @@ namespace YooAsset.Editor
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 停靠窗口类型集合
|
/// 停靠窗口类型集合
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public static readonly Type[] DockedWindowTypes = { typeof(AssetBundleBuilderWindow), typeof(AssetBundleCollectorWindow), typeof(AssetBundleDebuggerWindow), typeof(AssetBundleReporterWindow)};
|
public static readonly Type[] DockedWindowTypes =
|
||||||
|
{
|
||||||
|
typeof(AssetBundleBuilderWindow),
|
||||||
|
typeof(AssetBundleCollectorWindow),
|
||||||
|
typeof(AssetBundleDebuggerWindow),
|
||||||
|
typeof(AssetBundleReporterWindow),
|
||||||
|
typeof(ShaderVariantCollectorWindow)
|
||||||
|
};
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,8 @@ using UnityEditor;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public static class ShaderVariantCollectionReadme
|
[Serializable]
|
||||||
|
public class ShaderVariantCollectionManifest
|
||||||
{
|
{
|
||||||
[Serializable]
|
[Serializable]
|
||||||
public class ShaderVariantElement
|
public class ShaderVariantElement
|
||||||
|
@ -44,52 +45,49 @@ namespace YooAsset.Editor
|
||||||
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
|
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
|
||||||
}
|
}
|
||||||
|
|
||||||
[Serializable]
|
|
||||||
public class ShaderVariantCollectionManifest
|
/// <summary>
|
||||||
|
/// Number of shaders in this collection
|
||||||
|
/// </summary>
|
||||||
|
public int ShaderTotalCount;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Number of total varians in this collection
|
||||||
|
/// </summary>
|
||||||
|
public int VariantTotalCount;
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Shader variants info list.
|
||||||
|
/// </summary>
|
||||||
|
public List<ShaderVariantInfo> ShaderVariantInfos = new List<ShaderVariantInfo>(1000);
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 添加着色器变种信息
|
||||||
|
/// </summary>
|
||||||
|
public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords)
|
||||||
{
|
{
|
||||||
/// <summary>
|
var info = GetOrCreateShaderVariantInfo(assetPath, shaderName);
|
||||||
/// Number of shaders in this collection
|
ShaderVariantElement element = new ShaderVariantElement();
|
||||||
/// </summary>
|
element.PassType = passType;
|
||||||
public int ShaderTotalCount;
|
element.Keywords = keywords;
|
||||||
|
info.ShaderVariantElements.Add(element);
|
||||||
/// <summary>
|
}
|
||||||
/// Number of total varians in this collection
|
private ShaderVariantInfo GetOrCreateShaderVariantInfo(string assetPath, string shaderName)
|
||||||
/// </summary>
|
{
|
||||||
public int VariantTotalCount;
|
var selectList = ShaderVariantInfos.Where(t => t.ShaderName == shaderName && t.AssetPath == assetPath).ToList();
|
||||||
|
if (selectList.Count == 0)
|
||||||
/// <summary>
|
|
||||||
/// Shader variants info list.
|
|
||||||
/// </summary>
|
|
||||||
public List<ShaderVariantInfo> ShaderVariantInfos = new List<ShaderVariantInfo>(1000);
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// 添加着色器变种信息
|
|
||||||
/// </summary>
|
|
||||||
public void AddShaderVariant(string assetPath, string shaderName, PassType passType, string[] keywords)
|
|
||||||
{
|
{
|
||||||
var info = GetOrCreateShaderVariantInfo(assetPath, shaderName);
|
ShaderVariantInfo newInfo = new ShaderVariantInfo();
|
||||||
ShaderVariantElement element = new ShaderVariantElement();
|
newInfo.AssetPath = assetPath;
|
||||||
element.PassType = passType;
|
newInfo.ShaderName = shaderName;
|
||||||
element.Keywords = keywords;
|
ShaderVariantInfos.Add(newInfo);
|
||||||
info.ShaderVariantElements.Add(element);
|
return newInfo;
|
||||||
}
|
}
|
||||||
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)
|
if (selectList.Count != 1)
|
||||||
throw new Exception("Should never get here !");
|
throw new Exception("Should never get here !");
|
||||||
|
|
||||||
return selectList[0];
|
return selectList[0];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -30,8 +30,8 @@ namespace YooAsset.Editor
|
||||||
// 保存结果
|
// 保存结果
|
||||||
ShaderVariantCollectionHelper.SaveCurrentShaderVariantCollection(_saveFilePath);
|
ShaderVariantCollectionHelper.SaveCurrentShaderVariantCollection(_saveFilePath);
|
||||||
|
|
||||||
// 创建说明文件
|
// 创建清单
|
||||||
CreateReadme();
|
CreateManifest();
|
||||||
|
|
||||||
Debug.Log($"搜集SVC完毕!");
|
Debug.Log($"搜集SVC完毕!");
|
||||||
_completedCallback?.Invoke();
|
_completedCallback?.Invoke();
|
||||||
|
@ -64,7 +64,7 @@ namespace YooAsset.Editor
|
||||||
ShaderVariantCollectionHelper.ClearCurrentShaderVariantCollection();
|
ShaderVariantCollectionHelper.ClearCurrentShaderVariantCollection();
|
||||||
|
|
||||||
// 创建临时测试场景
|
// 创建临时测试场景
|
||||||
CreateTemperScene();
|
CreateTempScene();
|
||||||
|
|
||||||
// 收集着色器变种
|
// 收集着色器变种
|
||||||
var materials = GetAllMaterials();
|
var materials = GetAllMaterials();
|
||||||
|
@ -76,9 +76,8 @@ namespace YooAsset.Editor
|
||||||
_elapsedTime.Start();
|
_elapsedTime.Start();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void CreateTemperScene()
|
private static void CreateTempScene()
|
||||||
{
|
{
|
||||||
// 创建临时场景
|
|
||||||
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
|
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
|
||||||
}
|
}
|
||||||
private static List<Material> GetAllMaterials()
|
private static List<Material> GetAllMaterials()
|
||||||
|
@ -186,17 +185,17 @@ namespace YooAsset.Editor
|
||||||
go.transform.position = position;
|
go.transform.position = position;
|
||||||
go.name = $"Sphere_{index}|{material.name}";
|
go.name = $"Sphere_{index}|{material.name}";
|
||||||
}
|
}
|
||||||
private static void CreateReadme()
|
private static void CreateManifest()
|
||||||
{
|
{
|
||||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||||
|
|
||||||
ShaderVariantCollection svc = AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(_saveFilePath);
|
ShaderVariantCollection svc = AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(_saveFilePath);
|
||||||
if (svc != null)
|
if (svc != null)
|
||||||
{
|
{
|
||||||
var wrapper = ShaderVariantCollectionReadme.Extract(svc);
|
var wrapper = ShaderVariantCollectionManifest.Extract(svc);
|
||||||
string jsonContents = JsonUtility.ToJson(wrapper, true);
|
string jsonData = JsonUtility.ToJson(wrapper, true);
|
||||||
string savePath = _saveFilePath.Replace(".shadervariants", "Manifest.json");
|
string savePath = _saveFilePath.Replace(".shadervariants", ".json");
|
||||||
File.WriteAllText(savePath, jsonContents);
|
File.WriteAllText(savePath, jsonData);
|
||||||
}
|
}
|
||||||
|
|
||||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||||
|
|
|
@ -1,61 +1,82 @@
|
||||||
using UnityEngine;
|
#if UNITY_2019_4_OR_NEWER
|
||||||
|
using System;
|
||||||
|
using System.Linq;
|
||||||
|
using System.Collections.Generic;
|
||||||
using UnityEditor;
|
using UnityEditor;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEditor.UIElements;
|
||||||
|
using UnityEngine.UIElements;
|
||||||
|
|
||||||
namespace YooAsset.Editor
|
namespace YooAsset.Editor
|
||||||
{
|
{
|
||||||
public class ShaderVariantCollectionWindow : EditorWindow
|
public class ShaderVariantCollectorWindow : EditorWindow
|
||||||
{
|
{
|
||||||
static ShaderVariantCollectionWindow _thisInstance;
|
|
||||||
|
|
||||||
[MenuItem("YooAsset/ShaderVariant Collector", false, 201)]
|
[MenuItem("YooAsset/ShaderVariant Collector", false, 201)]
|
||||||
static void ShowWindow()
|
public static void ShowExample()
|
||||||
{
|
{
|
||||||
if (_thisInstance == null)
|
ShaderVariantCollectorWindow window = GetWindow<ShaderVariantCollectorWindow>("着色器变种收集工具", true, EditorDefine.DockedWindowTypes);
|
||||||
{
|
window.minSize = new Vector2(800, 600);
|
||||||
_thisInstance = GetWindow<ShaderVariantCollectionWindow>("着色器变种收集工具");
|
|
||||||
_thisInstance.minSize = new Vector2(800, 600);
|
|
||||||
}
|
|
||||||
_thisInstance.Show();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private ShaderVariantCollection _selectSVC;
|
private Button _collectButton;
|
||||||
|
private TextField _collectOutputField;
|
||||||
|
private Label _currentShaderCountField;
|
||||||
|
private Label _currentVariantCountField;
|
||||||
|
|
||||||
private void OnGUI()
|
public void CreateGUI()
|
||||||
{
|
{
|
||||||
EditorGUILayout.Space();
|
try
|
||||||
ShaderVariantCollectorSettingData.Setting.SavePath = EditorGUILayout.TextField("收集文件保存路径", ShaderVariantCollectorSettingData.Setting.SavePath);
|
|
||||||
|
|
||||||
int currentShaderCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount();
|
|
||||||
int currentVariantCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionVariantCount();
|
|
||||||
EditorGUILayout.LabelField($"CurrentShaderCount : {currentShaderCount}");
|
|
||||||
EditorGUILayout.LabelField($"CurrentVariantCount : {currentVariantCount}");
|
|
||||||
|
|
||||||
// 搜集变种
|
|
||||||
EditorGUILayout.Space();
|
|
||||||
if (GUILayout.Button("搜集变种", GUILayout.MaxWidth(80)))
|
|
||||||
{
|
{
|
||||||
ShaderVariantCollector.Run(ShaderVariantCollectorSettingData.Setting.SavePath, null);
|
VisualElement root = this.rootVisualElement;
|
||||||
}
|
|
||||||
|
|
||||||
// 查询
|
// 加载布局文件
|
||||||
EditorGUILayout.Space();
|
var visualAsset = EditorHelper.LoadWindowUXML<ShaderVariantCollectorWindow>();
|
||||||
if (GUILayout.Button("查询", GUILayout.MaxWidth(80)))
|
if (visualAsset == null)
|
||||||
{
|
|
||||||
string resultPath = EditorTools.OpenFilePath("Select File", "Assets/", "shadervariants");
|
|
||||||
if (string.IsNullOrEmpty(resultPath))
|
|
||||||
return;
|
return;
|
||||||
string assetPath = EditorTools.AbsolutePathToAssetPath(resultPath);
|
|
||||||
_selectSVC = AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(assetPath);
|
visualAsset.CloneTree(root);
|
||||||
|
|
||||||
|
// 文件输出目录
|
||||||
|
_collectOutputField = root.Q<TextField>("CollectOutput");
|
||||||
|
_collectOutputField.SetValueWithoutNotify(ShaderVariantCollectorSettingData.Setting.SavePath);
|
||||||
|
_collectOutputField.RegisterValueChangedCallback(evt =>
|
||||||
|
{
|
||||||
|
ShaderVariantCollectorSettingData.Setting.SavePath = _collectOutputField.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
_currentShaderCountField = root.Q<Label>("CurrentShaderCount");
|
||||||
|
_currentVariantCountField = root.Q<Label>("CurrentVariantCount");
|
||||||
|
|
||||||
|
// 变种收集按钮
|
||||||
|
_collectButton = root.Q<Button>("CollectButton");
|
||||||
|
_collectButton.clicked += CollectButton_clicked;
|
||||||
|
|
||||||
|
//RefreshWindow();
|
||||||
}
|
}
|
||||||
if (_selectSVC != null)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
EditorGUILayout.LabelField($"ShaderCount : {_selectSVC.shaderCount}");
|
Debug.LogError(e.ToString());
|
||||||
EditorGUILayout.LabelField($"VariantCount : {_selectSVC.variantCount}");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private void OnDestroy()
|
private void Update()
|
||||||
{
|
{
|
||||||
ShaderVariantCollectorSettingData.SaveFile();
|
if (_currentShaderCountField != null)
|
||||||
|
{
|
||||||
|
int currentShaderCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount();
|
||||||
|
_currentShaderCountField.text = $"Current Shader Count : {currentShaderCount}";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (_currentVariantCountField != null)
|
||||||
|
{
|
||||||
|
int currentVariantCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionVariantCount();
|
||||||
|
_currentVariantCountField.text = $"Current Variant Count : {currentVariantCount}";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void CollectButton_clicked()
|
||||||
|
{
|
||||||
|
ShaderVariantCollector.Run(ShaderVariantCollectorSettingData.Setting.SavePath, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
#endif
|
|
@ -0,0 +1,9 @@
|
||||||
|
<ui:UXML xmlns:ui="UnityEngine.UIElements" xmlns:uie="UnityEditor.UIElements" xsi="http://www.w3.org/2001/XMLSchema-instance" engine="UnityEngine.UIElements" editor="UnityEditor.UIElements" noNamespaceSchemaLocation="../../UIElementsSchema/UIElements.xsd" editor-extension-mode="True">
|
||||||
|
<uie:Toolbar name="Toolbar" style="display: flex; flex-direction: row-reverse;" />
|
||||||
|
<ui:VisualElement name="BuildContainer">
|
||||||
|
<ui:TextField picking-mode="Ignore" label="文件保存路径" name="CollectOutput" />
|
||||||
|
<ui:Label text="Current Shader Count" display-tooltip-when-elided="true" name="CurrentShaderCount" />
|
||||||
|
<ui:Label text="Current Variant Count" display-tooltip-when-elided="true" name="CurrentVariantCount" />
|
||||||
|
<ui:Button text="开始搜集" display-tooltip-when-elided="true" name="CollectButton" style="height: 50px; background-color: rgb(40, 106, 42); margin-top: 10px;" />
|
||||||
|
</ui:VisualElement>
|
||||||
|
</ui:UXML>
|
|
@ -0,0 +1,10 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 9bff4878063eaf04dab8713e1e662ac5
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 13804, guid: 0000000000000000e000000000000000, type: 0}
|
Loading…
Reference in New Issue