144 lines
7.1 KiB
C#
144 lines
7.1 KiB
C#
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEditor;
|
|||
|
|
using System.IO;
|
|||
|
|
using System.Linq;
|
|||
|
|
using GeneralTools;
|
|||
|
|
|
|||
|
|
public class AutoBuild : MonoBehaviour
|
|||
|
|
{
|
|||
|
|
/// <summary>
|
|||
|
|
///
|
|||
|
|
/// </summary>
|
|||
|
|
public static void Build(bool development)
|
|||
|
|
{
|
|||
|
|
BuildTargetGroup group = EditorUserBuildSettings.selectedBuildTargetGroup;
|
|||
|
|
BuildTarget target = EditorUserBuildSettings.activeBuildTarget;
|
|||
|
|
RuntimePlatform tr = Application.platform;
|
|||
|
|
if (group == BuildTargetGroup.Standalone && target == BuildTarget.StandaloneWindows)
|
|||
|
|
{
|
|||
|
|
//Windows
|
|||
|
|
Debug.Log("Windows打包_x86");
|
|||
|
|
BuildEXE(development);
|
|||
|
|
}
|
|||
|
|
else if (group == BuildTargetGroup.Standalone && target == BuildTarget.StandaloneWindows64)
|
|||
|
|
{
|
|||
|
|
//Windows
|
|||
|
|
Debug.Log("Windows打包_x86x64");
|
|||
|
|
BuildEXE64(development);
|
|||
|
|
}
|
|||
|
|
else if (group == BuildTargetGroup.Android && target == BuildTarget.Android)
|
|||
|
|
{
|
|||
|
|
//Android
|
|||
|
|
Debug.Log("Android打包");
|
|||
|
|
BuildAPK(development);
|
|||
|
|
}
|
|||
|
|
else if (group == BuildTargetGroup.iOS && target == BuildTarget.iOS)
|
|||
|
|
{
|
|||
|
|
//iOS
|
|||
|
|
Debug.Log("iOS打包");
|
|||
|
|
BuildIPA(development);
|
|||
|
|
}
|
|||
|
|
else if (group == BuildTargetGroup.Standalone && target == BuildTarget.StandaloneOSX)
|
|||
|
|
{
|
|||
|
|
//MacApp
|
|||
|
|
Debug.Log("MacApp打包");
|
|||
|
|
BuildAPP(development);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Windows32位
|
|||
|
|
/// </summary>
|
|||
|
|
private static void BuildEXE(bool development)
|
|||
|
|
{
|
|||
|
|
//EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows);
|
|||
|
|
//AssetDatabase.Refresh();
|
|||
|
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
|
|||
|
|
buildPlayerOptions.locationPathName = "Build/Windows/" + Application.productName + "/" + Application.productName + ".exe";
|
|||
|
|
buildPlayerOptions.scenes = EditorBuildSettings.scenes.Where(s => s.enabled && !string.IsNullOrEmpty(s.path)).Select(s => s.path).ToArray();
|
|||
|
|
buildPlayerOptions.targetGroup = BuildTargetGroup.Standalone;
|
|||
|
|
buildPlayerOptions.target = BuildTarget.StandaloneWindows;
|
|||
|
|
buildPlayerOptions.options = (BuildOptions)(8 + (development ? 1 : 0));
|
|||
|
|
OnPreprocessBuildDoing.OverridesBuildPlayer(buildPlayerOptions);
|
|||
|
|
// BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(buildPlayerOptions);
|
|||
|
|
//OpenFolder(Path.GetDirectoryName(Application.dataPath), "Build", "Windows", Application.productName);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Windows64位
|
|||
|
|
/// </summary>
|
|||
|
|
private static void BuildEXE64(bool development)
|
|||
|
|
{
|
|||
|
|
//EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows);
|
|||
|
|
//AssetDatabase.Refresh();
|
|||
|
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
|
|||
|
|
buildPlayerOptions.locationPathName = "Build/Windows/" + Application.productName + "/" + Application.productName + ".exe";
|
|||
|
|
buildPlayerOptions.scenes = EditorBuildSettings.scenes.Where(s => s.enabled && !string.IsNullOrEmpty(s.path)).Select(s => s.path).ToArray();
|
|||
|
|
buildPlayerOptions.targetGroup = BuildTargetGroup.Standalone;
|
|||
|
|
buildPlayerOptions.target = BuildTarget.StandaloneWindows64;
|
|||
|
|
buildPlayerOptions.options = (BuildOptions)(8 + (development ? 1 : 0));
|
|||
|
|
OnPreprocessBuildDoing.OverridesBuildPlayer(buildPlayerOptions);
|
|||
|
|
// BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(buildPlayerOptions);
|
|||
|
|
//OpenFolder(Path.GetDirectoryName(Application.dataPath), "Build", "Windows", Application.productName);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Android
|
|||
|
|
/// </summary>
|
|||
|
|
private static void BuildAPK(bool development)
|
|||
|
|
{
|
|||
|
|
//EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
|
|||
|
|
//AssetDatabase.Refresh();
|
|||
|
|
EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
|
|||
|
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
|
|||
|
|
buildPlayerOptions.locationPathName = "Build/Android/" + Application.productName + "/" + Application.productName + ".apk";
|
|||
|
|
buildPlayerOptions.scenes = EditorBuildSettings.scenes.Where(s => s.enabled && !string.IsNullOrEmpty(s.path)).Select(s => s.path).ToArray();
|
|||
|
|
buildPlayerOptions.targetGroup = BuildTargetGroup.Android;
|
|||
|
|
buildPlayerOptions.target = BuildTarget.Android;
|
|||
|
|
buildPlayerOptions.options = (BuildOptions)(8 + (development ? 1 : 0));
|
|||
|
|
OnPreprocessBuildDoing.OverridesBuildPlayer(buildPlayerOptions);
|
|||
|
|
// BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(buildPlayerOptions);
|
|||
|
|
// OpenFolder(Path.GetDirectoryName(Application.dataPath), "Build", "Android", Application.productName);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// IOS
|
|||
|
|
/// </summary>
|
|||
|
|
private static void BuildIPA(bool development)
|
|||
|
|
{
|
|||
|
|
//EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.iOS, BuildTarget.iOS);
|
|||
|
|
//AssetDatabase.Refresh();
|
|||
|
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
|
|||
|
|
buildPlayerOptions.locationPathName = "Build/iOS/" + Application.productName;
|
|||
|
|
buildPlayerOptions.scenes = EditorBuildSettings.scenes.Where(s => s.enabled && !string.IsNullOrEmpty(s.path)).Select(s => s.path).ToArray();
|
|||
|
|
buildPlayerOptions.targetGroup = BuildTargetGroup.iOS;
|
|||
|
|
buildPlayerOptions.target = BuildTarget.iOS;
|
|||
|
|
buildPlayerOptions.options = (BuildOptions)(8 + (development ? 1 : 0));
|
|||
|
|
OnPreprocessBuildDoing.OverridesBuildPlayer(buildPlayerOptions);
|
|||
|
|
// BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(buildPlayerOptions);
|
|||
|
|
// OpenFolder(Path.GetDirectoryName(Application.dataPath), "Build", "iOS", Application.productName);
|
|||
|
|
}
|
|||
|
|
/// <summary>
|
|||
|
|
/// Mac
|
|||
|
|
/// </summary>
|
|||
|
|
private static void BuildAPP(bool development)
|
|||
|
|
{
|
|||
|
|
//EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneOSX);
|
|||
|
|
//AssetDatabase.Refresh();
|
|||
|
|
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
|
|||
|
|
buildPlayerOptions.locationPathName = "Build/MacOS/" + Application.productName + "/" + Application.productName;
|
|||
|
|
buildPlayerOptions.scenes = EditorBuildSettings.scenes.Where(s => s.enabled && !string.IsNullOrEmpty(s.path)).Select(s => s.path).ToArray();
|
|||
|
|
buildPlayerOptions.targetGroup = BuildTargetGroup.Standalone;
|
|||
|
|
buildPlayerOptions.target = BuildTarget.StandaloneOSX;
|
|||
|
|
buildPlayerOptions.options = (BuildOptions)(8 + (development ? 1 : 0));
|
|||
|
|
OnPreprocessBuildDoing.OverridesBuildPlayer(buildPlayerOptions);
|
|||
|
|
// BuildPlayerWindow.DefaultBuildMethods.BuildPlayer(buildPlayerOptions);
|
|||
|
|
// OpenFolder(Path.GetDirectoryName(Application.dataPath), "Build", "MacOS", Application.productName);
|
|||
|
|
}
|
|||
|
|
private static void OpenFolder(params string[] path)
|
|||
|
|
{
|
|||
|
|
if (Application.platform == RuntimePlatform.WindowsEditor)
|
|||
|
|
{
|
|||
|
|
System.Diagnostics.Process.Start("explorer.exe", Path.Combine(path));
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|