private void OnEnable() { allDependNodes.ForEach(n => n.filters.ForEach(f => f.isFolder = !File.Exists(AssetBundleUtils.ConvertToAbsolutePath(n.dir) + "/" + f.path))); }
private void DrawInspector(AssetBundleConfigNode node) { EditorGUILayout.BeginVertical(); { string[] inspectorTypes = { "Properties", "PersistentAssets" }; _inspectorType = GUILayout.Toolbar(_inspectorType, inspectorTypes, EditorStyles.toolbarButton); if (_inspectorType == 0) { if (node != null) { EditorGUILayout.BeginHorizontal(); { node.enabled = GUILayout.Toggle(node.enabled, "", GUILayout.ExpandWidth(false)); GUILayout.Label("Name:", GUILayout.ExpandWidth(false)); node.name = EditorGUILayout.TextField(node.name, GUILayout.ExpandWidth(false)); GUILayout.Label("Dir:", GUILayout.ExpandWidth(false)); GUI.enabled = false; node.dir = EditorGUILayout.TextField(node.dir, GUILayout.ExpandWidth(true)); GUI.enabled = true; if (GUILayout.Button("...", EditorStyles.toolbarButton, GUILayout.ExpandWidth(false))) { string selectedPath = EditorUtility.OpenFolderPanel("Path", Application.dataPath, ""); if (!string.IsNullOrEmpty(selectedPath)) { node.dir = AssetBundleUtils.ConvertToAssetPath(selectedPath); } } GUILayout.Label("Independent:", GUILayout.ExpandWidth(false)); node.isIndependent = GUILayout.Toggle(node.isIndependent, "", GUILayout.ExpandWidth(false)); GUILayout.Label("Export:", GUILayout.ExpandWidth(false)); node.exportType = (ExportType)EditorGUILayout.EnumPopup(node.exportType, GUILayout.Width(80f)); } EditorGUILayout.EndHorizontal(); EditorGUILayout.BeginHorizontal(); { if (GUILayout.Button("AddFilter", EditorStyles.miniButtonLeft)) { node.filters.Add(new AssetBundleFilter(true)); } if (GUILayout.Button("AddFile", EditorStyles.miniButtonRight)) { node.filters.Add(new AssetBundleFilter(false)); } } EditorGUILayout.EndHorizontal(); _inspectorScrollPos = EditorGUILayout.BeginScrollView(_inspectorScrollPos); { for (int ii = 0; ii < node.filters.Count; ++ii) { AssetBundleFilter filter = node.filters[ii]; EditorGUILayout.BeginHorizontal(); { GUI.enabled = true; filter.valid = GUILayout.Toggle(filter.valid, "", GUILayout.ExpandWidth(false)); GUI.enabled = filter.valid; GUI.enabled = false; filter.path = GUILayout.TextField(filter.path, GUILayout.ExpandWidth(true)); GUI.enabled = true; GUI.enabled = filter.valid; if (GUILayout.Button("...", GUILayout.ExpandWidth(false))) { if (string.IsNullOrEmpty(node.dir)) { ShowNotification(new GUIContent("需要先指定节点目录")); } else { string selectedPath = filter.isFolder ? EditorUtility.OpenFolderPanel("Path", node.dir, "") : EditorUtility.OpenFilePanel("Path", node.dir, ""); if (!string.IsNullOrEmpty(selectedPath)) { selectedPath = AssetBundleUtils.ConvertToAssetPath(selectedPath); if (selectedPath.StartsWith(node.dir)) { filter.path = selectedPath.Substring((node.dir + "/").Length).Replace("\\", "/"); } else { ShowNotification(new GUIContent("不能在" + node.dir + "目录之外!")); } } } } if (filter.isFolder) { filter.filter = EditorGUILayout.TextField(filter.filter, GUILayout.Width(100)); filter.searchOption = (System.IO.SearchOption)EditorGUILayout.EnumPopup(filter.searchOption, GUILayout.Width(80)); } if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { node.filters.RemoveAt(ii); --ii; } } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); } } else if (_inspectorType == 1) { if (GUILayout.Button("AddFile", EditorStyles.miniButton)) { _config.persistentAssets.Add(string.Empty); } EditorGUILayout.BeginScrollView(Vector2.zero); { for (int ii = 0; ii < _config.persistentAssets.Count; ++ii) { EditorGUILayout.BeginHorizontal(); { GUI.enabled = false; GUILayout.TextField(_config.persistentAssets[ii], GUILayout.ExpandWidth(true)); GUI.enabled = true; if (GUILayout.Button("...", GUILayout.ExpandWidth(false))) { string selectedPath = EditorUtility.OpenFilePanel("Path", _config.persistentAssets[ii], ""); if (!string.IsNullOrEmpty(selectedPath)) { if (selectedPath.StartsWith(Application.dataPath)) { _config.persistentAssets[ii] = AssetBundleUtils.ConvertToAssetPath(selectedPath); } else { ShowNotification(new GUIContent("不能在Assets目录之外!")); } } } if (GUILayout.Button("X", EditorStyles.miniButton, GUILayout.ExpandWidth(false))) { _config.persistentAssets.RemoveAt(ii); --ii; } } EditorGUILayout.EndHorizontal(); } } EditorGUILayout.EndScrollView(); } } EditorGUILayout.EndVertical(); }
private void AddTargets(AssetBundleConfigNode configNode) { if (!configNode.enabled) { return; } int idx = _config.allDependNodes.IndexOf(configNode); AssetBundleConfigNode nextConfigNode = idx >= 0 && idx < _config.allDependNodes.Count - 1 ? _config.allDependNodes[idx + 1] : null; bool hasChild = nextConfigNode != null && nextConfigNode.level > configNode.level; AssetBundleNode node = new AssetBundleNode(configNode.ID, configNode.level, configNode.isIndependent, hasChild); List <string> assetPaths = new List <string>(); foreach (AssetBundleFilter filter in configNode.filters) { if (!filter.valid) { continue; } string filterPath = AssetBundleUtils.ConvertToAbsolutePath(configNode.dir) + "/" + filter.path; if (Directory.Exists(filterPath)) { string[] filterList = filter.filter.Split(';'); foreach (string fil in filterList) { string[] paths = Directory.GetFiles(filterPath, fil, filter.searchOption); foreach (string path in paths) { if (path.Contains("\\Editor\\") || path.EndsWith(".meta")) { continue; } assetPaths.Add(AssetBundleUtils.ConvertToAssetPath(path)); } } } else { assetPaths.Add(configNode.dir + "/" + filter.path); } } if (configNode.exportType == ExportType.Whole) { AssetBundleTarget at = new AssetBundleTarget(configNode.name, configNode.dir, node, null, ref assetPaths); node.targets.Add(at); } else { foreach (var path in assetPaths) { AssetBundleTarget at = new AssetBundleTarget(configNode.name, configNode.dir, node, path, ref assetPaths); node.targets.Add(at); } } _dependNodes.Add(node); }