Nenhuma descrição
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

SamsungAndroidProviderBuildProcess.cs 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. using System;
  2. using System.IO;
  3. using System.Linq;
  4. using UnityEditor;
  5. using UnityEditor.Android;
  6. using UnityEditor.Build;
  7. using UnityEditor.Build.Reporting;
  8. using UnityEngine;
  9. using UnityEngine.AdaptivePerformance;
  10. using UnityEditor.AdaptivePerformance.Editor;
  11. using UnityEngine.AdaptivePerformance.Samsung.Android;
  12. namespace UnityEditor.AdaptivePerformance.Samsung.Android.Editor
  13. {
  14. /// <summary>
  15. /// The Samsung Android provider build processor ensures that any custom configuration that the user creates is
  16. /// correctly passed on to the provider implementation at runtime.
  17. ///
  18. /// Custom configuration instances that are stored in EditorBuildSettings are not copied to the target build
  19. /// because they are considered unreferenced assets. To get them to the runtime, they must
  20. /// be serialized to the built app and deserialized at runtime. Previously, this as a manual process
  21. /// that required the implementor to manually serialize to some location that can then be read from to deserialize
  22. /// at runtime. With the new PlayerSettings Preloaded Assets API, you can now add your asset to the preloaded
  23. /// list and have it be instantiated at app launch.
  24. ///
  25. /// **Note**: Preloaded assets are only notified with Awake, so anything you want or need to do with the
  26. /// asset after launch needs to be handled in the Samsung Android provider build process.
  27. ///
  28. /// For more information about the APIs used, see:
  29. /// * <see href="https://docs.unity3d.com/ScriptReference/EditorBuildSettings.html">EditorBuildSettings</see>
  30. /// * <see href="https://docs.unity3d.com/ScriptReference/PlayerSettings.GetPreloadedAssets.html">PlayerSettings.GetPreloadedAssets</see>
  31. /// * <see href="https://docs.unity3d.com/ScriptReference/PlayerSettings.SetPreloadedAssets.html">PlayerSettings.SetPreloadedAssets</see>
  32. /// * <see href="https://docs.unity3d.com/ScriptReference/Android.IPostGenerateGradleAndroidProject.html">IPostGenerateGradleAndroidProject</see>
  33. /// </summary>
  34. public class SamsungAndroidProviderBuildProcess : IPreprocessBuildWithReport, IPostprocessBuildWithReport, IPostGenerateGradleAndroidProject
  35. {
  36. /// <summary>
  37. /// Override of <see cref="IPreprocessBuildWithReport"/> and <see cref="IPostprocessBuildWithReport"/>.
  38. /// </summary>
  39. public int callbackOrder
  40. {
  41. get { return 0; }
  42. }
  43. /// <summary>
  44. /// Clears out settings which could be left over from previous unsuccessfull runs.
  45. /// </summary>
  46. void CleanOldSettings()
  47. {
  48. UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();
  49. if (preloadedAssets == null)
  50. return;
  51. var oldSettings = from s in preloadedAssets
  52. where s != null && s.GetType() == typeof(SamsungAndroidProviderSettings)
  53. select s;
  54. if (oldSettings != null && oldSettings.Any())
  55. {
  56. var assets = preloadedAssets.ToList();
  57. foreach (var s in oldSettings)
  58. {
  59. assets.Remove(s);
  60. }
  61. PlayerSettings.SetPreloadedAssets(assets.ToArray());
  62. }
  63. }
  64. /// <summary>
  65. /// Override of <see cref="IPreprocessBuildWithReport"/>.
  66. /// </summary>
  67. /// <param name="report">Build report.</param>
  68. public void OnPreprocessBuild(BuildReport report)
  69. {
  70. // Always remember to clean up preloaded assets after build to make sure we don't
  71. // dirty later builds with assets that may not be needed or are out of date.
  72. CleanOldSettings();
  73. SamsungAndroidProviderSettings settings = null;
  74. EditorBuildSettings.TryGetConfigObject(SamsungAndroidProviderConstants.k_SettingsKey, out settings);
  75. if (settings == null)
  76. return;
  77. UnityEngine.Object[] preloadedAssets = PlayerSettings.GetPreloadedAssets();
  78. if (!preloadedAssets.Contains(settings))
  79. {
  80. var assets = preloadedAssets.ToList();
  81. assets.Add(settings);
  82. PlayerSettings.SetPreloadedAssets(assets.ToArray());
  83. }
  84. }
  85. /// <summary>Override of <see cref="IPostprocessBuildWithReport"/></summary>.
  86. /// <param name="report">Build report.</param>
  87. public void OnPostprocessBuild(BuildReport report)
  88. {
  89. // Always remember to clean up preloaded assets after build to make sure we don't
  90. // dirty later builds with assets that may not be needed or are out of date.
  91. CleanOldSettings();
  92. }
  93. /// <summary>
  94. /// Implementation of <see cref="IPostGenerateGradleAndroidProject"/>
  95. /// </summary>
  96. /// <param name="path"></param>
  97. public void OnPostGenerateGradleAndroidProject(string path)
  98. {
  99. var setting = AdaptivePerformanceBuildUtils.GetWantedStartupBoostSetting(SamsungAndroidProviderSettings.GetSettings());
  100. AdaptivePerformanceBuildUtils.UpdateBootConfigBoostSetting(path, "adaptive-performance-samsung-boost-launch", setting);
  101. }
  102. }
  103. }