GoogleMobileAdsSettingsEditor.cs 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246
  1. #if UNITY_6000_0_OR_NEWER || UNITY_2023 || UNITY_2022 || UNITY_2021_3_55 || UNITY_2021_3_54 || UNITY_2021_3_53 || UNITY_2021_3_52 || UNITY_2021_3_51 || UNITY_2021_3_50 || UNITY_2021_3_49 || UNITY_2021_3_48 || UNITY_2021_3_47 || UNITY_2021_3_46 || UNITY_2021_3_45 || UNITY_2021_3_44 || UNITY_2021_3_43 || UNITY_2021_3_42 || UNITY_2021_3_41
  2. #define ANDROID_GRADLE_BUILD_PRE_PROCESSOR_ENABLED
  3. #endif
  4. using System;
  5. using UnityEditor;
  6. using UnityEngine;
  7. namespace GoogleMobileAds.Editor
  8. {
  9. [InitializeOnLoad]
  10. [CustomEditor(typeof(GoogleMobileAdsSettings))]
  11. public class GoogleMobileAdsSettingsEditor : UnityEditor.Editor
  12. {
  13. SerializedProperty _appIdAndroid;
  14. SerializedProperty _appIdiOS;
  15. SerializedProperty _enableGradleBuildPreProcessor;
  16. SerializedProperty _enableKotlinXCoroutinesPackagingOption;
  17. SerializedProperty _disableOptimizeInitialization;
  18. SerializedProperty _disableOptimizeAdLoading;
  19. SerializedProperty _userLanguage;
  20. SerializedProperty _userTrackingUsageDescription;
  21. SerializedProperty _overrideDefaultGmaAndroidSdk;
  22. SerializedProperty _gmaAndroidSdk;
  23. // Using an ordered list of languages is computationally expensive when trying to create an
  24. // array out of them for purposes of showing a dropdown menu. Care should be taken to ensure
  25. // these arrays are kept in sync.
  26. string[] availableLanguages = new string[] { "English", "French"};
  27. string[] languageCodes = new string[] { "en", "fr" };
  28. int selectedIndex = 0;
  29. [MenuItem("Assets/Google Mobile Ads/Settings...")]
  30. public static void OpenInspector()
  31. {
  32. Selection.activeObject = GoogleMobileAdsSettings.LoadInstance();
  33. }
  34. [MenuItem("Assets/Google Mobile Ads/Access documentation")]
  35. public static void AccessDocumentation()
  36. {
  37. Application.OpenURL("https://developers.google.com/admob/unity/quick-start");
  38. }
  39. [MenuItem("Assets/Google Mobile Ads/Raise an issue")]
  40. public static void RaiseAnIssue()
  41. {
  42. Application.OpenURL("https://support.google.com/admob/contact/contact_us_gma_sdk");
  43. }
  44. public void OnEnable()
  45. {
  46. _appIdAndroid = serializedObject.FindProperty("adMobAndroidAppId");
  47. _appIdiOS = serializedObject.FindProperty("adMobIOSAppId");
  48. _overrideDefaultGmaAndroidSdk = serializedObject.FindProperty("overrideDefaultGmaAndroidSdk");
  49. _gmaAndroidSdk = serializedObject.FindProperty("selectedGmaAndroidSdk");
  50. _enableGradleBuildPreProcessor =
  51. serializedObject.FindProperty("enableGradleBuildPreProcessor");
  52. _enableKotlinXCoroutinesPackagingOption =
  53. serializedObject.FindProperty("enableKotlinXCoroutinesPackagingOption");
  54. _disableOptimizeInitialization = serializedObject.FindProperty("disableOptimizeInitialization");
  55. _disableOptimizeAdLoading = serializedObject.FindProperty("disableOptimizeAdLoading");
  56. _userLanguage = serializedObject.FindProperty("userLanguage");
  57. _userTrackingUsageDescription =
  58. serializedObject.FindProperty("userTrackingUsageDescription");
  59. selectedIndex = Array.IndexOf(languageCodes, _userLanguage.stringValue);
  60. selectedIndex = selectedIndex >= 0 ? selectedIndex : 0;
  61. }
  62. public override void OnInspectorGUI()
  63. {
  64. // Make sure the Settings object has all recent changes.
  65. serializedObject.Update();
  66. var settings = (GoogleMobileAdsSettings)target;
  67. if (settings == null)
  68. {
  69. UnityEngine.Debug.LogError("GoogleMobileAdsSettings is null.");
  70. return;
  71. }
  72. EditorLocalization localization = new EditorLocalization();
  73. EditorGUI.BeginChangeCheck();
  74. selectedIndex = EditorGUILayout.Popup("Language", selectedIndex, availableLanguages);
  75. if (EditorGUI.EndChangeCheck())
  76. {
  77. _userLanguage.stringValue = languageCodes[selectedIndex];
  78. }
  79. EditorGUIUtility.labelWidth = 60.0f;
  80. EditorGUILayout.LabelField(localization.ForKey("GMA_APP_ID_LABEL"),
  81. EditorStyles.boldLabel);
  82. EditorGUI.indentLevel++;
  83. EditorGUILayout.PropertyField(_appIdAndroid, new GUIContent("Android"));
  84. EditorGUILayout.PropertyField(_appIdiOS, new GUIContent("iOS"));
  85. EditorGUILayout.HelpBox(localization.ForKey("GMA_APP_ID_HELPBOX"), MessageType.Info);
  86. EditorGUI.indentLevel--;
  87. EditorGUILayout.Separator();
  88. EditorGUIUtility.labelWidth = 325.0f;
  89. EditorGUILayout.LabelField(localization.ForKey("ANDROID_SETTINGS_LABEL"),
  90. EditorStyles.boldLabel);
  91. EditorGUI.indentLevel++;
  92. var activeArch = settings.EffectiveGmaAndroidSdk;
  93. string activeArchStr = activeArch == GoogleMobileAdsSettings.GmaAndroidSdk.Standard
  94. ? localization.ForKey("GMA_ANDROID_SDK_STANDARD")
  95. : localization.ForKey("GMA_ANDROID_SDK_NEXT_GEN");
  96. GUIStyle richLabelStyle = new GUIStyle(EditorStyles.label);
  97. richLabelStyle.richText = true;
  98. EditorGUILayout.LabelField(
  99. localization.ForKey("ACTIVE_ARCHITECTURE_LABEL") + "<b>" + activeArchStr + "</b>",
  100. richLabelStyle);
  101. EditorGUILayout.PropertyField(
  102. _overrideDefaultGmaAndroidSdk,
  103. new GUIContent(localization.ForKey("OVERRIDE_DEFAULT_GMA_ANDROID_ARCHITECTURE_SETTING")));
  104. if (!_overrideDefaultGmaAndroidSdk.boolValue)
  105. {
  106. EditorGUILayout.LabelField(localization.ForKey("OVERRIDE_DEFAULT_GMA_ANDROID_ARCHITECTURE_DESCRIPTION"), EditorStyles.wordWrappedMiniLabel);
  107. }
  108. EditorGUI.BeginDisabledGroup(!_overrideDefaultGmaAndroidSdk.boolValue);
  109. EditorGUI.indentLevel++;
  110. int currentSelected = _gmaAndroidSdk.intValue;
  111. if (!_overrideDefaultGmaAndroidSdk.boolValue)
  112. {
  113. // Force to Standard when disabled.
  114. currentSelected = (int)GoogleMobileAdsSettings.GmaAndroidSdk.Standard;
  115. }
  116. GUIStyle radioStyle = new GUIStyle(EditorStyles.radioButton);
  117. radioStyle.padding.left += 10;
  118. // Standard Radio Button
  119. EditorGUILayout.BeginHorizontal();
  120. GUILayout.Space(EditorGUI.indentLevel * 15); // Manually apply indentation
  121. if (GUILayout.Toggle(currentSelected == (int)GoogleMobileAdsSettings.GmaAndroidSdk.Standard,
  122. localization.ForKey("GMA_ANDROID_SDK_STANDARD_OPTION"), radioStyle))
  123. {
  124. currentSelected = (int)GoogleMobileAdsSettings.GmaAndroidSdk.Standard;
  125. }
  126. EditorGUILayout.EndHorizontal();
  127. // Next Gen Radio Button
  128. EditorGUILayout.BeginHorizontal();
  129. GUILayout.Space(EditorGUI.indentLevel * 15); // Manually apply indentation
  130. if (GUILayout.Toggle(currentSelected == (int)GoogleMobileAdsSettings.GmaAndroidSdk.NextGen,
  131. localization.ForKey("GMA_ANDROID_SDK_NEXT_GEN_OPTION"), radioStyle))
  132. {
  133. currentSelected = (int)GoogleMobileAdsSettings.GmaAndroidSdk.NextGen;
  134. }
  135. EditorGUILayout.EndHorizontal();
  136. if (_overrideDefaultGmaAndroidSdk.boolValue)
  137. {
  138. _gmaAndroidSdk.intValue = currentSelected;
  139. }
  140. else
  141. {
  142. _gmaAndroidSdk.intValue = (int)GoogleMobileAdsSettings.GmaAndroidSdk.Standard;
  143. }
  144. EditorGUI.indentLevel--;
  145. EditorGUI.EndDisabledGroup();
  146. EditorGUILayout.Separator();
  147. EditorGUI.BeginChangeCheck();
  148. #if ANDROID_GRADLE_BUILD_PRE_PROCESSOR_ENABLED
  149. EditorGUILayout.PropertyField(
  150. _enableGradleBuildPreProcessor,
  151. new GUIContent(
  152. localization.ForKey("ENABLE_GRADLE_BUILD_PRE_PROCESSOR_SETTING")));
  153. if (settings.EnableGradleBuildPreProcessor)
  154. {
  155. EditorGUILayout.HelpBox(
  156. localization.ForKey("ENABLE_GRADLE_BUILD_PRE_PROCESSOR_HELPBOX"),
  157. MessageType.Info);
  158. }
  159. #endif
  160. EditorGUILayout.PropertyField(
  161. _enableKotlinXCoroutinesPackagingOption,
  162. new GUIContent(
  163. localization.ForKey("ENABLE_KOTLINX_COROUTINES_PACKAGING_OPTION_SETTING")));
  164. if (settings.EnableKotlinXCoroutinesPackagingOption)
  165. {
  166. EditorGUILayout.HelpBox(
  167. localization.ForKey("ENABLE_KOTLINX_COROUTINES_PACKAGING_OPTION_HELPBOX"),
  168. MessageType.Info);
  169. }
  170. EditorGUILayout.PropertyField(
  171. _disableOptimizeInitialization,
  172. new GUIContent(localization.ForKey("DISABLE_OPTIMIZE_INITIALIZATION_SETTING")));
  173. if (settings.DisableOptimizeInitialization)
  174. {
  175. EditorGUILayout.HelpBox(localization.ForKey("DISABLE_OPTIMIZE_INITIALIZATION_HELPBOX"),
  176. MessageType.Info);
  177. }
  178. EditorGUILayout.PropertyField(
  179. _disableOptimizeAdLoading,
  180. new GUIContent(localization.ForKey("DISABLE_OPTIMIZE_AD_LOADING_SETTING")));
  181. if (settings.DisableOptimizeAdLoading)
  182. {
  183. EditorGUILayout.HelpBox(localization.ForKey("DISABLE_OPTIMIZE_AD_LOADING_HELPBOX"),
  184. MessageType.Info);
  185. }
  186. EditorGUI.indentLevel--;
  187. EditorGUILayout.Separator();
  188. EditorGUIUtility.labelWidth = 300.0f;
  189. EditorGUILayout.LabelField(localization.ForKey("UMP_SPECIFIC_SETTINGS_LABEL"),
  190. EditorStyles.boldLabel);
  191. EditorGUI.indentLevel++;
  192. EditorGUILayout.PropertyField(
  193. _userTrackingUsageDescription,
  194. new GUIContent(localization.ForKey("USER_TRACKING_USAGE_DESCRIPTION_SETTING")));
  195. EditorGUILayout.HelpBox(localization.ForKey("USER_TRACKING_USAGE_DESCRIPTION_HELPBOX"),
  196. MessageType.Info);
  197. EditorGUI.indentLevel--;
  198. EditorGUILayout.Separator();
  199. serializedObject.ApplyModifiedProperties();
  200. }
  201. }
  202. }