| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEditor;
- using System.IO;
- using System;
- public class BuildTools : MonoBehaviour
- {
- private static string GameName = PlayerSettings.productName + "_" + DateTime.Now.ToString("yyyyMMddHHmm");
- private static string OutPutPath = System.IO.Directory.GetCurrentDirectory() + "/BuildTools/OutPut/";
- //private static string ApkPath = string.Format("{0}{1}.apk", OutPutPath, GameName);
- //private static string ApkAndroidPath = string.Format("{0}{1}", OutPutPath, GameName+ "Android");
- //private static string EXEPath = string.Format("{0}{1}.exe", OutPutPath + GameName+ "_PC" + "/",GameName);
- //private static string AndroidProjectPath = string.Format("{0}{1}_AndroidProject", OutPutPath, GameName);
- [MenuItem("Tools/打包/打包APK")]
- public static void BuildAPK()
- {
- string versionName = "1.0.0";
- int versionCode = 1;
- string productName = "";
- string WorkSpace = "";
- bool isDevelopment = false;
- Debug.Log("------------- 接收命令行参数 -------------");
- List<string> commondList = new List<string>();
- foreach (string arg in System.Environment.GetCommandLineArgs())
- {
- Debug.Log("命令行传递过来参数:" + arg);
- commondList.Add(arg);
- }
- try
- {
- Debug.Log("命令行传递过来参数数量:" + commondList.Count);
- versionName = commondList[commondList.Count - 3];
- productName = commondList[commondList.Count - 2];
- versionCode = int.Parse(commondList[commondList.Count - 1]);
- //versionCode = (int)commondList[commondList.Count - 1];
- }
- catch (Exception e)
- {
- print(e.Message);
- }
- string ApkPath = string.Format("{0}{1}.apk", OutPutPath, productName);
- Debug.Log("------------- 更新资源 -------------");
- //OneKeyRefreshSource.Create();
- Debug.Log("------------- 开始 BuildAPK -------------");
- EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
- PlayerSettings.bundleVersion = versionName;
- PlayerSettings.Android.bundleVersionCode = versionCode;
- PlayerSettings.Android.useCustomKeystore = true;
- // keystore 路径
- PlayerSettings.Android.keystoreName = "D:\\jenkins\\script\\zeewain.keystore";
- // one.keystore 密码
- PlayerSettings.Android.keystorePass = "zeewain123";
- // one.keystore 别名
- PlayerSettings.Android.keyaliasName = "zeewain";
- // 别名密码
- PlayerSettings.Android.keyaliasPass = "zeewain123";
- //打包安卓工程为true
- EditorUserBuildSettings.exportAsGoogleAndroidProject = false;
- SetSplashScreen();
- BuildOptions buildOption = BuildOptions.None;
- if (isDevelopment)
- buildOption |= BuildOptions.Development;
- else
- buildOption &= BuildOptions.Development;
- //PlayerSettings.Android.keystorePass = "00000000"; // 密钥密码
- //PlayerSettings.Android.keyaliasName = "test.keystore"; // 密钥别名
- //PlayerSettings.Android.keyaliasPass = "00000000";
- BuildPipeline.BuildPlayer(EditorBuildSettings.scenes, ApkPath, BuildTarget.Android, buildOption);
- Debug.Log("------------- 结束 BuildAPK -------------");
- Debug.Log("Build目录:" + ApkPath);
- Debug.Log("BuildEnd");
- //Application.OpenURL(OutPutPath);
- }
- public static void SetSplashScreen()
- {
- PlayerSettings.SplashScreen.show = true;
- PlayerSettings.SplashScreen.showUnityLogo = false;
- var logo = new PlayerSettings.SplashScreenLogo();
- //设置闪屏时间
- logo.duration = 2f;
- //设置闪屏背景颜色
- PlayerSettings.SplashScreen.backgroundColor = Color.black;
- //设置闪屏logo
- if (AssetDatabase.LoadAssetAtPath<Sprite>("Assets/Resources/Logo/logo.png") != null)
- {
- logo.logo = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/Resources/Logo/logo.png");
- PlayerSettings.SplashScreen.logos = new PlayerSettings.SplashScreenLogo[1] { logo };
- }
- }
- [MenuItem("Tools/打包/打包Android")]
- public static void BuildAndroid()
- {
- string versionName = "1.0.0";
- int versionCode = 1;
- string productName = "";
- string WorkSpace = "";
- bool isDevelopment = false;
- Debug.Log("------------- 接收命令行参数 -------------");
- List<string> commondList = new List<string>();
- foreach (string arg in System.Environment.GetCommandLineArgs())
- {
- Debug.Log("命令行传递过来参数:" + arg);
- commondList.Add(arg);
- }
- try
- {
- Debug.Log("命令行传递过来参数数量:" + commondList.Count);
- versionName = commondList[commondList.Count - 3];
- productName = commondList[commondList.Count - 2];
- //versionCode = (int)commondList[commondList.Count - 1];
- versionCode = int.Parse(commondList[commondList.Count - 1]);
- }
- catch (Exception e)
- {
- print(e.Message);
- }
- string[] m_Array;
- string m_ProductName = "";
- m_Array = productName.Split('_');
- m_ProductName = m_Array[0];
- string AndroidPath = string.Format("{0}{1}", OutPutPath, productName + "/" + m_ProductName);
- Debug.Log("------------- 更新资源 -------------");
- //OneKeyRefreshSource.Create();
- Debug.Log("------------- 开始 BuildApkAndroid -------------");
- EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
- PlayerSettings.bundleVersion = versionName;
- PlayerSettings.Android.bundleVersionCode = versionCode;
- // keystore 路径
- PlayerSettings.Android.keystoreName = "D:\\jenkins\\script\\zeewain.keystore";
- // one.keystore 密码
- PlayerSettings.Android.keystorePass = "zeewain123";
- // one.keystore 别名
- PlayerSettings.Android.keyaliasName = "zeewain";
- // 别名密码
- PlayerSettings.Android.keyaliasPass = "zeewain123";
- //打包安卓工程为true
- EditorUserBuildSettings.exportAsGoogleAndroidProject = true;
- SetSplashScreen();
- BuildOptions buildOption = BuildOptions.None;
- if (isDevelopment)
- buildOption |= BuildOptions.Development;
- else
- buildOption &= BuildOptions.Development;
- //PlayerSettings.Android.keystorePass = "00000000"; // 密钥密码
- //PlayerSettings.Android.keyaliasName = "test.keystore"; // 密钥别名
- //PlayerSettings.Android.keyaliasPass = "00000000";
- BuildPipeline.BuildPlayer(EditorBuildSettings.scenes, AndroidPath, BuildTarget.Android, buildOption);
- Debug.Log("------------- 结束 BuildAndroid -------------");
- Debug.Log("Build目录:" + AndroidPath);
- Debug.Log("BuildEnd");
- //Application.OpenURL(OutPutPath);
- }
- [MenuItem("Tools/打包/打包EXE")]
- public static void BuildEXE()
- {
- string versionName = "1.0.0";
- int versionCode = 1;
- string productName = "";
- string WorkSpace = "";
- bool isDevelopment = false;
- Debug.Log("------------- 接收命令行参数 -------------");
- List<string> commondList = new List<string>();
- foreach (string arg in System.Environment.GetCommandLineArgs())
- {
- Debug.Log("命令行传递过来参数:" + arg);
- commondList.Add(arg);
- }
- try
- {
- Debug.Log("命令行传递过来参数数量:" + commondList.Count);
- versionName = commondList[commondList.Count - 3];
- productName = commondList[commondList.Count - 2];
- versionCode = int.Parse(commondList[commondList.Count - 1]);
- //versionCode = (int)commondList[commondList.Count - 1];
- }
- catch (Exception e)
- {
- print(e.Message);
- }
- string EXEPath = string.Format("{0}{1}.exe", OutPutPath + productName + "/", productName);
- Debug.Log("------------- 更新资源 -------------");
- //OneKeyRefreshSource.Create();
- Debug.Log("------------- 开始 BuildEXE -------------");
- EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows);
- PlayerSettings.bundleVersion = versionName;
- PlayerSettings.Android.bundleVersionCode = versionCode;
- PlayerSettings.resizableWindow = false;
- PlayerSettings.fullScreenMode = FullScreenMode.FullScreenWindow;
- SetSplashScreen();
- BuildOptions buildOption = BuildOptions.None;
- if (isDevelopment)
- buildOption |= BuildOptions.Development;
- else
- buildOption &= BuildOptions.Development;
- //PlayerSettings.Android.keystorePass = "00000000"; // 密钥密码
- //PlayerSettings.Android.keyaliasName = "test.keystore"; // 密钥别名
- //PlayerSettings.Android.keyaliasPass = "00000000";
- BuildPipeline.BuildPlayer(EditorBuildSettings.scenes, EXEPath, BuildTarget.StandaloneWindows64, buildOption);
- Debug.Log("------------- 结束 BuildEXE -------------");
- Debug.Log("Build目录:" + EXEPath);
- Debug.Log("BuildEnd");
- //Application.OpenURL(OutPutPath);
- }
- }
|