protected void AddRootTargets(AssetBundleBuildRuleData.Rule rule) { var bundleDir = new DirectoryInfo(rule.directory); //Debug.Log(bundleDir.FullName); var patterns = rule.patterns; SearchOption searchOption = rule.recursion ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; for (int i = 0; i < patterns.Length; i++) { FileInfo[] prefabs = bundleDir.GetFiles(patterns[i], searchOption); foreach (FileInfo file in prefabs) { if (file.Extension.Contains("meta")) { continue; } AssetTarget target = AssetBundleUtils.Load(file); target.exportType = AssetBundleExportType.Root; if (!string.IsNullOrEmpty(rule.bundle)) { target.SetBundleName(Path.Combine(rule.directory, rule.bundle)); } } } }
/// <summary> /// 分析引用关系 /// </summary> public void Analyze() { if (_isAnalyzed) { return; } _isAnalyzed = true; Object[] deps = EditorUtility.CollectDependencies(new Object[] { asset }); List <Object> depList = new List <Object>(); for (int i = 0; i < deps.Length; i++) { Object o = deps[i]; //不包含脚本对象 //不包含LightingDataAsset对象 if (o is MonoScript || o is LightingDataAsset) { continue; } //不包含builtin对象 string path = AssetDatabase.GetAssetPath(o); if (path.StartsWith("Resources")) { continue; } depList.Add(o); } deps = depList.ToArray(); var res = from s in deps let obj = AssetDatabase.GetAssetPath(s) select obj; var paths = res.Distinct().ToArray(); for (int i = 0; i < paths.Length; i++) { if (File.Exists(paths[i]) == false) { //Debug.Log("invalid:" + paths[i]); continue; } FileInfo fi = new FileInfo(paths[i]); AssetTarget target = AssetBundleUtils.Load(fi); if (target == null) { continue; } this.AddDependParent(target); target.Analyze(); } }
/// <summary> /// 分析引用关系 /// </summary> public void Analyze() { if (_isAnalyzed) { return; } _isAnalyzed = true; Object[] deps = EditorUtility.CollectDependencies(new Object[] { asset }); List <Object> depList = new List <Object>(); for (int i = 0; i < deps.Length; i++) { Object o = deps[i]; //不包含脚本对象 //不包含LightingDataAsset对象 if (o is MonoScript || o is LightingDataAsset) { continue; } //不包含builtin对象 string path = AssetDatabase.GetAssetPath(o); if (path.StartsWith("Resources")) { continue; } //如果自身为预制件, 需要过滤一些情况 if (IsPrefab()) { //不包含预制件嵌套(包含和自己同一路径). 这是unity不完善的地方, 没办法, 从2018.3开始有这个问题 //https://issuetracker.unity3d.com/issues/nestedprefabs-when-building-assetbundles-with-nested-prefab-assets-are-duplicated-in-parent-prefab-assetbundle //Prefabs are baked out during the build process so each prefab, nested or otherwise, is full and independent of each other. if (path.EndsWith(".prefab")) { continue; } //不包含asset //asset的格式和预制件一致. 在使用过程中, 发现会有与预制件嵌套类似的问题. 在使用spine, 会发现预制件和asset同时包含一张图片, 所以干脆过滤掉. if (path.EndsWith(".asset")) { continue; } } depList.Add(o); } deps = depList.ToArray(); var res = from s in deps let obj = AssetDatabase.GetAssetPath(s) select obj; var paths = res.Distinct().ToArray(); for (int i = 0; i < paths.Length; i++) { if (File.Exists(paths[i]) == false) { //Debug.Log("invalid:" + paths[i]); continue; } FileInfo fi = new FileInfo(paths[i]); AssetTarget target = AssetBundleUtils.Load(fi); if (target == null) { continue; } this.AddDependParent(target); target.Analyze(); } }