#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; using YooAsset.Editor; public class ShaderVariantCollectorWindow : EditorWindow { [MenuItem("YooAsset/Tools/着色器变种收集器", false, 100)] public static void OpenWindow() { ShaderVariantCollectorWindow window = GetWindow("着色器变种收集工具", true); window.minSize = new Vector2(800, 600); } private Button _collectButton; private TextField _collectOutputField; private Label _currentShaderCountField; private Label _currentVariantCountField; private SliderInt _processCapacitySlider; private PopupField _packageField; private List _packageNames; private string _currentPackageName; public void CreateGUI() { try { VisualElement root = this.rootVisualElement; // 加载布局文件 var visualAsset = UxmlLoader.LoadWindowUXML(); if (visualAsset == null) return; visualAsset.CloneTree(root); // 包裹名称列表 _packageNames = GetBuildPackageNames(); _currentPackageName = _packageNames[0]; // 文件输出目录 _collectOutputField = root.Q("CollectOutput"); _collectOutputField.SetValueWithoutNotify(ShaderVariantCollectorSetting.GeFileSavePath(_currentPackageName)); _collectOutputField.RegisterValueChangedCallback(evt => { ShaderVariantCollectorSetting.SetFileSavePath(_currentPackageName, _collectOutputField.value); }); // 收集的包裹 var packageContainer = root.Q("PackageContainer"); if (_packageNames.Count > 0) { int defaultIndex = GetDefaultPackageIndex(_currentPackageName); _packageField = new PopupField(_packageNames, defaultIndex); _packageField.label = "Package"; _packageField.style.width = 350; _packageField.RegisterValueChangedCallback(evt => { _currentPackageName = _packageField.value; }); packageContainer.Add(_packageField); } else { _packageField = new PopupField(); _packageField.label = "Package"; _packageField.style.width = 350; packageContainer.Add(_packageField); } // 容器值 _processCapacitySlider = root.Q("ProcessCapacity"); _processCapacitySlider.SetValueWithoutNotify(ShaderVariantCollectorSetting.GeProcessCapacity(_currentPackageName)); #if !UNITY_2020_3_OR_NEWER _processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})"; _processCapacitySlider.RegisterValueChangedCallback(evt => { ShaderVariantCollectorSetting.SetProcessCapacity(_currentPackageName, _processCapacitySlider.value); _processCapacitySlider.label = $"Capacity ({_processCapacitySlider.value})"; }); #else _processCapacitySlider.RegisterValueChangedCallback(evt => { ShaderVariantCollectorSetting.SetProcessCapacity(_currentPackageName, _processCapacitySlider.value); }); #endif _currentShaderCountField = root.Q