public static void BuildStreamedSceneAssetBundles() { // Choose the output path according to the build target. string outputPath = ExportUtil.getStreamingDataPath(""); if (!Directory.Exists(outputPath)) { Directory.CreateDirectory(outputPath); } string[] levels = ExportUtil.GetLevelsFromBuildSettings(); AssetBundleParam param = new AssetBundleParam(); param.m_buildList = new AssetBundleBuild[1]; param.m_buildList[0].assetBundleName = "TestExportScene"; param.m_buildList[0].assetBundleVariant = UtilApi.UNITY3D; param.m_buildList[0].assetNames = new string[1]; param.m_buildList[0].assetNames[0] = levels[3]; // 这个目录一定要是 Assets 下面写,并且加上扩展名字 param.m_pathName = outputPath; param.m_assetBundleOptions = 0; param.m_targetPlatform = EditorUserBuildSettings.activeBuildTarget; ExportUtil.BuildAssetBundle(param); }
// 打包场景 public static void BuildPlayer() { var outputPath = EditorUtility.SaveFolderPanel("Choose Location of the Built Game", "", ""); if (outputPath.Length == 0) { return; } string[] levels = ExportUtil.GetLevelsFromBuildSettings(); if (levels.Length == 0) { Debug.Log("Nothing to build."); return; } string targetName = ExportUtil.GetBuildTargetName(EditorUserBuildSettings.activeBuildTarget); if (targetName == null) { return; } // Build and copy AssetBundles. BuildScriptTest.BuildAssetLabelsAssetBundles(); BuildScriptTest.CopyAssetBundlesTo(Path.Combine(Application.streamingAssetsPath, ExportUtil.ASSET_BUNDLES_OUTPUT_PATH)); BuildOptions option = EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None; PlayerParam param = new PlayerParam(); param.m_levels = levels; param.m_locationPath = outputPath + targetName; param.m_target = EditorUserBuildSettings.activeBuildTarget; param.m_options = option; ExportUtil.BuildPlayer(param); }