private void OnDrawCollector() { // 列表显示 EditorGUILayout.Space(); EditorGUILayout.LabelField($"[ Collector ]"); for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++) { var collector = AssetBundleCollectorSettingData.Setting.Collectors[i]; string directory = collector.CollectDirectory; string labelClassName = collector.LabelClassName; string filterClassName = collector.FilterClassName; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(directory); // 标签类 { int index = LabelClassNameToIndex(labelClassName); int newIndex = EditorGUILayout.Popup(index, _labelClassArray, GUILayout.MaxWidth(150)); if (newIndex != index) { labelClassName = IndexToLabelClassName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, labelClassName, filterClassName); } } // 过滤类 { int index = FilterClassNameToIndex(filterClassName); int newIndex = EditorGUILayout.Popup(index, _filterClassArray, GUILayout.MaxWidth(150)); if (newIndex != index) { filterClassName = IndexToFilterClassName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, labelClassName, filterClassName); } } if (GUILayout.Button("-", GUILayout.MaxWidth(40))) { AssetBundleCollectorSettingData.RemoveCollector(directory); break; } } EditorGUILayout.EndHorizontal(); } // 添加按钮 if (GUILayout.Button("+")) { string resultPath = EditorTools.OpenFolderPanel("Select Folder", _lastOpenFolderPath); if (resultPath != null) { _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); AssetBundleCollectorSettingData.AddCollector(_lastOpenFolderPath); } } }
private void OnDrawElement() { // 列表显示 EditorGUILayout.Space(); EditorGUILayout.LabelField($"Collector"); for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++) { string directory = AssetBundleCollectorSettingData.Setting.Collectors[i].CollectDirectory; AssetBundleCollectorSetting.ECollectRule packRule = AssetBundleCollectorSettingData.Setting.Collectors[i].CollectRule; string collectorName = AssetBundleCollectorSettingData.Setting.Collectors[i].CollectorName; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(directory); AssetBundleCollectorSetting.ECollectRule newPackRule = (AssetBundleCollectorSetting.ECollectRule)EditorGUILayout.EnumPopup(packRule, GUILayout.MaxWidth(150)); if (newPackRule != packRule) { packRule = newPackRule; AssetBundleCollectorSettingData.ModifyCollector(directory, packRule, collectorName); } int index = NameToIndex(collectorName); int newIndex = EditorGUILayout.Popup(index, _collectorClassArray, GUILayout.MaxWidth(150)); if (newIndex != index) { string newCollectorName = IndexToName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, packRule, newCollectorName); } if (GUILayout.Button("-", GUILayout.MaxWidth(40))) { AssetBundleCollectorSettingData.RemoveCollector(directory); break; } } EditorGUILayout.EndHorizontal(); } // 添加按钮 if (GUILayout.Button("+")) { string resultPath = EditorTools.OpenFolderPanel("Select Folder", _lastOpenFolderPath); if (resultPath != null) { _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); AssetBundleCollectorSettingData.AddCollector(_lastOpenFolderPath); } } }
public static void ImportXmlConfig(string filePath) { if (File.Exists(filePath) == false) { throw new FileNotFoundException(filePath); } if (Path.GetExtension(filePath) != ".xml") { throw new Exception($"Only support xml : {filePath}"); } List <CollectWrapper> wrappers = new List <CollectWrapper>(); // 加载文件 XmlDocument xml = new XmlDocument(); xml.Load(filePath); // 解析文件 XmlElement root = xml.DocumentElement; XmlNodeList nodeList = root.GetElementsByTagName(XmlCollector); if (nodeList.Count == 0) { throw new Exception($"Not found any {XmlCollector}"); } foreach (XmlNode node in nodeList) { XmlElement collect = node as XmlElement; string directory = collect.GetAttribute(XmlDirectory); string packRuleName = collect.GetAttribute(XmlPackRule); string filterRuleName = collect.GetAttribute(XmlFilterRule); string dontWriteAssetPath = collect.GetAttribute(XmlDontWriteAssetPath); string assetTags = collect.GetAttribute(XmlAssetTags); if (Directory.Exists(directory) == false) { throw new Exception($"Not found directory : {directory}"); } if (collect.HasAttribute(XmlPackRule) == false) { throw new Exception($"Not found attribute {XmlPackRule} in collector : {directory}"); } if (collect.HasAttribute(XmlFilterRule) == false) { throw new Exception($"Not found attribute {XmlFilterRule} in collector : {directory}"); } if (collect.HasAttribute(XmlDontWriteAssetPath) == false) { throw new Exception($"Not found attribute {XmlDontWriteAssetPath} in collector : {directory}"); } if (collect.HasAttribute(XmlAssetTags) == false) { throw new Exception($"Not found attribute {XmlAssetTags} in collector : {directory}"); } if (AssetBundleCollectorSettingData.HasPackRuleName(packRuleName) == false) { throw new Exception($"Invalid {nameof(IPackRule)} class type : {packRuleName}"); } if (AssetBundleCollectorSettingData.HasFilterRuleName(filterRuleName) == false) { throw new Exception($"Invalid {nameof(IFilterRule)} class type : {filterRuleName}"); } bool dontWriteAssetPathValue = StringConvert.StringToBool(dontWriteAssetPath); CollectWrapper collectWrapper = new CollectWrapper(directory, packRuleName, filterRuleName, dontWriteAssetPathValue, assetTags); wrappers.Add(collectWrapper); } // 导入配置数据 AssetBundleCollectorSettingData.ClearAllCollector(); foreach (var wrapper in wrappers) { AssetBundleCollectorSettingData.AddCollector(wrapper.CollectDirectory, wrapper.PackRuleName, wrapper.FilterRuleName, wrapper.DontWriteAssetPath, wrapper.AssetTags, false); } // 保存配置数据 AssetBundleCollectorSettingData.SaveFile(); Debug.Log($"导入配置完毕,一共导入{wrappers.Count}个收集器。"); }
private void OnDrawCollector() { // 着色器选项 EditorGUILayout.Space(); bool isCollectAllShader = EditorGUILayout.Toggle("收集所有着色器", AssetBundleCollectorSettingData.Setting.IsCollectAllShaders); if (isCollectAllShader != AssetBundleCollectorSettingData.Setting.IsCollectAllShaders) { AssetBundleCollectorSettingData.ModifyShader(isCollectAllShader, AssetBundleCollectorSettingData.Setting.ShadersBundleName); } if (isCollectAllShader) { string shadersBundleName = EditorGUILayout.TextField("AssetBundle名称", AssetBundleCollectorSettingData.Setting.ShadersBundleName); if (shadersBundleName != AssetBundleCollectorSettingData.Setting.ShadersBundleName) { AssetBundleCollectorSettingData.ModifyShader(isCollectAllShader, shadersBundleName); } } // 列表显示 EditorGUILayout.Space(); EditorGUILayout.LabelField($"[ Collector ]"); _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++) { var collector = AssetBundleCollectorSettingData.Setting.Collectors[i]; string directory = collector.CollectDirectory; string packRuleClassName = collector.PackRuleClassName; string filterRuleClassName = collector.FilterRuleClassName; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(directory); // IPackRule { int index = PackRuleClassNameToIndex(packRuleClassName); int newIndex = EditorGUILayout.Popup(index, _packRuleClassArray, GUILayout.MaxWidth(200)); if (newIndex != index) { packRuleClassName = IndexToPackRuleClassName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleClassName, filterRuleClassName); } } // IFilterRule { int index = FilterRuleClassNameToIndex(filterRuleClassName); int newIndex = EditorGUILayout.Popup(index, _filterRuleClassArray, GUILayout.MaxWidth(150)); if (newIndex != index) { filterRuleClassName = IndexToFilterRuleClassName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleClassName, filterRuleClassName); } } if (GUILayout.Button("-", GUILayout.MaxWidth(40))) { AssetBundleCollectorSettingData.RemoveCollector(directory); break; } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); // 添加按钮 if (GUILayout.Button("+")) { string resultPath = EditorTools.OpenFolderPanel("Select Folder", _lastOpenFolderPath); if (resultPath != null) { _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); string defaultPackRuleClassName = nameof(PackExplicit); string defaultFilterRuleClassName = nameof(CollectAll); AssetBundleCollectorSettingData.AddCollector(_lastOpenFolderPath, defaultPackRuleClassName, defaultFilterRuleClassName); } } // 导入配置按钮 if (GUILayout.Button("Import Config")) { string resultPath = EditorTools.OpenFilePath("Select Folder", _lastOpenFolderPath); if (resultPath != null) { CollectorConfigImporter.ImportXmlConfig(resultPath); } } }
private void OnDrawCollector() { // 列表显示 EditorGUILayout.Space(); _scrollPos = EditorGUILayout.BeginScrollView(_scrollPos); for (int i = 0; i < AssetBundleCollectorSettingData.Setting.Collectors.Count; i++) { var collector = AssetBundleCollectorSettingData.Setting.Collectors[i]; string directory = collector.CollectDirectory; string packRuleName = collector.PackRuleName; string filterRuleName = collector.FilterRuleName; bool dontWriteAssetPath = collector.DontWriteAssetPath; string assetTags = collector.AssetTags; EditorGUILayout.BeginHorizontal(); { // Directory EditorGUILayout.LabelField(directory, GUILayout.MinWidth(GuiDirecotryMinSize), GUILayout.MaxWidth(GuiDirecotryMaxSize)); // IPackRule { int index = PackRuleNameToIndex(packRuleName); int newIndex = EditorGUILayout.Popup(index, _packRuleArray, GUILayout.MinWidth(GuiPackRuleSize), GUILayout.MaxWidth(GuiPackRuleSize)); if (newIndex != index) { packRuleName = IndexToPackRuleName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); } } // IFilterRule { int index = FilterRuleNameToIndex(filterRuleName); int newIndex = EditorGUILayout.Popup(index, _filterRuleArray, GUILayout.MinWidth(GuiFilterRuleSize), GUILayout.MaxWidth(GuiFilterRuleSize)); if (newIndex != index) { filterRuleName = IndexToFilterRuleName(newIndex); AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); } } // DontWriteAssetPath { bool newToggleValue = EditorGUILayout.Toggle(dontWriteAssetPath, GUILayout.MinWidth(GuiDontWriteAssetPathSize), GUILayout.MaxWidth(GuiDontWriteAssetPathSize)); if (newToggleValue != dontWriteAssetPath) { dontWriteAssetPath = newToggleValue; AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); } } // AssetTags { string newTextValue = EditorGUILayout.TextField(assetTags, GUILayout.MinWidth(GuiAssetTagsMinSize), GUILayout.MaxWidth(GuiAssetTagsMaxSize)); if (newTextValue != assetTags) { assetTags = newTextValue; AssetBundleCollectorSettingData.ModifyCollector(directory, packRuleName, filterRuleName, dontWriteAssetPath, assetTags); } } if (GUILayout.Button("-", GUILayout.MinWidth(GuiBtnSize), GUILayout.MaxWidth(GuiBtnSize))) { AssetBundleCollectorSettingData.RemoveCollector(directory); break; } } EditorGUILayout.EndHorizontal(); } EditorGUILayout.EndScrollView(); // 添加按钮 if (GUILayout.Button("+")) { string resultPath = EditorTools.OpenFolderPanel("Select Folder", _lastOpenFolderPath); if (resultPath != null) { _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); string defaultPackRuleName = nameof(PackExplicit); string defaultFilterRuleName = nameof(CollectAll); bool defaultDontWriteAssetPathValue = false; string defaultAssetTag = string.Empty; AssetBundleCollectorSettingData.AddCollector(_lastOpenFolderPath, defaultPackRuleName, defaultFilterRuleName, defaultDontWriteAssetPathValue, defaultAssetTag); } } // 导入配置按钮 if (GUILayout.Button("Import Config")) { string resultPath = EditorTools.OpenFilePath("Select File", "Assets/", "xml"); if (resultPath != null) { CollectorConfigImporter.ImportXmlConfig(resultPath); } } }