Update ShaderVariantCollector
parent
c37b5e52ac
commit
9397a0ebae
|
@ -8,7 +8,14 @@ namespace YooAsset.Editor
|
|||
/// <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
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,8 @@ using UnityEditor;
|
|||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public static class ShaderVariantCollectionReadme
|
||||
[Serializable]
|
||||
public class ShaderVariantCollectionManifest
|
||||
{
|
||||
[Serializable]
|
||||
public class ShaderVariantElement
|
||||
|
@ -44,9 +45,7 @@ namespace YooAsset.Editor
|
|||
public List<ShaderVariantElement> ShaderVariantElements = new List<ShaderVariantElement>(1000);
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class ShaderVariantCollectionManifest
|
||||
{
|
||||
|
||||
/// <summary>
|
||||
/// Number of shaders in this collection
|
||||
/// </summary>
|
||||
|
@ -90,7 +89,6 @@ namespace YooAsset.Editor
|
|||
|
||||
return selectList[0];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
|
|
|
@ -30,8 +30,8 @@ namespace YooAsset.Editor
|
|||
// 保存结果
|
||||
ShaderVariantCollectionHelper.SaveCurrentShaderVariantCollection(_saveFilePath);
|
||||
|
||||
// 创建说明文件
|
||||
CreateReadme();
|
||||
// 创建清单
|
||||
CreateManifest();
|
||||
|
||||
Debug.Log($"搜集SVC完毕!");
|
||||
_completedCallback?.Invoke();
|
||||
|
@ -64,7 +64,7 @@ namespace YooAsset.Editor
|
|||
ShaderVariantCollectionHelper.ClearCurrentShaderVariantCollection();
|
||||
|
||||
// 创建临时测试场景
|
||||
CreateTemperScene();
|
||||
CreateTempScene();
|
||||
|
||||
// 收集着色器变种
|
||||
var materials = GetAllMaterials();
|
||||
|
@ -76,9 +76,8 @@ namespace YooAsset.Editor
|
|||
_elapsedTime.Start();
|
||||
}
|
||||
|
||||
private static void CreateTemperScene()
|
||||
private static void CreateTempScene()
|
||||
{
|
||||
// 创建临时场景
|
||||
EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects);
|
||||
}
|
||||
private static List<Material> GetAllMaterials()
|
||||
|
@ -186,17 +185,17 @@ namespace YooAsset.Editor
|
|||
go.transform.position = position;
|
||||
go.name = $"Sphere_{index}|{material.name}";
|
||||
}
|
||||
private static void CreateReadme()
|
||||
private static void CreateManifest()
|
||||
{
|
||||
AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
|
||||
|
||||
ShaderVariantCollection svc = AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(_saveFilePath);
|
||||
if (svc != null)
|
||||
{
|
||||
var wrapper = ShaderVariantCollectionReadme.Extract(svc);
|
||||
string jsonContents = JsonUtility.ToJson(wrapper, true);
|
||||
string savePath = _saveFilePath.Replace(".shadervariants", "Manifest.json");
|
||||
File.WriteAllText(savePath, jsonContents);
|
||||
var wrapper = ShaderVariantCollectionManifest.Extract(svc);
|
||||
string jsonData = JsonUtility.ToJson(wrapper, true);
|
||||
string savePath = _saveFilePath.Replace(".shadervariants", ".json");
|
||||
File.WriteAllText(savePath, jsonData);
|
||||
}
|
||||
|
||||
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 UnityEngine;
|
||||
using UnityEditor.UIElements;
|
||||
using UnityEngine.UIElements;
|
||||
|
||||
namespace YooAsset.Editor
|
||||
{
|
||||
public class ShaderVariantCollectionWindow : EditorWindow
|
||||
public class ShaderVariantCollectorWindow : EditorWindow
|
||||
{
|
||||
static ShaderVariantCollectionWindow _thisInstance;
|
||||
|
||||
[MenuItem("YooAsset/ShaderVariant Collector", false, 201)]
|
||||
static void ShowWindow()
|
||||
public static void ShowExample()
|
||||
{
|
||||
if (_thisInstance == null)
|
||||
{
|
||||
_thisInstance = GetWindow<ShaderVariantCollectionWindow>("着色器变种收集工具");
|
||||
_thisInstance.minSize = new Vector2(800, 600);
|
||||
}
|
||||
_thisInstance.Show();
|
||||
ShaderVariantCollectorWindow window = GetWindow<ShaderVariantCollectorWindow>("着色器变种收集工具", true, EditorDefine.DockedWindowTypes);
|
||||
window.minSize = new Vector2(800, 600);
|
||||
}
|
||||
|
||||
private ShaderVariantCollection _selectSVC;
|
||||
private Button _collectButton;
|
||||
private TextField _collectOutputField;
|
||||
private Label _currentShaderCountField;
|
||||
private Label _currentVariantCountField;
|
||||
|
||||
private void OnGUI()
|
||||
public void CreateGUI()
|
||||
{
|
||||
EditorGUILayout.Space();
|
||||
ShaderVariantCollectorSettingData.Setting.SavePath = EditorGUILayout.TextField("收集文件保存路径", ShaderVariantCollectorSettingData.Setting.SavePath);
|
||||
try
|
||||
{
|
||||
VisualElement root = this.rootVisualElement;
|
||||
|
||||
// 加载布局文件
|
||||
var visualAsset = EditorHelper.LoadWindowUXML<ShaderVariantCollectorWindow>();
|
||||
if (visualAsset == null)
|
||||
return;
|
||||
|
||||
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();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
Debug.LogError(e.ToString());
|
||||
}
|
||||
}
|
||||
private void Update()
|
||||
{
|
||||
if (_currentShaderCountField != null)
|
||||
{
|
||||
int currentShaderCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionShaderCount();
|
||||
int currentVariantCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionVariantCount();
|
||||
EditorGUILayout.LabelField($"CurrentShaderCount : {currentShaderCount}");
|
||||
EditorGUILayout.LabelField($"CurrentVariantCount : {currentVariantCount}");
|
||||
_currentShaderCountField.text = $"Current Shader Count : {currentShaderCount}";
|
||||
}
|
||||
|
||||
// 搜集变种
|
||||
EditorGUILayout.Space();
|
||||
if (GUILayout.Button("搜集变种", GUILayout.MaxWidth(80)))
|
||||
if (_currentVariantCountField != null)
|
||||
{
|
||||
int currentVariantCount = ShaderVariantCollectionHelper.GetCurrentShaderVariantCollectionVariantCount();
|
||||
_currentVariantCountField.text = $"Current Variant Count : {currentVariantCount}";
|
||||
}
|
||||
}
|
||||
|
||||
private void CollectButton_clicked()
|
||||
{
|
||||
ShaderVariantCollector.Run(ShaderVariantCollectorSettingData.Setting.SavePath, null);
|
||||
}
|
||||
|
||||
// 查询
|
||||
EditorGUILayout.Space();
|
||||
if (GUILayout.Button("查询", GUILayout.MaxWidth(80)))
|
||||
{
|
||||
string resultPath = EditorTools.OpenFilePath("Select File", "Assets/", "shadervariants");
|
||||
if (string.IsNullOrEmpty(resultPath))
|
||||
return;
|
||||
string assetPath = EditorTools.AbsolutePathToAssetPath(resultPath);
|
||||
_selectSVC = AssetDatabase.LoadAssetAtPath<ShaderVariantCollection>(assetPath);
|
||||
}
|
||||
if (_selectSVC != null)
|
||||
{
|
||||
EditorGUILayout.LabelField($"ShaderCount : {_selectSVC.shaderCount}");
|
||||
EditorGUILayout.LabelField($"VariantCount : {_selectSVC.variantCount}");
|
||||
}
|
||||
}
|
||||
private void OnDestroy()
|
||||
{
|
||||
ShaderVariantCollectorSettingData.SaveFile();
|
||||
}
|
||||
}
|
||||
}
|
||||
#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