游戏应用打包

作者:追风剑情 发布于:2022-8-10 17:00 分类:Unity3d

差异化打包


  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEditor;
  5. using UnityEditor.Build.Reporting;
  6.  
  7. public class MenuToolEditor : MonoBehaviour
  8. {
  9. [MenuItem("Tool/Build XXX")]
  10. public static void BuildBigDipper()
  11. {
  12. Debug.Log("Build XXX");
  13. //设置产品名称
  14. PlayerSettings.productName = "XXX";
  15. //设置包名
  16. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, Config.BIG_DIPPER_IDENTIFIER);
  17. //设置AppIcon
  18. string[] appIconNames = { "192", "144", "96", "72", "48", "36" };
  19. Texture2D[] icons = new Texture2D[appIconNames.Length];
  20. for (int i=0; i<icons.Length; i++)
  21. {
  22. string path = string.Format("UI/Sprite/海岛/AppIcon/{0}", appIconNames[i]);
  23. icons[i] = Resources.Load<Texture2D>(path);
  24. }
  25. PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, icons);
  26. //设置闪屏Logo
  27. var logo = Resources.Load<Sprite>("UI/Sprite/Logo/logo_new");
  28. var screenLogo = PlayerSettings.SplashScreenLogo.Create(2, logo);
  29. PlayerSettings.SplashScreen.logos = new PlayerSettings.SplashScreenLogo[] { screenLogo };
  30. //打包APK
  31. BuildAndroid();
  32. }
  33.  
  34. [MenuItem("Tool/Build YYY")]
  35. public static void BuildMicrowave()
  36. {
  37. Debug.Log("Build YYY");
  38. //设置产品名称
  39. PlayerSettings.productName = "YYY";
  40. //设置包名
  41. PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, Config.MICROWAVE_IDENTIFIER);
  42. //设置AppIcon
  43. string[] appIconNames = { "192", "144", "96", "72", "48", "36" };
  44. Texture2D[] icons = new Texture2D[appIconNames.Length];
  45. for (int i = 0; i < icons.Length; i++)
  46. {
  47. string path = string.Format("UI/Sprite/城市/AppIcon/{0}", appIconNames[i]);
  48. icons[i] = Resources.Load<Texture2D>(path);
  49. }
  50. PlayerSettings.SetIconsForTargetGroup(BuildTargetGroup.Android, icons);
  51. //设置闪屏Logo
  52. var logo = Resources.Load<Sprite>("UI/Sprite/Logo/logo_new");
  53. var screenLogo = PlayerSettings.SplashScreenLogo.Create(2, logo);
  54. PlayerSettings.SplashScreen.logos = new PlayerSettings.SplashScreenLogo[] { screenLogo };
  55. //打包APK
  56. BuildAndroid();
  57. }
  58.  
  59. //生成APK
  60. public static void BuildAndroid()
  61. {
  62. PlayerSettings.Android.keystorePass = "123456";
  63. PlayerSettings.Android.keyaliasPass = "123456";
  64.  
  65. List<string> levels = new List<string>();
  66. foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
  67. {
  68. if (!scene.enabled) continue;
  69. levels.Add(scene.path);
  70. }
  71. EditorUserBuildSettings.SwitchActiveBuildTarget(BuildTargetGroup.Android, BuildTarget.Android);
  72. BuildReport report = BuildPipeline.BuildPlayer(levels.ToArray(), "APK/MilitaryTopics.apk", BuildTarget.Android, BuildOptions.None);
  73. if (report.summary.result == BuildResult.Succeeded)
  74. Debug.Log("Build Succeeded");
  75. else
  76. Debug.LogErrorFormat("Build {0}", report.summary.result);
  77. }
  78. }


标签: Unity3d

Powered by emlog  蜀ICP备18021003号-1   sitemap

川公网安备 51019002001593号