BuildPipeline.BuildPlayer()

作者:追风剑情 发布于:2018-12-12 18:32 分类:Unity3d

示例代码


// Build场景
public static void BuildScene(Object asset, string export_folder=null)
{
	if (asset == null)
		return;
	string assetPath = AssetDatabase.GetAssetPath(asset);
	BuildScene(assetPath, export_folder);
}

public static void BuildScene(string assetPath, string export_folder=null)
{
	if (string.IsNullOrEmpty(assetPath) || !assetPath.EndsWith(".unity"))
		return;

	if (string.IsNullOrEmpty(export_folder))
		export_folder = "Assets/StreamingAssets/res/scenes";

	if (!Directory.Exists(export_folder))
		Directory.CreateDirectory(export_folder);

	string assetName = Path.GetFileNameWithoutExtension(assetPath);
	string locationPathName = string.Format("{0}/{1}.scene", export_folder, assetName);
	Debug.Log(locationPathName);

	BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
	buildPlayerOptions.scenes = new string[] { assetPath };
	buildPlayerOptions.locationPathName = locationPathName;
	buildPlayerOptions.target = EditorUserBuildSettings.activeBuildTarget;
	buildPlayerOptions.options = BuildOptions.BuildAdditionalStreamedScenes;

	string result = BuildPipeline.BuildPlayer(buildPlayerOptions);
	if (!string.IsNullOrEmpty(result)) {
		Debug.LogError(result);
	}
}

public static void BuildWindows()
{
        //PC平台打包
        BuildPipeline.BuildPlayer(EditorBuildSettings.scenes, 
            "pc/xxx.exe", 
            EditorUserBuildSettings.activeBuildTarget,
            BuildOptions.None);
}


标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号