106 lines
3.5 KiB
C#
106 lines
3.5 KiB
C#
using System.Linq;
|
|
using UnityEditor;
|
|
using UnityEditor.Build.Reporting;
|
|
using UnityEngine;
|
|
|
|
namespace ET
|
|
{
|
|
public static class BuildHelper
|
|
{
|
|
private const string relativeDirPrefix = "../Release";
|
|
|
|
public static string BuildFolder = "../Release/{0}/StreamingAssets/";
|
|
|
|
[InitializeOnLoadMethod]
|
|
public static void ReGenerateProjectFiles()
|
|
{
|
|
Unity.CodeEditor.CodeEditor.CurrentEditor.SyncAll();
|
|
}
|
|
|
|
#if ENABLE_VIEW
|
|
[MenuItem("ET/ChangeDefine/Remove ENABLE_VIEW", false, ETMenuItemPriority.ChangeDefine)]
|
|
public static void RemoveEnableView()
|
|
{
|
|
EnableDefineSymbols("ENABLE_VIEW", false);
|
|
}
|
|
#else
|
|
[MenuItem("ET/ChangeDefine/Add ENABLE_VIEW", false, ETMenuItemPriority.ChangeDefine)]
|
|
public static void AddEnableView()
|
|
{
|
|
EnableDefineSymbols("ENABLE_VIEW", true);
|
|
}
|
|
#endif
|
|
public static void EnableDefineSymbols(string symbols, bool enable)
|
|
{
|
|
Debug.Log($"EnableDefineSymbols {symbols} {enable}");
|
|
string defines = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup);
|
|
var ss = defines.Split(';').ToList();
|
|
if (enable)
|
|
{
|
|
if (ss.Contains(symbols))
|
|
{
|
|
return;
|
|
}
|
|
|
|
ss.Add(symbols);
|
|
}
|
|
else
|
|
{
|
|
if (!ss.Contains(symbols))
|
|
{
|
|
return;
|
|
}
|
|
|
|
ss.Remove(symbols);
|
|
}
|
|
|
|
Debug.Log($"EnableDefineSymbols {symbols} {enable}");
|
|
defines = string.Join(";", ss);
|
|
PlayerSettings.SetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup, defines);
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
}
|
|
|
|
public static void Build(PlatformType type, BuildOptions buildOptions)
|
|
{
|
|
BuildTarget buildTarget = BuildTarget.StandaloneWindows;
|
|
string programName = "ET";
|
|
string exeName = programName;
|
|
switch (type)
|
|
{
|
|
case PlatformType.Windows:
|
|
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;
|
|
case PlatformType.Linux:
|
|
buildTarget = BuildTarget.StandaloneLinux64;
|
|
break;
|
|
}
|
|
|
|
AssetDatabase.Refresh();
|
|
|
|
Debug.Log("start build exe");
|
|
|
|
string[] levels = { "Assets/Scenes/Init.unity" };
|
|
BuildReport report = BuildPipeline.BuildPlayer(levels, $"{relativeDirPrefix}/{exeName}", buildTarget, buildOptions);
|
|
if (report.summary.result != BuildResult.Succeeded)
|
|
{
|
|
Debug.Log($"BuildResult:{report.summary.result}");
|
|
return;
|
|
}
|
|
|
|
Debug.Log("finish build exe");
|
|
EditorUtility.OpenWithDefaultApp(relativeDirPrefix);
|
|
}
|
|
}
|
|
} |