public static void CreateAssetBundlesFromSelection(UnityEngine.Object[] objects, string bundleParent) { if (objects == null || objects.Length == 0) { return; } float progress = 0.0f; foreach (UnityEngine.Object obj in objects) { string assetPath = AssetDatabase.GetAssetPath(obj); if (string.IsNullOrEmpty(assetPath)) { continue; } if (EditorUtility.DisplayCancelableProgressBar("Create AssetBundles from selection", string.Format("Adding {0} to bundle manager", assetPath), ++progress / objects.Length)) { EditorUtility.ClearProgressBar(); return; } string assetName = obj.name; if (BundleManager.GetBundleData(assetName) == null) { BundleManager.CreateNewBundle(assetName, bundleParent, false); } if (BundleManager.CanAddPathToBundle(assetPath, assetName)) { BundleManager.AddPathToBundle(assetPath, assetName); } } EditorUtility.ClearProgressBar(); }
bool GUI_TreeItem(int indent, string bundleName) { if (!m_CurrentShowingBundles.Contains(bundleName)) { m_CurrentShowingBundles.Add(bundleName); } BundleData bundleData = BundleManager.GetBundleData(bundleName); if (bundleData == null) { Debug.LogError("Cannot find bundle : " + bundleName); return(true); } Rect itemRect = GUI_DrawItem(bundleData, indent); EditProcess(itemRect, bundleData.name); if (DragProcess(itemRect, bundleData.name)) { return(false); } SelectProcess(itemRect, bundleData.name); if (m_CurrentEditing != bundleData.name) { RightClickMenu(itemRect); } return(GUI_DrawChildren(bundleData.name, indent)); }
internal static bool BuildBundleTree(BundleData bundle, List <string> requiredBuildList) { BuildPipeline.PushAssetDependencies(); bool succ = false; if (bundle.name.StartsWith("+")) { succ = true; EB.Debug.Log("Skip Folder Node {0}", bundle.name); } else { succ = BuildSingleBundle(bundle); if (!succ) { EB.Debug.LogError("{0} build failed.", bundle.name); BuildPipeline.PopAssetDependencies(); return(false); } else { EB.Debug.Log("{0} build succeed.", bundle.name); } } foreach (string childName in bundle.children) { BundleData child = BundleManager.GetBundleData(childName); if (child == null) { EB.Debug.LogError("Cannnot find bundle [{0}]. Sth wrong with the bundle config data.", childName); BuildPipeline.PopAssetDependencies(); return(false); } bool isDependingBundle = false; foreach (string requiredBundle in requiredBuildList) { if (BundleManager.IsBundleDependOn(requiredBundle, childName)) { isDependingBundle = true; break; } } if (isDependingBundle || !BuildConfiger.DeterministicBundle) { succ = BuildBundleTree(child, requiredBuildList); if (!succ) { BuildPipeline.PopAssetDependencies(); return(false); } } } BuildPipeline.PopAssetDependencies(); return(true); }
public void LoadBundleShipInfoFile() { if (!System.IO.File.Exists(mBundleInfoFilePath)) { string path = EditorUtility.OpenFilePanel("Load Bundle Ship Info File", "", "json"); if (!string.IsNullOrEmpty(path)) { mBundleInfoFilePath = path; } } try { using (System.IO.TextReader reader = new System.IO.StreamReader(mBundleInfoFilePath)) { string jsonStr = reader.ReadToEnd(); mCurrentEditItems = GM.JSON.ToObject <List <GM.BundleInfo> >(jsonStr); for (int i = 0; i < mCurrentEditItems.Count; ++i) { var bundle = BundleManager.GetBundleData(mCurrentEditItems[i].BundleName); mCurrentEditItems[i].Priority = bundle != null ? bundle.priority : mCurrentEditItems[i].Priority; } mCurrentEditItemsChanged = true; } } catch (System.Exception ex) { mBundleInfoFilePath = ""; mCurrentEditItems = null; Debug.LogErrorFormat("LoadBundleShipInfoFile Failed. Reason: {0}", ex.ToString()); } }
void newDefBundleTo(string parent, bool sceneBundle) { // Find a new bundle name string defBundleName = "EmptyBundle"; string currentBundleName = defBundleName; int index = 0; while (BundleManager.GetBundleData(currentBundleName) != null) { currentBundleName = defBundleName + (++index); } bool created = BundleManager.CreateNewBundle(currentBundleName, parent, sceneBundle); if (created) { if (IsFold(parent)) { SetFold(parent, false); } m_Selections.Clear(); m_Selections.Add(currentBundleName); } StartEditBundleName(currentBundleName); }
internal static void AddBundleToBuildList(string bundleName, ref Dictionary <string, List <string> > buildingRoutes) { BundleData bundle = BundleManager.GetBundleData(bundleName); var state = BundleManager.GetBuildStateOfBundle(bundleName); if (bundle == null) { Debug.LogError("Cannot find bundle " + bundleName); return; } //if( BuildHelper.IsBundleNeedBunild(bundle) ) if (state.changed) { string rootName = BundleManager.GetRootOf(bundle.name); if (buildingRoutes.ContainsKey(rootName)) { if (!buildingRoutes[rootName].Contains(bundle.name)) { buildingRoutes[rootName].Add(bundle.name); } else { Debug.LogError("Bundle name duplicated: " + bundle.name); } } else { List <string> buildingList = new List <string>(); buildingList.Add(bundle.name); buildingRoutes.Add(rootName, buildingList); } } }
private static void CreateBundle(string bunlePath, string parentName) { Object[] assetObjects = Resources.LoadAll(bunlePath); foreach (var asset in assetObjects) { string bundleName = asset.name; if (BundleManager.GetBundleData(bundleName) != null) { continue; } bool created = BundleManager.CreateNewBundle(bundleName, parentName, false); if (!created) { UnityEngine.Debug.LogError("Can't create bundle tree bundle : " + bundleName); } string bundleAssetDataPath = AssetDatabase.GetAssetPath(asset); if (BundleManager.CanAddPathToBundle(bundleAssetDataPath, bundleName)) { BundleManager.AddPathToBundle(bundleAssetDataPath, bundleName); } } }
void Update() { if (lastTimeSelection != LastSelection()) { lastTimeSelection = LastSelection(); BundleEditorDrawer.ShowBundle(BundleManager.GetBundleData(lastTimeSelection)); } if (m_EditWaitBundle != "" && m_EditWaitStartTime > 0) { // See if we can start edit if (EditorApplication.timeSinceStartup - m_EditWaitStartTime > 0.6) { StartEditBundleName(m_EditWaitBundle); } } if (BMDataAccessor.ShouldSaveBundleData) { BMDataAccessor.ShouldSaveBundleData = false; BMDataAccessor.SaveBundleData(); } if (BMDataAccessor.ShouldSaveBundleStates) { BMDataAccessor.ShouldSaveBundleStates = false; BMDataAccessor.SaveBundleBuildeStates(); } }
public static void RefreshBundlesForUI() { const string STANDLONE_BUNDLE_NAME = "UIStandalone"; //Check Error var standaloneBundle = BundleManager.GetBundleData(STANDLONE_BUNDLE_NAME); if (standaloneBundle == null) { Debug.LogError("Cannot find parent bundle:" + STANDLONE_BUNDLE_NAME); return; } //standalone UI Bundles var groups = new Dictionary <string, string>(); foreach (var filePath in Directory.GetFiles("Assets/_Prefab/Edit/UI/Windwos", ".prefab", SearchOption.TopDirectoryOnly)) { var groupName = "UI/" + Path.GetFileNameWithoutExtension(filePath); groups.Add(groupName, filePath); } foreach (var filePath in Directory.GetFiles("Assets/_Prefab/Edit/UI/NewUI", ".prefab", SearchOption.TopDirectoryOnly)) { var groupName = "UI/" + Path.GetFileNameWithoutExtension(filePath); groups.Add(groupName, filePath); } var oldGroups = BundleManager.GetBundleData(STANDLONE_BUNDLE_NAME).GetChildren().ToArray(); foreach (var oldGroup in oldGroups) { if (!groups.ContainsKey(oldGroup)) { BundleManager.RemoveBundle(oldGroup); } } foreach (var pair in groups) { var groupName = pair.Key; var bundle = BundleManager.GetBundleData(groupName); if (bundle == null) { BundleManager.CreateNewBundle(groupName, STANDLONE_BUNDLE_NAME, BundleType.Normal); bundle = BundleManager.GetBundleData(groupName); BundleManager.AddPathToBundle(pair.Value, groupName); } else { var path = pair.Value; var guid = AssetDatabase.AssetPathToGUID(path); if (bundle.includeGUIDs[0] != guid) { BundleManager.RemoveAssetFromBundle(bundle.includeGUIDs[0], groupName); BundleManager.AddPathToBundle(path, groupName); } } } }
public static void RebuildSelection(string[] selections) { foreach (string bundleName in selections) { var bundle = BundleManager.GetBundleData(bundleName); BundleManager.RefreshBundleDependencies(bundle); BundleManager.GetBuildStateOfBundle(bundleName).changed = true; } BuildBundles(selections); }
List <BundleData> TreeToList(BundleData root) { List <BundleData> list = new List <BundleData>(); list.Add(root); foreach (var child in root.children) { list.AddRange(TreeToList(BundleManager.GetBundleData(child))); } return(list); }
internal static bool BuildBundleTree(BundleData bundle, List <string> requiredBuildList) { BuildPipeline.PushAssetDependencies(); bool succ = BuildSingleBundle(bundle); if (!succ) { Debug.LogError(bundle.name + " build failed."); //为了实现能够跳过build错误的bundle继续进行打包而注释 //BuildPipeline.PopAssetDependencies(); //return false; } else { var buildState = BundleManager.GetBuildStateOfBundle(bundle.name); Debug.Log(bundle.name + " build succeed."); } if (succ) { foreach (string childName in bundle.GetChildren()) { BundleData child = BundleManager.GetBundleData(childName); if (child == null) { Debug.LogError("Cannnot find bundle [" + childName + "]. Sth wrong with the bundle config data."); BuildPipeline.PopAssetDependencies(); return(false); } bool isDependingBundle = false; foreach (string requiredBundle in requiredBuildList) { if (BundleManager.IsBundleDependOn(requiredBundle, childName)) { isDependingBundle = true; break; } } if (isDependingBundle || !BuildConfiger.DeterministicBundle) { succ = BuildBundleTree(child, requiredBuildList); if (!succ) { BuildPipeline.PopAssetDependencies(); return(false); } } } } BuildPipeline.PopAssetDependencies(); return(true); }
/** * Copy the configeration files to target directory. */ //public static void ExportBMDatasToOutput() //{ // string exportPath = BuildConfiger.InterpretedOutputPath; // if(!Directory.Exists(exportPath)) // Directory.CreateDirectory(exportPath); // uint crc = 0; // if(!BuildAssetBundle(new string[]{BMDataAccessor.BundleDataPath, BMDataAccessor.BundleBuildStatePath, BMDataAccessor.BMConfigerPath}, Path.Combine( exportPath, "BM.data" ), out crc)) // Debug.LogError("Failed to build bundle of config files."); // BuildHelper.ExportBundleDataFileToOutput(); // BuildHelper.ExportBundleBuildDataFileToOutput(); // BuildHelper.ExportBMConfigerFileToOutput(); //} /** * Copy the bundle datas to target directory. */ public static void BuildSelections(string[] selections) { BMDataAccessor.AssetStates.Clear(); foreach (string bundleName in selections) { var bundle = BundleManager.GetBundleData(bundleName); BundleManager.RefreshBundleDependencies(bundle); BuildHelper.RefreshBundleChanged(bundle); } BuildBundles(selections); }
private static void CreateEquipBundle() { //ArangeBundleDependent.ArangeDependent("RTP/Equip", "Equip"); BundleManager.CreateNewBundle("EquipCommon", "", false); BundleData commonBundleData = BundleManager.GetBundleData("EquipCommon"); commonBundleData.includs.Add("Assets/CommonEmpty.txt"); CreateBundle("RTP/Equip", "EquipCommon"); }
public static void MarkParentsNeedBuild(BundleData bundle) { var extra = bundle.GetExtraData(); extra.needBuild = true; var parentBundle = BundleManager.GetBundleData(bundle.parent); if (parentBundle != null) { MarkParentsNeedBuild(parentBundle); } }
public static bool BuildRootBundle(BundleData bundle) { if (!IsNeedBuild(bundle)) { Debug.Log(string.Format("Bundle {0} Skiped!", bundle.name)); return(true); } PushCommontDepends(); BuildPipeline.PushAssetDependencies(); for (int i = 0; i < bundle.depends.Count; i++) { BundleData dependBundle = BundleManager.GetBundleData(bundle.depends[i]); if (!BuildSingleBundle(dependBundle)) { Debug.Log(string.Format("Build {0} Fail!", dependBundle.name)); goto ONE_POP; } } BuildPipeline.PushAssetDependencies(); BundleData mainBundle = BundleManager.GetBundleData(bundle.assetPath); if (!BuildSingleBundle(mainBundle)) { goto TWO_POP; } goto SUCCEED; ONE_POP: Debug.Log(string.Format("{0} Depends Build Error! ", bundle.name)); BuildPipeline.PopAssetDependencies(); PopCommontDepends(); return(false); TWO_POP: Debug.Log(string.Format("{0} Self Build Error! ", bundle.name)); BuildPipeline.PopAssetDependencies(); BuildPipeline.PopAssetDependencies(); PopCommontDepends(); return(false); SUCCEED: Debug.Log(string.Format("Build {0} Succeed!", bundle.name)); BuildPipeline.PopAssetDependencies(); BuildPipeline.PopAssetDependencies(); PopCommontDepends(); return(true); }
private void _CreateCombatBundleForCharacter() { var parentName = "Combat"; var srcBundle = m_Selections[0]; var destBundleName = srcBundle.Replace("Character/model_", "Combat/combat_"); var parentBundle = BundleManager.GetBundleData(parentName); if (parentBundle == null) { Debug.LogError("Cannot find parent bundle:" + parentName); return; } if (BundleManager.GetBundleData(destBundleName) != null) { Debug.LogWarning("Didn't creat[" + destBundleName + "].Its already in the bundle list."); return; } if (!BundleManager.CreateNewBundle(destBundleName, parentName, BundleType.Normal)) { Debug.LogError("Create failed,unexpeted."); return; } //Add effects- 通过名字特征来搜索符合的特效 var keyword = srcBundle.Replace("Character/model_", ""); var guids = AssetDatabase.FindAssets(keyword, new[] { "Asset/_Prefab/Edit.Effect" }); foreach (var guid in guids) { var assetPath = AssetDatabase.GUIDToAssetPath(guid); if (!Directory.Exists(assetPath)) { BundleManager.AddPathToBundle(assetPath, destBundleName); } } //Add Sounds - 声音的命名方式和特效不一样,使用特殊处理 var soundKeyword = keyword.Remove(keyword.IndexOf("_"), 1); var soundGuids = AssetDatabase.FindAssets(soundKeyword, new[] { "Asset/_Prefab/Edit/Sound" }); foreach (var soundGuid in soundGuids) { var assetPath = AssetDatabase.GUIDToAssetPath(soundGuid); if (!Directory.Exists(assetPath)) { BundleManager.AddPathToBundle(assetPath, destBundleName); } } }
/** * Detect if the bundle need update. */ public static bool IsBundleNeedBunild(BundleData bundle) { string outputPath = GenerateOutputPathForBundle(bundle.name); if (!File.Exists(outputPath)) { return(true); } BundleBuildState bundleBuildState = BundleManager.GetBuildStateOfBundle(bundle.name); DateTime lastBuildTime = File.GetLastWriteTime(outputPath); DateTime bundleChangeTime = bundleBuildState.changeTime == -1 ? DateTime.MaxValue : DateTime.FromBinary(bundleBuildState.changeTime); if (System.DateTime.Compare(lastBuildTime, bundleChangeTime) < 0) { return(true); } string[] assetPaths = GetAssetsFromPaths(BundleManager.GUIDsToPaths(bundle.includeGUIDs.ToArray()), bundle.sceneBundle); string[] dependencies = AssetDatabase.GetDependencies(assetPaths); if (!EqualStrArray(dependencies, bundleBuildState.lastBuildDependencies)) { return(true); // Build depenedencies list changed. } foreach (string file in dependencies) { if (DateTime.Compare(lastBuildTime, File.GetLastWriteTime(file)) < 0) { return(true); } } if (bundle.parent != "") { BundleData parentBundle = BundleManager.GetBundleData(bundle.parent); if (parentBundle != null) { if (IsBundleNeedBunild(parentBundle)) { return(true); } } else { Debug.LogError("Cannot find bundle"); } } return(false); }
void CreateFolderNode() { string defFolderName = "+Folder"; string currentFolderName = defFolderName; int index = 0; while (BundleManager.GetBundleData(currentFolderName) != null) { currentFolderName = defFolderName + (++index); } BuildHelper.CreateFolderNode(currentFolderName); StartEditBundleName(currentFolderName); }
private void CreateBundleFromAssetWithFolder(Object asset, string parent = "") { var path = AssetDatabase.GetAssetOrScenePath(asset); if (!path.StartsWith("Assets")) { return; } string defBundleName = System.IO.Path.GetFileNameWithoutExtension(path); string currentBundleName = defBundleName; //int index = 0; //while (BundleManager.GetBundleData(currentBundleName)!=null) //{ // currentBundleName = defBundleName + (++index); //} currentBundleName = parent + "/" + currentBundleName; if (BundleManager.GetBundleData(currentBundleName) != null) { Debug.Log("Skip [" + currentBundleName + "].Its already int the bundle list"); return; } if (string.IsNullOrEmpty(parent) && m_Selections.Count == 1) { parent = m_Selections[0]; } var bundleType = path.EndsWith(".unity") ? BundleType.Scene : BundleType.Normal; bool created = BundleManager.CreateNewBundle(currentBundleName, parent, bundleType); if (created) { if (BundleManager.CanAddPathToBundle(path, currentBundleName)) { BundleManager.AddPathToBundle(path, currentBundleName); } if (IsFold(parent)) { SetFold(parent, false); } m_Selections.Clear(); m_Selections.Add(currentBundleName); } }
void Update() { if (lastTimeSelection != LastSelection()) { lastTimeSelection = LastSelection(); BundleEditorDrawer.ShowBundle(BundleManager.GetBundleData(lastTimeSelection)); } if (m_EditWaitBundle != "" && m_EditWaitStartTime > 0) { // See if we can start edit if (EditorApplication.timeSinceStartup - m_EditWaitStartTime > 0.6) { StartEditBundleName(m_EditWaitBundle); } } }
/** * Build bundles. */ public static void BuildBundles(string[] bundles) { Dictionary <string, List <string> > buildingRoutes = new Dictionary <string, List <string> >(); foreach (string bundle in bundles) { AddBundleToBuildList(bundle, ref buildingRoutes); } foreach (var buildRoute in buildingRoutes) { BundleData bundle = BundleManager.GetBundleData(buildRoute.Key); if (bundle != null) { BuildBundleTree(bundle, buildRoute.Value); } } }
/** * Build bundles. */ public static void BuildBundles(string[] bundles) { Dictionary <string, List <string> > buildingRoutes = new Dictionary <string, List <string> >(); foreach (string bundle in bundles) { AddBundleToBuildList(bundle, ref buildingRoutes); } m_BuiltCount = 0; var startTime = Time.realtimeSinceStartup; foreach (var buildRoute in buildingRoutes) { BundleData bundle = BundleManager.GetBundleData(buildRoute.Key); if (bundle != null) { BuildBundleTree(bundle, buildRoute.Value); } } BMDataAccessor.BuildVersion++; BMDataAccessor.SaveBundleBuildVersion(); BMDataAccessor.SaveBundleVersionInfo(); string exportpath = BuildConfiger.InterpretedOutputPath; if (!Directory.Exists(exportpath)) { Directory.CreateDirectory(exportpath); } BundleManager.UpdateAllBundlesNeedBuild(); uint crc = 0; if (!BuildAssetBundle(new string[] { BMDataAccessor.BundleBuildVersionPath, BMDataAccessor.BMConfigerPath }, Path.Combine(exportpath, "BM.data"), out crc)) { //存入数据,三个path指向三个txt文件,将三个txt文件导入BM.data Debug.LogError("Failed to build bundle of config files."); } Debug.Log("Build bundles:" + m_BuiltCount + "| AssetBundleVersion:" + BMDataAccessor.BuildVersion + "| Time Consumed" + (Time.realtimeSinceStartup - startTime)); File.WriteAllText(Path.Combine(exportpath, "BMDataVersion.txt"), BMDataAccessor.BuildVersion.ToString()); }
bool GUI_DrawChildren(string bundleName, int indent) { BundleData bundleData = BundleManager.GetBundleData(bundleName); if (bundleData.children.Count == 0 || IsFold(bundleName)) { return(true); } for (int i = 0; i < bundleData.children.Count; ++i) { if (!GUI_TreeItem(indent + 1, bundleData.children[i])) { return(false); } } return(true); }
static void CreateBundle(BundleData bundleData, string parent) { BundleManager.CreateNewBundle(bundleData.name, bundleData.parent, false); BundleData addedBundleData = BundleManager.GetBundleData(bundleData.name); addedBundleData.includs.AddRange(bundleData.includs); foreach (var asset in bundleData.includs) { BundleManager.AddIncludeRef(asset, addedBundleData); BundleManager.RefreshBundleDependencies(addedBundleData); BundleManager.UpdateBundleChangeTime(addedBundleData.name); } foreach (var child in bundleData.children) { CreateBundle(_treedBundleDatas[child], bundleData.name); } }
private static BundleData AddRootBundleData(string rootPath) { BundleData root = BundleManager.GetBundleData(rootPath); if (root == null) { root = CreateBundleData(rootPath); BundleManager.AddNewBundleData(root); } for (int i = 0; i < root.depends.Count; i++) { if (!BundleManager.IsHaveBundleData(root.depends[i])) { BundleManager.AddNewBundleData(CreateBundleData(root.depends[i])); } } return(root); }
internal static SingleBundleEnd BuildBundleTree(BundleData bundle, List <string> requiredBuildList) { BuildPipeline.PushAssetDependencies(); SingleBundleEnd end = BuildSingleBundle(bundle); if (end == SingleBundleEnd.eFail) { UnityEngine.Debug.LogError(bundle.name + " build failed."); BuildPipeline.PopAssetDependencies(); return(end); } else if (end == SingleBundleEnd.eSucc) { UnityEngine.Debug.Log(bundle.name + " build succeed."); } else { UnityEngine.Debug.Log(bundle.name + " is empty , remove it."); BuildPipeline.PopAssetDependencies(); return(end); } //即将要移除的空资源包 List <string> bundleToRemove = new List <string>(); foreach (string childName in bundle.children) { BundleData child = BundleManager.GetBundleData(childName); if (child == null) { UnityEngine.Debug.LogError("Cannnot find bundle [" + childName + "]. Sth wrong with the bundle config data."); BuildPipeline.PopAssetDependencies(); return(end); } bool isDependingBundle = false; foreach (string requiredBundle in requiredBuildList) { if (BundleManager.IsBundleDependOn(requiredBundle, childName)) { isDependingBundle = true; break; } } if (isDependingBundle || !BuildConfiger.DeterministicBundle) { end = BuildBundleTree(child, requiredBuildList); if (end == SingleBundleEnd.eFail) { BuildPipeline.PopAssetDependencies(); return(end); } else if (end == SingleBundleEnd.eEmptyRemove) { bundleToRemove.Add(childName); } } } foreach (var removeBundle in bundleToRemove) { BundleManager.RemoveBundle(removeBundle); } BuildPipeline.PopAssetDependencies(); return(end); }
//you can use this to make prefabs & assetbundles, or just prefabs public static void CreateAssetBundlesFromScene(bool do_assetbundling = true) { //BundleData[] bundles = BundleManager.bundles.Select(); string[] names = BundleManager.bundles.Select(bundle => bundle.name).ToArray(); string active_level = EditorApplication.currentScene; active_level = System.IO.Path.GetFileName(active_level); string[] levelsplit = active_level.Split('.'); active_level = levelsplit[0]; //if scene doesnt have an assetbundle folder bool level_has_assetbundle_folder = false; for (int i = 0; i < names.Length; i++) { if (string.Equals(names[i], active_level)) { level_has_assetbundle_folder = true; break; } } //create a scene assetbundle folder if (!level_has_assetbundle_folder) { CreateFolderNode("+" + active_level); } //get all the gameobjects that should be assetbundles in the scene GameObject[] obj = (GameObject[])GameObject.FindSceneObjectsOfType(typeof(GameObject)); List <GameObject> assetbundle_list = new List <GameObject>(); for (int i = 0; i < obj.Length; i++) { if (obj[i].GetComponent <AssetBundleHelper>() != null) { assetbundle_list.Add(obj[i]); } } //does the prefab exits? for (int i = 0; i < assetbundle_list.Count; i++) { GameObject assetbundle_obj = assetbundle_list[i]; string prefab_path = "Assets/_GameAssets/Res/Environment/" + active_level + "/Prefabs/" + assetbundle_list[i].name + ".prefab"; if (!Directory.Exists("Assets/_GameAssets/Res/Environment/" + active_level + "/Prefabs/")) { AssetDatabase.CreateFolder("Assets/_GameAssets/Res/Environment/" + active_level, "Prefabs"); } //needs a prefab //if(!AssetDatabase.Contains(assetbundle_list[i])) { //create a prefab! Transform parent = assetbundle_obj.transform.parent; Vector3 local_pos = assetbundle_obj.transform.localPosition; Vector3 local_scale = assetbundle_obj.transform.localScale; Quaternion local_rotation = assetbundle_obj.transform.localRotation; GameObject new_prefab = PrefabUtility.CreatePrefab(prefab_path, assetbundle_obj); GameObject.DestroyImmediate(assetbundle_obj); GameObject new_obj = (GameObject)EditorUtility.InstantiatePrefab(new_prefab); new_obj.transform.localPosition = local_pos; new_obj.transform.localScale = local_scale; new_obj.transform.localRotation = local_rotation; new_obj.transform.parent = parent; assetbundle_obj = new_obj; } if (do_assetbundling) { if (BundleManager.GetBundleData(assetbundle_obj.name) == null) { BundleManager.CreateNewBundle(assetbundle_obj.name, "+" + active_level, false); } //add the new prefab to the assetbundle if (BundleManager.CanAddPathToBundle(prefab_path, assetbundle_obj.name)) { BundleManager.AddPathToBundle(prefab_path, assetbundle_obj.name); } } } }