AppLovinSettings.cs 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. //
  2. // AppLovinSettings.cs
  3. // AppLovin MAX Unity Plugin
  4. //
  5. // Created by Santosh Bagadi on 1/27/20.
  6. // Copyright © 2019 AppLovin. All rights reserved.
  7. //
  8. using AppLovinMax.Scripts.IntegrationManager.Editor;
  9. using System.IO;
  10. using UnityEditor;
  11. using UnityEngine;
  12. using UnityEngine.Serialization;
  13. /// <summary>
  14. /// A <see cref="ScriptableObject"/> representing the AppLovin Settings that can be set in the Integration Manager Window.
  15. ///
  16. /// The scriptable object asset is created with the name <c>AppLovinSettings.asset</c> and is placed under the directory <c>Assets/MaxSdk/Resources</c>.
  17. ///
  18. /// NOTE: Not name spacing this class since it is reflected upon by the Google adapter and will break compatibility.
  19. /// </summary>
  20. public class AppLovinSettings : ScriptableObject
  21. {
  22. private const string SettingsExportPath = "MaxSdk/Resources/AppLovinSettings.asset";
  23. private static AppLovinSettings _instance;
  24. [SerializeField] private bool qualityServiceEnabled = true;
  25. [SerializeField] private string sdkKey;
  26. [SerializeField] private bool setAttributionReportEndpoint;
  27. [SerializeField] private string customGradleVersionUrl;
  28. [SerializeField] private string customGradleToolsVersion;
  29. [SerializeField] private string adMobAndroidAppId = string.Empty;
  30. [SerializeField] private string adMobIosAppId = string.Empty;
  31. /// <summary>
  32. /// An instance of AppLovin Setting.
  33. /// </summary>
  34. public static AppLovinSettings Instance
  35. {
  36. get
  37. {
  38. if (_instance == null)
  39. {
  40. // Check for an existing AppLovinSettings somewhere in the project
  41. var guids = AssetDatabase.FindAssets("AppLovinSettings t:ScriptableObject");
  42. if (guids.Length > 1)
  43. {
  44. MaxSdkLogger.UserWarning("Multiple AppLovinSettings found. This may cause unexpected results.");
  45. }
  46. if (guids.Length != 0)
  47. {
  48. var path = AssetDatabase.GUIDToAssetPath(guids[0]);
  49. _instance = AssetDatabase.LoadAssetAtPath<AppLovinSettings>(path);
  50. return _instance;
  51. }
  52. // If there is no existing AppLovinSettings asset, create one in the default location
  53. string settingsFilePath;
  54. // The settings file should be under the Assets/ folder so that it can be version controlled and cannot be overriden when updating.
  55. // If the plugin is outside the Assets folder, create the settings asset at the default location.
  56. if (AppLovinIntegrationManager.IsPluginInPackageManager)
  57. {
  58. // Note: Can't use absolute path when calling `CreateAsset`. Should use relative path to Assets/ directory.
  59. settingsFilePath = Path.Combine("Assets", SettingsExportPath);
  60. var maxSdkDir = Path.Combine(Application.dataPath, "MaxSdk");
  61. if (!Directory.Exists(maxSdkDir))
  62. {
  63. Directory.CreateDirectory(maxSdkDir);
  64. }
  65. }
  66. else
  67. {
  68. settingsFilePath = Path.Combine(AppLovinIntegrationManager.PluginParentDirectory, SettingsExportPath);
  69. }
  70. var settingsDir = Path.GetDirectoryName(settingsFilePath);
  71. if (!Directory.Exists(settingsDir))
  72. {
  73. Directory.CreateDirectory(settingsDir);
  74. }
  75. // On script reload AssetDatabase.FindAssets() can fail and will overwrite AppLovinSettings without this check
  76. if (!File.Exists(settingsFilePath))
  77. {
  78. _instance = CreateInstance<AppLovinSettings>();
  79. AssetDatabase.CreateAsset(_instance, settingsFilePath);
  80. MaxSdkLogger.D("Creating new AppLovinSettings asset at path: " + settingsFilePath);
  81. }
  82. }
  83. return _instance;
  84. }
  85. }
  86. /// <summary>
  87. /// Whether or not to install Quality Service plugin.
  88. /// </summary>
  89. public bool QualityServiceEnabled
  90. {
  91. get { return Instance.qualityServiceEnabled; }
  92. set { Instance.qualityServiceEnabled = value; }
  93. }
  94. /// <summary>
  95. /// AppLovin SDK Key.
  96. /// </summary>
  97. public string SdkKey
  98. {
  99. get { return Instance.sdkKey; }
  100. set { Instance.sdkKey = value; }
  101. }
  102. /// <summary>
  103. /// Whether or not to set `NSAdvertisingAttributionReportEndpoint` in Info.plist.
  104. /// </summary>
  105. public bool SetAttributionReportEndpoint
  106. {
  107. get { return Instance.setAttributionReportEndpoint; }
  108. set { Instance.setAttributionReportEndpoint = value; }
  109. }
  110. /// <summary>
  111. /// A URL to set the distributionUrl in the gradle-wrapper.properties file (ex: https\://services.gradle.org/distributions/gradle-6.9.3-bin.zip)
  112. /// </summary>
  113. public string CustomGradleVersionUrl
  114. {
  115. get { return Instance.customGradleVersionUrl; }
  116. set { Instance.customGradleVersionUrl = value; }
  117. }
  118. /// <summary>
  119. /// A string to set the custom gradle tools version (ex: com.android.tools.build:gradle:4.2.0)
  120. /// </summary>
  121. public string CustomGradleToolsVersion
  122. {
  123. get { return Instance.customGradleToolsVersion; }
  124. set { Instance.customGradleToolsVersion = value; }
  125. }
  126. /// <summary>
  127. /// AdMob Android App ID.
  128. /// </summary>
  129. public string AdMobAndroidAppId
  130. {
  131. get { return Instance.adMobAndroidAppId; }
  132. set { Instance.adMobAndroidAppId = value; }
  133. }
  134. /// <summary>
  135. /// AdMob iOS App ID.
  136. /// </summary>
  137. public string AdMobIosAppId
  138. {
  139. get { return Instance.adMobIosAppId; }
  140. set { Instance.adMobIosAppId = value; }
  141. }
  142. /// <summary>
  143. /// Saves the instance of the settings.
  144. /// </summary>
  145. public void SaveAsync()
  146. {
  147. EditorUtility.SetDirty(_instance);
  148. }
  149. }