/// <summary> /// 编辑元素 /// </summary> public static void ModifyElement(string folderPath, CollectionSetting.EFolderPackRule packRule, CollectionSetting.EBundleLabelRule labelRule) { // 注意:这里强制修改忽略文件夹的命名规则为None if (packRule == CollectionSetting.EFolderPackRule.Ignore) { labelRule = CollectionSetting.EBundleLabelRule.None; } else { if (labelRule == CollectionSetting.EBundleLabelRule.None) { labelRule = CollectionSetting.EBundleLabelRule.LabelByFilePath; } } for (int i = 0; i < Setting.Elements.Count; i++) { if (Setting.Elements[i].FolderPath == folderPath) { Setting.Elements[i].PackRule = packRule; Setting.Elements[i].LabelRule = labelRule; break; } } SaveFile(); }
private void OnGUI() { // 列表显示 EditorGUILayout.Space(); EditorGUILayout.LabelField($"Collection List"); for (int i = 0; i < CollectionSettingData.Setting.Elements.Count; i++) { string folderPath = CollectionSettingData.Setting.Elements[i].FolderPath; CollectionSetting.EFolderPackRule packRule = CollectionSettingData.Setting.Elements[i].PackRule; CollectionSetting.EBundleLabelRule labelRule = CollectionSettingData.Setting.Elements[i].LabelRule; EditorGUILayout.BeginHorizontal(); { EditorGUILayout.LabelField(folderPath); CollectionSetting.EFolderPackRule newPackRule = (CollectionSetting.EFolderPackRule)EditorGUILayout.EnumPopup(packRule, GUILayout.MaxWidth(150)); if (newPackRule != packRule) { packRule = newPackRule; CollectionSettingData.ModifyElement(folderPath, packRule, labelRule); } CollectionSetting.EBundleLabelRule newLabelRule = (CollectionSetting.EBundleLabelRule)EditorGUILayout.EnumPopup(labelRule, GUILayout.MaxWidth(150)); if (newLabelRule != labelRule) { labelRule = newLabelRule; CollectionSettingData.ModifyElement(folderPath, packRule, labelRule); } if (GUILayout.Button("-", GUILayout.MaxWidth(40))) { CollectionSettingData.RemoveElement(folderPath); break; } } EditorGUILayout.EndHorizontal(); } // 添加按钮 if (GUILayout.Button("+")) { string resultPath = EditorTools.OpenFolderPanel("+", _lastOpenFolderPath); if (resultPath != null) { _lastOpenFolderPath = EditorTools.AbsolutePathToAssetPath(resultPath); CollectionSettingData.AddElement(_lastOpenFolderPath); } } }