public static AssetBundleRule CreateAssetRule() { var assetRule = AssetBundleRule.CreateInstance <AssetBundleRule>(); assetRule.ApplyDefaults(); return(assetRule); }
void OnEnable() { //changed = false; orig = (AssetBundleRule)target; currentSetting = orig.settings; Undo.RecordObject(target, "assetbundleruleundo"); }
public AssetBundleRuleFindResult(AssetBundleRule rule, string assetPath) { Rule = rule; RulePath = AssetDatabase.GetAssetPath(rule); AssetPath = assetPath; // 同一级目录的话,就应用文件规则。 否则应用子目录规则 IsApplyFileRule = Path.GetDirectoryName(RulePath) == Path.GetDirectoryName(assetPath); }
/// <summary> /// 查找该文件对应的规则文件 /// </summary> /// <param name="path"></param> /// <returns></returns> public static AssetBundleRuleFindResult FindRuleForAsset(string path) { AssetBundleRule rule = SearchRecursive(path); if (rule != null) { return(new AssetBundleRuleFindResult(rule, path)); } return(null); }
private void Apply(AssetBundleRule assetBundleRule) { AssetBundleRuleUtils.ApplyRule(assetBundleRule); // save rule setting EditorUtility.SetDirty(assetBundleRule); //AssetDatabase.RemoveUnusedAssetBundleNames(); //changed = false; //currentSetting = orig.settings; orig.settings = currentSetting; }
/// <summary> /// 应用该规则文件 /// </summary> /// <param name="assetBundleRule"></param> public static void ApplyRule(AssetBundleRule assetBundleRule) { if (assetBundleRule == null) { Debug.LogError("ApplyRule assetBundleRule == null"); return; } // get the directories that we do not want to apply changes to var assetrulepath = AssetDatabase.GetAssetPath(assetBundleRule).Replace(assetBundleRule.name + ".asset", "") .TrimEnd('/'); string projPath = Application.dataPath; projPath = projPath.Remove(projPath.Length - 6); string fullPath = projPath + AssetDatabase.GetAssetPath(assetBundleRule); string dirPath = Path.GetDirectoryName(fullPath); if (string.IsNullOrEmpty(dirPath)) { Debug.LogError("ApplyRule dirPath == null fullPath:" + fullPath); return; } // 找到不能应用该规则的子目录(就是有自己规则的目录) List <string> dontapply = new List <string>(); var assetGuids = AssetDatabase.FindAssets("t:AssetBundleRule", new[] { assetrulepath }); foreach (var guid in assetGuids) { // 排除当前rule目录 string assetDir = Path.GetDirectoryName(AssetDatabase.GUIDToAssetPath(guid)); if (!string.IsNullOrEmpty(assetDir) && String.Compare(assetDir, assetrulepath, StringComparison.OrdinalIgnoreCase) != 0) { var d = assetDir.Replace(Application.dataPath, "Assets"); d = d.TrimEnd('/'); d = d.Replace('\\', '/'); // 增加自己目录 if (!dontapply.Contains(d)) { dontapply.Add(d); } // 有assetBundle rule文件的话, 子目录都应该排除掉 string[] directories = Directory.GetDirectories(d, "*", SearchOption.AllDirectories); foreach (var oneDir in directories) { var dir = oneDir.TrimEnd('/'); dir = dir.Replace('\\', '/'); if (!dontapply.Contains(dir)) { dontapply.Add(dir); } } } } // 遍历所有文件, 找到合适的文件 List <string> finalAssetList = new List <string>(); var allAssets = AssetDatabase.FindAssets("", new[] { assetrulepath }); foreach (var findAsset in allAssets) { var asset = AssetDatabase.GUIDToAssetPath(findAsset); if (!IsValidBundlePath(asset)) { continue; } if (IsAssetBundleRuleFile(asset)) { continue; } if (dontapply.Contains(Path.GetDirectoryName(asset))) { continue; } if (finalAssetList.Contains(asset)) { continue; } if (asset == AssetDatabase.GetAssetPath(assetBundleRule)) { continue; } finalAssetList.Add(asset); } // 设置每个文件的规则 foreach (var asset in finalAssetList) { ApplyRuleToOneFile(new AssetBundleRuleFindResult(assetBundleRule, asset)); } }