GoogleMobileAdsSettings.cs 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using UnityEditor;
  5. using UnityEngine;
  6. namespace GoogleMobileAds.Editor
  7. {
  8. internal class GoogleMobileAdsSettings : ScriptableObject
  9. {
  10. private const string MobileAdsSettingsResDir = "Assets/GoogleMobileAds/Resources";
  11. private const string MobileAdsSettingsFile = "GoogleMobileAdsSettings";
  12. private const string MobileAdsSettingsFileExtension = ".asset";
  13. // Project-relative path of the settings asset.
  14. internal const string AssetPath =
  15. MobileAdsSettingsResDir + "/" + MobileAdsSettingsFile + MobileAdsSettingsFileExtension;
  16. public enum GmaAndroidSdk
  17. {
  18. Standard = 0,
  19. NextGen = 1
  20. }
  21. internal static GoogleMobileAdsSettings LoadInstance()
  22. {
  23. // Read from resources.
  24. var instance = Resources.Load<GoogleMobileAdsSettings>(MobileAdsSettingsFile);
  25. // Create instance if null.
  26. if (instance == null)
  27. {
  28. Directory.CreateDirectory(MobileAdsSettingsResDir);
  29. instance = ScriptableObject.CreateInstance<GoogleMobileAdsSettings>();
  30. string assetPath = Path.Combine(MobileAdsSettingsResDir,
  31. MobileAdsSettingsFile + MobileAdsSettingsFileExtension);
  32. AssetDatabase.CreateAsset(instance, assetPath);
  33. AssetDatabase.SaveAssets();
  34. }
  35. return instance;
  36. }
  37. [SerializeField]
  38. private string adMobAndroidAppId = string.Empty;
  39. [SerializeField]
  40. private string adMobIOSAppId = string.Empty;
  41. [SerializeField]
  42. private bool enableKotlinXCoroutinesPackagingOption = true;
  43. [SerializeField]
  44. private bool enableGradleBuildPreProcessor = true;
  45. [SerializeField]
  46. private bool disableOptimizeInitialization;
  47. [SerializeField]
  48. private bool disableOptimizeAdLoading;
  49. [SerializeField]
  50. private string userTrackingUsageDescription;
  51. [SerializeField]
  52. private string userLanguage = "en";
  53. [SerializeField]
  54. private bool overrideDefaultGmaAndroidSdk = false;
  55. [SerializeField]
  56. private int selectedGmaAndroidSdk = 0;
  57. // The EDM opt-out depends on `enableExternalDependencyManager` and `edmPackageDetected`
  58. // persisting in the settings asset, which is shared through version control and is not
  59. // shipped in the `.unitypackage`. If they are lost or reset, `EdmDependencyInstaller` treats
  60. // the project as a first-time import and adds EDM back, undoing the publisher's removal.
  61. //
  62. // When true, the plugin installs and uses Unity's External Dependency Manager package.
  63. // Disabled automatically when the publisher removes the package after it was installed.
  64. [SerializeField]
  65. private bool enableExternalDependencyManager = true;
  66. // Whether Unity's External Dependency Manager package has been detected in this project.
  67. // Used to tell a publisher removal apart from a first-time import.
  68. [SerializeField]
  69. private bool edmPackageDetected;
  70. // The version of EDM that the plugin most recently added to this project. If the plugin
  71. // requires a different version, it adds EDM again at that version.
  72. [SerializeField]
  73. private string addedEdmVersion;
  74. [SerializeField]
  75. private int debugGeography = 0;
  76. [SerializeField]
  77. private List<string> testDeviceHashedIds = new List<string>();
  78. public string GoogleMobileAdsAndroidAppId
  79. {
  80. get { return adMobAndroidAppId; }
  81. set { adMobAndroidAppId = value; }
  82. }
  83. public bool EnableGradleBuildPreProcessor
  84. {
  85. get { return enableGradleBuildPreProcessor; }
  86. set { enableGradleBuildPreProcessor = value; }
  87. }
  88. public bool EnableKotlinXCoroutinesPackagingOption
  89. {
  90. get { return enableKotlinXCoroutinesPackagingOption; }
  91. set { enableKotlinXCoroutinesPackagingOption = value; }
  92. }
  93. public string GoogleMobileAdsIOSAppId
  94. {
  95. get { return adMobIOSAppId; }
  96. set { adMobIOSAppId = value; }
  97. }
  98. public bool DisableOptimizeInitialization
  99. {
  100. get { return disableOptimizeInitialization; }
  101. set { disableOptimizeInitialization = value; }
  102. }
  103. public bool DisableOptimizeAdLoading
  104. {
  105. get { return disableOptimizeAdLoading; }
  106. set { disableOptimizeAdLoading = value; }
  107. }
  108. public string UserTrackingUsageDescription
  109. {
  110. get { return userTrackingUsageDescription; }
  111. set { userTrackingUsageDescription = value; }
  112. }
  113. public string UserLanguage
  114. {
  115. get { return userLanguage; }
  116. set { userLanguage = value; }
  117. }
  118. public bool OverrideDefaultGmaAndroidSdk
  119. {
  120. get { return overrideDefaultGmaAndroidSdk; }
  121. set { overrideDefaultGmaAndroidSdk = value; }
  122. }
  123. public int SelectedGmaAndroidSdk
  124. {
  125. get { return selectedGmaAndroidSdk; }
  126. set { selectedGmaAndroidSdk = value; }
  127. }
  128. public bool EnableExternalDependencyManager
  129. {
  130. get { return enableExternalDependencyManager; }
  131. set { enableExternalDependencyManager = value; }
  132. }
  133. public bool EdmPackageDetected
  134. {
  135. get { return edmPackageDetected; }
  136. set { edmPackageDetected = value; }
  137. }
  138. public string AddedEdmVersion
  139. {
  140. get { return addedEdmVersion; }
  141. set { addedEdmVersion = value; }
  142. }
  143. public int DebugGeography
  144. {
  145. get { return debugGeography; }
  146. set { debugGeography = value; }
  147. }
  148. public List<string> TestDeviceHashedIds
  149. {
  150. get { return testDeviceHashedIds ?? (testDeviceHashedIds = new List<string>()); }
  151. set { testDeviceHashedIds = value ?? new List<string>(); }
  152. }
  153. /// <summary>
  154. /// Returns the active GMA Android SDK architecture.
  155. /// This property is decoupled from the stored value to allow easily switching the default
  156. /// to Next-Gen in the next phase of migration for users who haven't overridden the default.
  157. /// </summary>
  158. public GmaAndroidSdk EffectiveGmaAndroidSdk
  159. {
  160. get
  161. {
  162. if (overrideDefaultGmaAndroidSdk)
  163. {
  164. return (GmaAndroidSdk)selectedGmaAndroidSdk;
  165. }
  166. return GmaAndroidSdk.Standard;
  167. }
  168. }
  169. }
  170. }