public static void BuildBundleForCurrentPlatforms(AssetBundleListing listing) { var curPlats = Settings.GetPlatformsForCurrentBuildTarget(EditorUserBuildSettings.activeBuildTarget); foreach (BundlePlatform plat in curPlats) { string path = Settings.bundleDirectoryRelativeToProjectFolder; DirectoryInfo di = new DirectoryInfo(path); path += "/" + listing.name + "_" + plat.name + ".unity3d"; if (!di.Exists) { di.Create(); } BuildAssetBundleOptions babOpts = BuildAssetBundleOptions.CompleteAssets; if (listing.gatherDependencies) { babOpts |= BuildAssetBundleOptions.CollectDependencies; } if (!listing.compressed) { babOpts |= BuildAssetBundleOptions.UncompressedAssetBundle; } var files = listing.GetAssetsForPlatform(plat.name); var names = listing.GetNamesForPlatform(plat.name); BuildPipeline.BuildAssetBundleExplicitAssetNames(files.ToArray(), names.ToArray(), path, babOpts, plat.unityBuildTarget); } }
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; } } } }
public static IEnumerator Get(AssetBundleListing listing, string assetName) { string key = AssetBundleFileNameForPlatform(listing.name, Platform); if (!bundleCache.ContainsKey(key)) { Debug.Log("Load AssetBundle from " + AssetBundlePath(listing.name)); var www = new WWW(AssetBundlePath(listing.name)); yield return(www); if (www.assetBundle) { bundleCache.Add(key, www.assetBundle); } www.Dispose(); } var bundle = bundleCache.Get(key); if (bundle.Contains(assetName)) { yield return(bundle.Load(assetName)); } else { Debug.LogWarning("Bundle does not contain " + assetName); yield break; } }
public DateTime GetLastWriteTime(AssetBundleListing listing, string platform) { string path = bundleDirectoryRelativeToProjectFolder + "/" + listing.name + "_" + platform+".unity3d"; var fileInfo = new FileInfo(path); if(!fileInfo.Exists){ return new DateTime((System.Int64)0); } return fileInfo.LastWriteTimeUtc; }
public DateTime GetLastWriteTime(AssetBundleListing listing, string platform) { string path = bundleDirectoryRelativeToProjectFolder + "/" + listing.name + "_" + platform + ".unity3d"; var fileInfo = new FileInfo(path); if (!fileInfo.Exists) { return(new DateTime((System.Int64) 0)); } return(fileInfo.LastWriteTimeUtc); }
public static void Release(AssetBundleListing listing, string assetName) { string key = AssetBundleFileNameForPlatform(listing.name, Platform); if(!bundleCache.ContainsKey(key)){ Debug.LogWarning("No bundle with id " + key); return; } var bundle = bundleCache.GetUntracked(key); if(bundleCache.Release(key)){ bundle.Unload(false); } }
public static void Release(AssetBundleListing listing, string assetName) { string key = AssetBundleFileNameForPlatform(listing.name, Platform); if (!bundleCache.ContainsKey(key)) { Debug.LogWarning("No bundle with id " + key); return; } var bundle = bundleCache.GetUntracked(key); if (bundleCache.Release(key)) { bundle.Unload(false); } }
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(); }
public static void BuildBundleForCurrentPlatforms(AssetBundleListing listing) { var curPlats = Settings.GetPlatformsForCurrentBuildTarget(EditorUserBuildSettings.activeBuildTarget); foreach(BundlePlatform plat in curPlats){ string path = Settings.bundleDirectoryRelativeToProjectFolder; DirectoryInfo di = new DirectoryInfo(path); path += "/" + listing.name + "_" + plat.name +".unity3d"; if(!di.Exists) di.Create(); BuildAssetBundleOptions babOpts = BuildAssetBundleOptions.CompleteAssets; if(listing.gatherDependencies) babOpts |= BuildAssetBundleOptions.CollectDependencies; if(!listing.compressed) babOpts |= BuildAssetBundleOptions.UncompressedAssetBundle; var files = listing.GetListingForPlatform(plat.name); var names = listing.assets.ConvertAll<string>((x) => x.name).ToList(); BuildPipeline.BuildAssetBundleExplicitAssetNames(files.ToArray(),names.ToArray(), path, babOpts, plat.unityBuildTarget); } }
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()); }
IEnumerator LoadAssetList(AssetListLoadedFunc callBack) { // Defer this function to the next frame until server replied and response has been downloaded UnityWebRequest req = UnityWebRequest.Get(string.Format("{0}/Bundle", this.ServerAddress)); yield return req.SendWebRequest(); if (req.isNetworkError || req.isHttpError) { _lastError = req.error; if (callBack != null) callBack(null); } else { Debug.Log("Asset Manager: Asset list finished downloading."); AssetBundleListing listing = JsonUtility.FromJson<AssetBundleListing>(req.downloadHandler.text); List<string> assetList = new List<string>(); foreach (var bundle in listing.AssetBundleList) { assetList.Add(bundle.BundleName); if (bundle.Thumbnail != null) { _thumbnails[bundle.BundleName] = System.Convert.FromBase64String(bundle.Thumbnail); bundle.Thumbnail = null; } } if (callBack != null) { // Dispatch events callBack(assetList); if (OnAssetListLoaded != null) { OnAssetListLoaded(assetList); } } } }
public static IEnumerator Get(AssetBundleListing listing, string assetName) { string key = AssetBundleFileNameForPlatform(listing.name, Platform); if(!bundleCache.ContainsKey(key)){ Debug.Log("Load AssetBundle from " + AssetBundlePath(listing.name)); var www = new WWW(AssetBundlePath(listing.name)); yield return www; if(www.assetBundle){ bundleCache.Add(key, www.assetBundle); } www.Dispose(); } var bundle = bundleCache.Get(key); if(bundle.Contains(assetName)){ yield return bundle.Load(assetName); } else{ Debug.LogWarning("Bundle does not contain " + assetName); yield break; } }
public override void OnInspectorGUI() { serializedObject.Update(); AssetBundleListing listing = target as AssetBundleListing; EditorGUIUtility.LookLikeControls(); GUILayout.Label("Bundle Contents", EditorStyles.boldLabel); GUILayout.BeginVertical(GUI.skin.box); //Header GUILayout.BeginHorizontal(EditorStyles.toolbar); GUILayout.Label("Name", GUILayout.MinWidth(100)); GUILayout.FlexibleSpace(); foreach (var plat in Settings.platforms) { GUILayout.Label(new GUIContent(plat.name, plat.icon32), GUILayout.Height(14), GUILayout.Width(60)); } GUILayout.Space(16); GUILayout.EndHorizontal(); //Asset listing foreach (var entry in assets) { GUILayout.BeginHorizontal(); GUILayout.Space(2); string name = GUILayout.TextField(entry.name, GUILayout.MinWidth(100)); if (entry.name != name) { entry.name = name; UpdateBundleContents(); } GUILayout.FlexibleSpace(); foreach (var plat in Settings.platforms) { Object o = null; Object d = null; bool usingDefault = false; d = entry.GetAssetForPlatform(AssetBundleRuntimeSettings.DefaultPlatform); o = entry.GetAssetForPlatform(plat.name); if (o == null && d != null) { usingDefault = true; } if (usingDefault) { GUI.backgroundColor = Color.grey; Object n = EditorGUILayout.ObjectField(d, typeof(Object), false, GUILayout.Width(60)); GUI.backgroundColor = Color.white; if (n != d) { entry.Add(n, plat.name); UpdateBundleContents(); } } else { if (d != null && o.GetType() != d.GetType()) { GUI.backgroundColor = Color.yellow; } Object n = EditorGUILayout.ObjectField(o, typeof(Object), false, GUILayout.Width(60)); GUI.backgroundColor = Color.white; if (n != o) { entry.Add(n, plat.name); UpdateBundleContents(); } } } if (GUILayout.Button("", Settings.deleteButtonStyle)) { toRemove.Add(entry); } GUILayout.Space(2); GUILayout.EndHorizontal(); } //New entry GUILayout.BeginHorizontal(); GUILayout.FlexibleSpace(); if (GUILayout.Button("", Settings.addButtonStyle)) { assets.Add(new ListingEditorEntry()); UpdateBundleContents(); } GUILayout.EndHorizontal(); GUILayout.EndVertical(); //Handle removed entries if (toRemove.Count > 0) { assets.RemoveAll((x) => toRemove.Contains(x)); toRemove.Clear(); UpdateBundleContents(); } //Settings GUILayout.Label("Bundle Build Options", EditorStyles.boldLabel); listing.gatherDependencies = EditorGUILayout.Toggle("Gather Dependencies", listing.gatherDependencies); listing.compressed = EditorGUILayout.Toggle("Compressed", listing.compressed); if (GUI.changed) { serializedObject.ApplyModifiedProperties(); EditorUtility.SetDirty(target); } var curPlats = Settings.GetPlatformsForCurrentBuildTarget(EditorUserBuildSettings.activeBuildTarget); string platList = ""; foreach (var plat in curPlats) { platList += " " + plat.name; } if (GUILayout.Button("Build AssetBundle (" + platList + ")")) { BuildBundleForCurrentPlatforms(listing); } }
public void OnGUI() { if (detectedBundlesFileInfos == null || detectedBundles == null) { Refresh(); return; } EditorGUIUtility.LookLikeInspector(); GUILayout.BeginHorizontal(); GUILayout.Label("Bundles", EditorStyles.boldLabel); GUILayout.FlexibleSpace(); if (GUILayout.Button("Refresh", EditorStyles.miniButton)) { Refresh(); } GUILayout.EndHorizontal(); GUILayout.BeginVertical(GUI.skin.box); GUILayout.BeginHorizontal(EditorStyles.toolbar); GUILayout.Label("Name", GUILayout.MinWidth(100)); GUILayout.FlexibleSpace(); foreach (var plat in AssetBundleListingEditor.Settings.platforms) { GUILayout.Label(new GUIContent(plat.name, plat.icon32), GUILayout.Height(14), GUILayout.Width(60)); } GUILayout.EndHorizontal(); List <AssetBundleListing> listingsOutOfDate = new List <AssetBundleListing>(); var curPlats = AssetBundleListingEditor.Settings.GetPlatformsForCurrentBuildTarget(EditorUserBuildSettings.activeBuildTarget); for (int i = 0; i < detectedBundles.Count; i++) { AssetBundleListing listing = detectedBundles[i]; if (listing == null) { Refresh(); return; } FileInfo listingFile = detectedBundlesFileInfos[i]; if (listingFile == null) { Refresh(); return; } Dictionary <string, bool> isOutofdate = new Dictionary <string, bool>(); GUILayout.BeginHorizontal(); if (GUILayout.Button(listing.name, EditorStyles.miniButton, GUILayout.MinWidth(100))) { Selection.activeObject = listing; EditorGUIUtility.PingObject(Selection.activeObject); } GUILayout.FlexibleSpace(); DateTime badDate = new DateTime((System.Int64) 0); foreach (var plat in AssetBundleListingEditor.Settings.platforms) { DateTime lastBundleWriteTime = AssetBundleListingEditor.Settings.GetLastWriteTime(listing, plat.name); bool exists = lastBundleWriteTime != badDate; isOutofdate[plat.name] = listingFile.LastWriteTimeUtc > lastBundleWriteTime; var platObjs = listing.GetListingForPlatform(plat.name); string[] strings = platObjs.ConvertAll <string>((x) => { return(AssetDatabase.GetAssetPath(x)); }).Distinct().ToArray <string>(); strings = AssetDatabase.GetDependencies(strings); platObjs = Array.ConvertAll <string, UnityEngine.Object>(strings, (x) => { return(AssetDatabase.LoadMainAssetAtPath(x)); }).ToList(); foreach (var obj in platObjs) { string projectPath = AssetDatabase.GetAssetPath(obj); if (projectPath == "") { continue; } FileInfo objFileInfo = new FileInfo(projectPath); string metaPath = AssetDatabase.GetTextMetaDataPathFromAssetPath(projectPath); FileInfo metaFileInfo = new FileInfo(metaPath); if (objFileInfo.LastWriteTimeUtc > lastBundleWriteTime || (metaPath != "" && metaFileInfo.LastWriteTimeUtc > lastBundleWriteTime)) { isOutofdate[plat.name] = true; } } if (!exists) { GUILayout.Label(AssetBundleListingEditor.Settings.box, GUILayout.Width(60)); if (curPlats.Contains(plat) && !listingsOutOfDate.Contains(listing)) { listingsOutOfDate.Add(listing); } } else if (isOutofdate[plat.name]) { GUILayout.Label(AssetBundleListingEditor.Settings.outOfDate, GUILayout.Width(60)); if (curPlats.Contains(plat) && !listingsOutOfDate.Contains(listing)) { listingsOutOfDate.Add(listing); } } else { GUILayout.Label(AssetBundleListingEditor.Settings.checkedBox, GUILayout.Width(60)); } } GUILayout.EndHorizontal(); } GUILayout.EndVertical(); string platList = ""; foreach (var plat in curPlats) { platList += " " + plat.name; } if (listingsOutOfDate.Count > 0 && GUILayout.Button("Build missing/out of date bundles for" + platList + " (" + listingsOutOfDate.Count + ")")) { foreach (AssetBundleListing listing in listingsOutOfDate) { AssetBundleListingEditor.BuildBundleForCurrentPlatforms(listing); } } }