You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.8 KiB
83 lines
2.8 KiB
3 years ago
|
using System.IO;
|
||
|
|
||
|
using UnityEditor;
|
||
|
using UnityEngine;
|
||
|
|
||
|
namespace ET
|
||
|
{
|
||
|
public static class BuildHelper
|
||
|
{
|
||
|
private const string relativeDirPrefix = "../Release";
|
||
|
|
||
|
public static string BuildFolder = "../Release/{0}/StreamingAssets/";
|
||
|
|
||
|
public static void Build(PlatformType type, BuildAssetBundleOptions buildAssetBundleOptions, BuildOptions buildOptions, bool isBuildExe, bool isContainAB, bool clearFolder)
|
||
|
{
|
||
|
BuildTarget buildTarget = BuildTarget.StandaloneWindows;
|
||
|
string programName = "ET";
|
||
|
string exeName = programName;
|
||
|
switch (type)
|
||
|
{
|
||
|
case PlatformType.PC:
|
||
|
buildTarget = BuildTarget.StandaloneWindows64;
|
||
|
exeName += ".exe";
|
||
|
break;
|
||
|
case PlatformType.Android:
|
||
|
buildTarget = BuildTarget.Android;
|
||
|
exeName += ".apk";
|
||
|
break;
|
||
|
case PlatformType.IOS:
|
||
|
buildTarget = BuildTarget.iOS;
|
||
|
break;
|
||
|
case PlatformType.MacOS:
|
||
|
buildTarget = BuildTarget.StandaloneOSX;
|
||
|
break;
|
||
|
}
|
||
|
|
||
|
string fold = string.Format(BuildFolder, type);
|
||
|
|
||
|
if (clearFolder && Directory.Exists(fold))
|
||
|
{
|
||
|
Directory.Delete(fold, true);
|
||
|
Directory.CreateDirectory(fold);
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
Directory.CreateDirectory(fold);
|
||
|
}
|
||
|
|
||
|
UnityEngine.Debug.Log("开始资源打包");
|
||
|
BuildPipeline.BuildAssetBundles(fold, buildAssetBundleOptions, buildTarget);
|
||
|
|
||
|
UnityEngine.Debug.Log("完成资源打包");
|
||
|
|
||
|
if (isContainAB)
|
||
|
{
|
||
|
FileHelper.CleanDirectory("Assets/StreamingAssets/");
|
||
|
FileHelper.CopyDirectory(fold, "Assets/StreamingAssets/");
|
||
|
}
|
||
|
|
||
|
if (isBuildExe)
|
||
|
{
|
||
|
AssetDatabase.Refresh();
|
||
|
string[] levels = {
|
||
|
"Assets/Scenes/Init.unity",
|
||
|
};
|
||
|
UnityEngine.Debug.Log("开始EXE打包");
|
||
|
BuildPipeline.BuildPlayer(levels, $"{relativeDirPrefix}/{exeName}", buildTarget, buildOptions);
|
||
|
UnityEngine.Debug.Log("完成exe打包");
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
if (isContainAB && type == PlatformType.PC)
|
||
|
{
|
||
|
string targetPath = Path.Combine(relativeDirPrefix, $"{programName}_Data/StreamingAssets/");
|
||
|
FileHelper.CleanDirectory(targetPath);
|
||
|
Debug.Log($"src dir: {fold} target: {targetPath}");
|
||
|
FileHelper.CopyDirectory(fold, targetPath);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|