public void OnEnable() { //Construct more readily editable asset mapping assets = new List <ListingEditorEntry>(); var assetsByName = new Dictionary <string, ListingEditorEntry>(); AssetBundleListing listing = target as AssetBundleListing; foreach (var pair in listing.assets) { AssetBundleContents contents = pair.Load(); if (contents != null) { foreach (var entry in contents.assets) { if (!assetsByName.ContainsKey(entry.name)) { var newEntry = new ListingEditorEntry(); newEntry.name = entry.name; assetsByName[entry.name] = newEntry; assets.Add(newEntry); } assetsByName[entry.name].assets[contents.platform] = entry.isInherited ? null : entry.asset; } } } }
protected void UpdateBundleContents() { var listing = target as AssetBundleListing; foreach (var plat in Settings.platforms) { AssetBundleContents bundle = listing.GetBundleForPlatform(plat.name); bundle.assets.Clear(); foreach (ListingEditorEntry entry in assets) { BundleContentsEntry bundleEntry = new BundleContentsEntry(); bundleEntry.name = entry.name; bundleEntry.asset = entry.GetAssetForPlatformOrInherited(plat.name, out bundleEntry.isInherited); bundle.assets.Add(bundleEntry); } EditorUtility.SetDirty(bundle); } EditorUtility.SetDirty(listing); }
public AssetBundleContents LoadOrCreate(AssetBundleListing sourceListing) { if (string.IsNullOrEmpty(contentsPath)) { string dir = "Assets/AssetBundleHelper/BundleContents/"; if (!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } contentsPath = AssetDatabase.GenerateUniqueAssetPath(Path.Combine(dir, sourceListing.name + "_" + platform + ".asset")); AssetBundleContents contents = ScriptableObject.CreateInstance <AssetBundleContents>(); contents.listing = sourceListing; contents.platform = platform; AssetDatabase.CreateAsset(contents, contentsPath); EditorUtility.SetDirty(sourceListing); AssetDatabase.SaveAssets(); } return(Load()); }