You've already forked taptap2024_GJ_chidouren
init
This commit is contained in:
142
Assets/Scripts/Editor/BuildTools.cs
Normal file
142
Assets/Scripts/Editor/BuildTools.cs
Normal file
@@ -0,0 +1,142 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
|
||||
namespace BuildEditor
|
||||
{
|
||||
public class BuildTools
|
||||
{
|
||||
// [MenuItem("Build/自动化构建ab包")]
|
||||
private static void BuildAssetBundle(bool isTest)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
#if UNITY_ANDROID
|
||||
[MenuItem("Build/Build Taptap (需要先打ab包)")]
|
||||
public static void BuildTaptap()
|
||||
{
|
||||
GameGlobalConfig.Instance.Channel = GameChannel.Taptap;
|
||||
BuildStandalonePlayer(BuildOptions.ShowBuiltPlayer);
|
||||
}
|
||||
|
||||
[MenuItem("Build/Build 快爆 (需要先打ab包)")]
|
||||
public static void BuildKuaibao()
|
||||
{
|
||||
GameGlobalConfig.Instance.Channel = GameChannel.Kuaibao;
|
||||
BuildStandalonePlayer(BuildOptions.ShowBuiltPlayer);
|
||||
}
|
||||
|
||||
[MenuItem("Build/Build 摸摸鱼 (需要先打ab包)")]
|
||||
public static void BuildMomoyu()
|
||||
{
|
||||
GameGlobalConfig.Instance.Channel = GameChannel.Momoyu;
|
||||
BuildStandalonePlayer(BuildOptions.ShowBuiltPlayer);
|
||||
}
|
||||
|
||||
[MenuItem("Build/一键打包 测试包 (自动build ab包)")]
|
||||
public static void BuildTest()
|
||||
{
|
||||
BuildAssetBundle(true);
|
||||
GameGlobalConfig.Instance.Channel = GameChannel.Private;
|
||||
BuildStandalonePlayer(BuildOptions.ShowBuiltPlayer);
|
||||
}
|
||||
|
||||
[MenuItem("Build/构建所有渠道包 (自动build ab包)")]
|
||||
public static void BuildAll ()
|
||||
{
|
||||
BuildAssetBundle(false);
|
||||
GameGlobalConfig.Instance.Channel = GameChannel.Taptap;
|
||||
BuildStandalonePlayer();
|
||||
GameGlobalConfig.Instance.Channel = GameChannel.Kuaibao;
|
||||
BuildStandalonePlayer();
|
||||
GameGlobalConfig.Instance.Channel = GameChannel.Momoyu;
|
||||
BuildStandalonePlayer(BuildOptions.ShowBuiltPlayer);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public static void BuildStandalonePlayer(BuildOptions buildOptions = BuildOptions.None)
|
||||
{
|
||||
#if !UNITY_IOS
|
||||
CheckKeyPwd();
|
||||
#endif
|
||||
var outputPath =
|
||||
Path.Combine(Environment.CurrentDirectory,
|
||||
"Build/" + Application.version); //EditorUtility.SaveFolderPanel("Choose Location of the Built Game", "", "");
|
||||
if (outputPath.Length == 0)
|
||||
return;
|
||||
|
||||
var levels = new List<string>();
|
||||
for (int i = 0; i < SceneManager.sceneCount; i++)
|
||||
{
|
||||
var sceneAt = SceneManager.GetSceneAt(i);
|
||||
if (sceneAt.IsValid())
|
||||
{
|
||||
levels.Add(sceneAt.path);
|
||||
}
|
||||
}
|
||||
|
||||
if (levels.Count == 0)
|
||||
{
|
||||
Debug.Log("Nothing to build.");
|
||||
return;
|
||||
}
|
||||
|
||||
var targetName = "/" + Application.identifier +
|
||||
$"_{GameGlobalConfig.Instance.Channel}_{Application.version}.apk";
|
||||
#if GM
|
||||
targetName = targetName.Replace(".apk", "[GM].apk");
|
||||
#endif
|
||||
if (targetName == null)
|
||||
return;
|
||||
#if UNITY_5_4 || UNITY_5_3 || UNITY_5_2 || UNITY_5_1 || UNITY_5_0
|
||||
BuildOptions option = EditorUserBuildSettings.development ? BuildOptions.Development : BuildOptions.None;
|
||||
BuildPipeline.BuildPlayer(levels, path + targetName, EditorUserBuildSettings.activeBuildTarget, option);
|
||||
#else
|
||||
var buildPlayerOptions = new BuildPlayerOptions
|
||||
{
|
||||
scenes = levels.ToArray(),
|
||||
locationPathName = outputPath + targetName,
|
||||
target = EditorUserBuildSettings.activeBuildTarget,
|
||||
options = EditorUserBuildSettings.development
|
||||
? BuildOptions.Development
|
||||
: buildOptions
|
||||
// : BuildOptions.AutoRunPlayer
|
||||
};
|
||||
var buildPlayer = BuildPipeline.BuildPlayer(buildPlayerOptions);
|
||||
BuildSummary summary = buildPlayer.summary;
|
||||
if (summary.result == BuildResult.Succeeded)
|
||||
{
|
||||
Debug.Log("构建应用成功: " + summary.totalSize / (1024 * 1024.0f * 10) + " mb");
|
||||
Debug.Log("构建应用地址: " + summary.outputPath);
|
||||
}
|
||||
|
||||
if (summary.result == BuildResult.Failed)
|
||||
{
|
||||
Debug.Log("构建应用失败");
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
[MenuItem("Build/Check KeyPwd")]
|
||||
public static void CheckKeyPwd()
|
||||
{
|
||||
if (string.IsNullOrEmpty(PlayerSettings.keystorePass))
|
||||
{
|
||||
PlayerSettings.keystorePass = "123456";
|
||||
PlayerSettings.keyaliasPass = "123456";
|
||||
}
|
||||
}
|
||||
|
||||
[MenuItem("Build/打开持久化存储目录")]
|
||||
private static void ViewDataPath()
|
||||
{
|
||||
EditorUtility.OpenWithDefaultApp(Application.persistentDataPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user