public override void OnInspectorGUI() { AssetBundleBuilder gen = (AssetBundleBuilder)target; DrawDefaultInspector(); EditorGUILayout.BeginVertical(); EditorGUILayout.BeginHorizontal(); if (GUILayout.Button("Build Web")) { gen.BuildWeb(); } if (GUILayout.Button("Build Android")) { gen.BuildAndroid(); } if (Application.platform == RuntimePlatform.OSXEditor) { if (GUILayout.Button("Build iOS")) { gen.BuildiPhone(); } } EditorGUILayout.EndHorizontal(); if (GUILayout.Button("Build All Platform")) { gen.BuildAll(); } EditorGUILayout.EndVertical(); }
private static void Window() { AssetBundleBuilder window = GetWindow(typeof(AssetBundleBuilder), false, "Asset Bundle Builder") as AssetBundleBuilder; window.minSize = new Vector2(200, 320); window.ShowTab(); }
/// <summary> /// 返回Key为资源Path,Value为该资源所在的BundlePath字典 /// </summary> /// <param name="splitPathListListDict"></param> private static Dictionary <string, string> BuildAssets(Dictionary <string, List <List <string> > > splitPathListListDict) { Dictionary <string, string> result = new Dictionary <string, string>(); foreach (string entryPath in splitPathListListDict.Keys) { List <List <string> > assetPathListList = splitPathListListDict[entryPath]; List <StrategyNode> nodeList = AssetBuildStrategyManager.GetAssetBuildStrategy(entryPath).nodeList; HashSet <string> bundlePathSet = new HashSet <string>(); for (int i = 0; i < assetPathListList.Count; i++) { Dictionary <string, string> bundlePathDict = AssetBundleBuilder.Add(entryPath, assetPathListList[i], nodeList[i]); foreach (string k in bundlePathDict.Keys) { string path = ReplaceTemparyPath(k); if (result.ContainsKey(path) == false) { result.Add(path, bundlePathDict[k]); } bundlePathSet.Add(bundlePathDict[k]); } } AssetRecordHelper.RecordAssetDependency(entryPath, bundlePathSet.ToList <string>()); } AssetBundleBuilder.Build(); return(result); }
public void PopulateLowercaseMappingsWorkCorrectly() { var builder = new AssetBundleBuilder(); var pairs = new List <ContentServerUtils.MappingPair>(); pairs.Add(new ContentServerUtils.MappingPair() { file = "foo", hash = "tEsT1" }); pairs.Add(new ContentServerUtils.MappingPair() { file = "foo", hash = "Test2" }); pairs.Add(new ContentServerUtils.MappingPair() { file = "foo", hash = "tesT3" }); pairs.Add(new ContentServerUtils.MappingPair() { file = "foo", hash = "teSt4" }); builder.PopulateLowercaseMappings(pairs.ToArray()); Assert.IsTrue(builder.hashLowercaseToHashProper.ContainsKey("test1")); Assert.IsTrue(builder.hashLowercaseToHashProper.ContainsKey("test2")); Assert.IsTrue(builder.hashLowercaseToHashProper.ContainsKey("test3")); Assert.IsTrue(builder.hashLowercaseToHashProper.ContainsKey("test4")); Assert.AreEqual("tEsT1", builder.hashLowercaseToHashProper["test1"]); Assert.AreEqual("Test2", builder.hashLowercaseToHashProper["test2"]); Assert.AreEqual("tesT3", builder.hashLowercaseToHashProper["test3"]); Assert.AreEqual("teSt4", builder.hashLowercaseToHashProper["test4"]); }
private void CreateVersion(string path, bool clearPath = false) { if (clearPath && !Directory.Exists(path)) { Directory.Delete(path, true); } if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } if (EditorUtility.DisplayDialog("打包提示", "请确保打包的时候资源变化都已经保存,否则打包出来的资源可能不是最新的", "确定", "取消")) { if (m_BuildPlatform == BuildPlatform.StandaloneWindows) { AssetBundleBuilder.AssetBundleBuildTarget = BuildTarget.StandaloneWindows; } else if (m_BuildPlatform == BuildPlatform.Android) { AssetBundleBuilder.AssetBundleBuildTarget = BuildTarget.Android; } AssetBundleBuilder.ExportDir = path; AssetBundleBuilder.LoadAllAssets(); } }
/// <summary> /// Builds for ios. /// </summary> public static void BuildForIOS() { var args = GetArgs(); EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.iOS, BuildTarget.iOS); AssetBundleBuilder.Build(); BuildPipeline.BuildPlayer(GetBuildScenes(), args["out"], BuildTarget.iOS, BuildOptions.None); }
private void PublishToShellScript() { AssetBundleBuilder.DeleteStreamingAssetBundle(); AssetBundleBuilder.ExecuteShellScript(AssetBundleBuildSetting.ShellScript, "AssetBundlePath", AssetBundleBuilder.GetAssetBundlePath(EditorUserBuildSettings.activeBuildTarget, AssetBundleBuildSetting.RelativeOutputPath) ); }
static void Init() { // Get existing open window or if none, make a new one: AssetBundleBuilder window = (AssetBundleBuilder)GetWindow(typeof(AssetBundleBuilder)); window.minSize = new Vector2(500f, 330f); window.OnLoad(); }
/// <summary> /// 读取配置 /// </summary> private static void LoadSettingsFromPlayerPrefs(AssetBundleBuilder builder) { builder.CompressOption = (AssetBundleBuilder.ECompressOption)Enum.Parse(typeof(AssetBundleBuilder.ECompressOption), PlayerPrefs.GetString(ABBuildSettingCompressOptionKey, AssetBundleBuilder.ECompressOption.Uncompressed.ToString())); builder.IsForceRebuild = PlayerPrefs.GetInt(ABBuildSettingIsForceRebuildKey, 0) != 0; builder.IsAppendHash = PlayerPrefs.GetInt(ABBuildSettingIsAppendHashKey, 0) != 0; builder.IsDisableWriteTypeTree = PlayerPrefs.GetInt(ABBuildSettingIsDisableWriteTypeTreeKey, 0) != 0; builder.IsIgnoreTypeTreeChanges = PlayerPrefs.GetInt(ABBuildSettingIsIgnoreTypeTreeChangesKey, 0) != 0; }
private static void Build(BuildTarget target) { m_Builder = new AssetBundleBuilder(); m_Builder.Init(startPath, target); BuildConfigure(); m_Builder.Build(); m_Builder = null; }
/// <summary> /// 存储配置 /// </summary> private static void SaveSettingsToPlayerPrefs(AssetBundleBuilder builder) { PlayerPrefs.SetString(ABBuildSettingCompressOptionKey, builder.CompressOption.ToString()); PlayerPrefs.SetInt(ABBuildSettingIsForceRebuildKey, builder.IsForceRebuild ? 1 : 0); PlayerPrefs.SetInt(ABBuildSettingIsAppendHashKey, builder.IsAppendHash ? 1 : 0); PlayerPrefs.SetInt(ABBuildSettingIsDisableWriteTypeTreeKey, builder.IsDisableWriteTypeTree ? 1 : 0); PlayerPrefs.SetInt(ABBuildSettingIsIgnoreTypeTreeChangesKey, builder.IsIgnoreTypeTreeChanges ? 1 : 0); }
// -- Editor ResourceLoader -- public static AssetBundleBuilder.ConfigureInfo[] GetBuildConfigures() { m_Builder = new AssetBundleBuilder(); m_Builder.Init(startPath, BuildTarget.StandaloneWindows); BuildConfigure(); AssetBundleBuilder.ConfigureInfo[] infos = m_Builder.GetBuildConfigures(); m_Builder = null; return(infos); }
/// <summary> /// Builds for android. /// </summary> public static void BuildForAndroid() { var args = GetArgs(); PlayerSettings.productName = args["name"]; PlayerSettings.bundleVersion = args["version"]; EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android); AssetBundleBuilder.Build(); BuildPipeline.BuildPlayer(GetBuildScenes(), args["out"], BuildTarget.Android, BuildOptions.None); }
private static void Initialize() { TemporaryAssetHelper.Initialize(); MaterialJsonData.Initialize(); AssetBuildStrategyManager.Initialize(); AssetBundleBuilder.Initialize(); AssetRecordHelper.ReadAssetRecord(); Logger.GetLogger(LOGGER_NAME).Level = Logger.LEVEL_LOG; _processedAssetPathSet = new HashSet <string>(); }
private static AssetPackConfig BuildAssetBundles() { AssetDatabase.Refresh(); var builds = _assetBundleNameToAssetGuid.Select(bundleAndGuid => new AssetBundleBuild { assetBundleName = bundleAndGuid.Key, assetNames = new[] { AssetDatabase.GUIDToAssetPath(bundleAndGuid.Value) } }).ToArray(); return(AssetBundleBuilder.BuildAssetBundles(AssetBundleDirectory, builds, AssetPackDeliveryMode.OnDemand, null, BuildAssetBundleOptions.UncompressedAssetBundle, true)); }
private void BuildUpdatePackage() { AssetBundleBuilder.BuildAssetsBundle(new BuildAssetConfig() { isUpdate = true, packagePath = PackagePath, updatePackagePath = UpdatePackagePath, successCallback = (path) => { UpdatePackagePath = string.Empty; EditorUtility.RevealInFinder(path); } }); }
public static void BuildAssetBundlesForCurrentPlatform() { var targetPlatform = AssetBundleEditorUtility.GetCurrentBuildTarget(); if (targetPlatform != BuildTarget.NoTarget) { var options = AssetBundleEditorUtility.GetBuildOptions(); AssetBundleBuilder.Build(targetPlatform, options); } else { Debug.LogError("Current platform has not supported."); } }
public IEnumerator WhenConvertedWithExternalTexturesDependenciesAreGeneratedCorrectly() { Caching.ClearCache(); if (Directory.Exists(AssetBundleBuilderConfig.ASSET_BUNDLES_PATH_ROOT)) { Directory.Delete(AssetBundleBuilderConfig.ASSET_BUNDLES_PATH_ROOT, true); } if (Directory.Exists(AssetBundleBuilderConfig.DOWNLOADED_PATH_ROOT)) { Directory.Delete(AssetBundleBuilderConfig.DOWNLOADED_PATH_ROOT, true); } AssetDatabase.Refresh(); var builder = new AssetBundleBuilder(); bool finished = false; System.Action <AssetBundleBuilder.ErrorCodes> onFinish = (x) => { finished = true; }; builder.DumpArea(new Vector2Int(-110, -110), new Vector2Int(1, 1), onFinish); yield return(new WaitUntil(() => finished == true)); AssetBundle abDependency = AssetBundle.LoadFromFile(AssetBundleBuilderConfig.ASSET_BUNDLES_PATH_ROOT + "/QmYACL8SnbXEonXQeRHdWYbfm8vxvaFAWnsLHUaDG4ABp5"); abDependency.LoadAllAssets(); AssetBundle abMain = AssetBundle.LoadFromFile(AssetBundleBuilderConfig.ASSET_BUNDLES_PATH_ROOT + "/QmNS4K7GaH63T9rhAfkrra7ADLXSEeco8FTGknkPnAVmKM"); Material[] mats = abMain.LoadAllAssets <Material>(); bool hasMap = false; foreach (var mat in mats) { if (mat.name.ToLowerInvariant().Contains("mini town")) { hasMap = mat.GetTexture("_BaseMap") != null; } } abMain.Unload(true); abDependency.Unload(true); Assert.IsTrue(hasMap, "Dependency has NOT been generated correctly!"); }
private void OnEnable() { ABOperationTypeNameArray = Enum.GetNames(typeof(EABOperationType)); mToolBarSelectIndex = 0; CurrentOperationType = (EABOperationType)Enum.Parse(typeof(EABOperationType), ABOperationTypeNameArray[mToolBarSelectIndex]); // 创建资源打包器 var appVersion = new Version(Application.version); var buildVersion = appVersion.Revision; var buildTarget = EditorUserBuildSettings.activeBuildTarget; mAssetBuilder = new AssetBundleBuilder(buildTarget, buildVersion); // 读取配置 LoadSettingsFromPlayerPrefs(mAssetBuilder); }
public static void CompleteBuild() { AssetBundleBuilder.SyncAssetBundles().Then(() => { InternalUpdateAchievementToServer(false).Then(() => { InternalUpdatePurchasableItemsToServer(false).Then(() => { InternalUpdateServerSettings(false).Then(() => { Build(); }); }); }); }); }
public static void BuildAssetBundles() { AssetDatabase.RemoveUnusedAssetBundleNames(); var assetBundleNames = AssetDatabase.GetAllAssetBundleNames(); var assetBundleBuilds = AssetBundleBuilder.GenerateAssetBundleBuilds(assetBundleNames); var currentBuildTarget = EditorUserBuildSettings.activeBuildTarget; var platformName = PlatformNameManager.GetPlatformName(currentBuildTarget); var outputPath = string.Format("AssetBundles/{0}", platformName); AssetBundleBuilder.CheckAndCreateDirectory(outputPath); var assetBundleManifest = BuildPipeline.BuildAssetBundles(outputPath, assetBundleBuilds, BuildAssetBundleOptions.ChunkBasedCompression, currentBuildTarget); AssetBundleBuilder.SaveAssetBundleInfoListFile(outputPath, assetBundleManifest); }
private static void BuildAssets(List <string> selectedPathList) { //获取资源分离后的路径 Dictionary <string, List <List <string> > > splitPathListListDict = GetSplitPathListListDict(selectedPathList); AssetDatabase.SaveAssets(); BuildAssets(splitPathListListDict); AssetRecordHelper.WriteAssetRecord(); AssetBundleBuilder.BuildAssetRecord(); //TemporaryAssetHelper.DeleteAllTempAsset(); if (AssetBuildStrategyManager.isSaveUIMediate == false) { UIPrefabProcessor.DeleteMediate(); } AssetBundleBuilder.LogBuildResult(); }
private void mOneKeyBuildStep2() { string str = EditorPrefs.GetString(GetOneKeyBuildPrefKeyStep1(), string.Empty); EditorPrefs.DeleteKey(GetOneKeyBuildPrefKeyStep1()); if (string.IsNullOrEmpty(str)) { Debug.LogError("Can Not Find OneKeyBuildStep2 param"); return; } Debug.Log("PlayerSettingTool Begin OneKeyBuildStep2"); JsonData jsonData = JsonMapper.ToObject(str); bool useCodeMove = jsonData["useCodeMove"].GetBoolean(); #if UNITY_IPHONE string target_dir = jsonData["target_dir"].GetString(); #endif if (useCodeMove) { #if USE_JSZ CodeManagerTool.moveUnUsedMonoCode(true); #else CodeManagerTool.moveJSBFramework(true); #endif } AssetBundleBuilder.ShowWindow(); AssetBundleBuilder.Instance._slientMode = true; Debug.Log("PlayerSettingTool UpdateAllBundleName"); AssetBundleBuilder.Instance.UpdateAllBundleName(); if (AssetBundleBuilder._curResConfig == null) { throw new SystemException("AssetBundleBuilder._curResConfig == null"); } Debug.Log("PlayerSettingTool BuildAllAssetBundle"); AssetBundleBuilder.Instance.BuildAll(AssetBundleBuilder._curResConfig.Version + 1, true); AssetBundleBuilder.ShowWindow(); EditorPrefs.SetString(GetOneKeyBuildPrefKeyStep2(), jsonData.ToJson()); Debug.Log("PlayerSettingTool OneKeyBuildStep2 Finish"); #if UNITY_IPHONE mOneKeyBuildStep3(); #else if (!EditorApplication.isCompiling) { mOneKeyBuildStep3(); } #endif }
private static void BuildAssetBundlesForCurrentPlatform(bool copyClientFull) { var assetBundleBuilder = new AssetBundleBuilder(); var resourcePlatform = AssetBundleBuilder.GetResourcePlatformFromBuildTarget(EditorUserBuildSettings.activeBuildTarget); var internalResourceVersion = AssetBundleBuilder.GetInternalResourceVersion(Application.version, resourcePlatform); assetBundleBuilder.BuildPlatform(resourcePlatform, true, false, BuildAssetBundleOptions.None); var outputDirectory = Path.Combine(assetBundleBuilder.GetOutputDirectory(resourcePlatform, internalResourceVersion), copyClientFull ? AssetBundleBuilder.ClientFullFolderName : AssetBundleBuilder.ClientFolderName); var di = new DirectoryInfo(Application.streamingAssetsPath); foreach (var file in di.GetFiles()) { if (file.Name.StartsWith(".")) { continue; } file.Delete(); } foreach (var dir in di.GetDirectories()) { dir.Delete(true); } foreach (var dirPath in Directory.GetDirectories(outputDirectory, "*", SearchOption.AllDirectories)) { Directory.CreateDirectory(dirPath.Replace(outputDirectory, Application.streamingAssetsPath)); } foreach (var filePath in Directory.GetFiles(outputDirectory, "*.*", SearchOption.AllDirectories)) { if (Regex.IsMatch(Path.GetFileName(filePath) ?? string.Empty, @".*index\..*\.dat\.json")) { continue; } File.Copy(filePath, filePath.Replace(outputDirectory, Application.streamingAssetsPath)); } AssetDatabase.Refresh(); }
private void QuickBuildPlayer() { if (!IsAbMode) { SwitchToAbMode(); } string savePath = EditorUtility.SaveFilePanel("Build", Directory.GetCurrentDirectory(), "f**k", GetPlatformPackageExtesion()); string saveDirectory = Path.GetDirectoryName(savePath); if (!Directory.Exists(saveDirectory)) { Directory.CreateDirectory(saveDirectory); } if (BuildResourcesPackage()) { AssetBundleBuilder.QuickBuildPlayer(savePath); } }
private void GenerateAsset(List <string> modList, string outputDir) { if (modList.IsEmpty()) { return; } foreach (string assetPath in modList) { string dstPath = GetOutputPath(outputDir, assetPath); dstPath = PathUtil.ReplaceExtension(dstPath, FileTypeEx.ASSET_BUNDLE); Object obj = AssetDatabase.LoadAssetAtPath("Assets/" + assetPath, typeof(Object)); if (obj != null) { AssetBundleBuilder.BuildAssetBundle(dstPath, buildTarget, obj, Path.GetFileNameWithoutExtension(assetPath)); log.Debug("Create AssetBundle '{0}'", dstPath); } else { throw new Exception("Invalid asset " + assetPath); } } }
private static void DoBuildAssetBundles() { var abPath = Application.streamingAssetsPath; if (Directory.Exists(abPath)) { Directory.Delete(abPath, true); } if (!Directory.Exists(abPath)) { Directory.CreateDirectory(abPath); } var builder = new AssetBundleBuilder(); builder.AddSceneBundle("Assets/Scenes/Test.unity", "scenes_"); builder.AddSceneBundle("Assets/Scenes/Loading.unity", "scenes_"); builder.AddDirBundle("Assets/Textures/Dynamic", "", "textures_"); builder.UpdateSharedAssets(); builder.BuildAssetBundles(abPath, BuildAssetBundleOptions.ChunkBasedCompression, EditorUserBuildSettings.activeBuildTarget); }
static string GetScenePrefabABName(GameObject go) { PrefabType prefabType = PrefabUtility.GetPrefabType(go); string bundleName = null; switch (prefabType) { case PrefabType.PrefabInstance: case PrefabType.Prefab: case PrefabType.ModelPrefabInstance: case PrefabType.ModelPrefab: Object asset = PrefabUtility.GetPrefabObject(go); if (asset != null) { string assetPath = AssetDatabase.GetAssetPath(asset); int changeCount = 0; bundleName = AssetBundleBuilder.UpdateStreamSceneBySingle(assetPath, ref changeCount); } break; } return(bundleName); }
public void InitializeDirectoryPathsWorkCorrectly() { var builder = new AssetBundleBuilder(); builder.InitializeDirectoryPaths(false); Assert.IsFalse(string.IsNullOrEmpty(builder.finalAssetBundlePath)); Assert.IsFalse(string.IsNullOrEmpty(builder.finalDownloadedPath)); Assert.IsTrue(Directory.Exists(builder.finalAssetBundlePath)); Assert.IsTrue(Directory.Exists(builder.finalDownloadedPath)); string file1 = builder.finalAssetBundlePath + "test.txt"; string file2 = builder.finalDownloadedPath + "test.txt"; File.WriteAllText(file1, "test"); File.WriteAllText(file2, "test"); builder.InitializeDirectoryPaths(true); Assert.IsFalse(File.Exists(file1)); Assert.IsFalse(File.Exists(file2)); }
public static void BuildAllAssetBundles() { Log.i("#Start Build All AssetBundles."); AssetBundleBuilder.BuildAB(FilePath.streamingAssetsPath4AB, EditorUserBuildSettings.activeBuildTarget); BuildDataTable(); }