AppLovinSettings.cs 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 string customGradleVersionUrl;
  27. [SerializeField] private string customGradleToolsVersion;
  28. [SerializeField] private string adMobAndroidAppId = string.Empty;
  29. [SerializeField] private string adMobIosAppId = string.Empty;
  30. /// <summary>
  31. /// An instance of AppLovin Setting.
  32. /// </summary>
  33. public static AppLovinSettings Instance
  34. {
  35. get
  36. {
  37. if (_instance == null)
  38. {
  39. // Check for an existing AppLovinSettings somewhere in the project
  40. var guids = AssetDatabase.FindAssets("AppLovinSettings t:ScriptableObject");
  41. if (guids.Length > 1)
  42. {
  43. MaxSdkLogger.UserWarning("Multiple AppLovinSettings found. This may cause unexpected results.");
  44. }
  45. if (guids.Length != 0)
  46. {
  47. var path = AssetDatabase.GUIDToAssetPath(guids[0]);
  48. _instance = AssetDatabase.LoadAssetAtPath<AppLovinSettings>(path);
  49. return _instance;
  50. }
  51. // If there is no existing AppLovinSettings asset, create one in the default location
  52. string settingsFilePath;
  53. // The settings file should be under the Assets/ folder so that it can be version controlled and cannot be overriden when updating.
  54. // If the plugin is outside the Assets folder, create the settings asset at the default location.
  55. if (AppLovinIntegrationManager.IsPluginInPackageManager)
  56. {
  57. // Note: Can't use absolute path when calling `CreateAsset`. Should use relative path to Assets/ directory.
  58. settingsFilePath = Path.Combine("Assets", SettingsExportPath);
  59. var maxSdkDir = Path.Combine(Application.dataPath, "MaxSdk");
  60. if (!Directory.Exists(maxSdkDir))
  61. {
  62. Directory.CreateDirectory(maxSdkDir);
  63. }
  64. }
  65. else
  66. {
  67. settingsFilePath = Path.Combine(AppLovinIntegrationManager.PluginParentDirectory, SettingsExportPath);
  68. }
  69. var settingsDir = Path.GetDirectoryName(settingsFilePath);
  70. if (!Directory.Exists(settingsDir))
  71. {
  72. Directory.CreateDirectory(settingsDir);
  73. }
  74. // On script reload AssetDatabase.FindAssets() can fail and will overwrite AppLovinSettings without this check
  75. if (!File.Exists(settingsFilePath))
  76. {
  77. _instance = CreateInstance<AppLovinSettings>();
  78. AssetDatabase.CreateAsset(_instance, settingsFilePath);
  79. MaxSdkLogger.D("Creating new AppLovinSettings asset at path: " + settingsFilePath);
  80. }
  81. }
  82. return _instance;
  83. }
  84. }
  85. /// <summary>
  86. /// Whether or not to install Quality Service plugin.
  87. /// </summary>
  88. public bool QualityServiceEnabled
  89. {
  90. get { return Instance.qualityServiceEnabled; }
  91. set { Instance.qualityServiceEnabled = value; }
  92. }
  93. /// <summary>
  94. /// AppLovin SDK Key.
  95. /// </summary>
  96. public string SdkKey
  97. {
  98. get { return Instance.sdkKey; }
  99. set { Instance.sdkKey = value; }
  100. }
  101. /// <summary>
  102. /// A URL to set the distributionUrl in the gradle-wrapper.properties file (ex: https\://services.gradle.org/distributions/gradle-6.9.3-bin.zip)
  103. /// </summary>
  104. public string CustomGradleVersionUrl
  105. {
  106. get { return Instance.customGradleVersionUrl; }
  107. set { Instance.customGradleVersionUrl = value; }
  108. }
  109. /// <summary>
  110. /// A string to set the custom gradle tools version (ex: com.android.tools.build:gradle:4.2.0)
  111. /// </summary>
  112. public string CustomGradleToolsVersion
  113. {
  114. get { return Instance.customGradleToolsVersion; }
  115. set { Instance.customGradleToolsVersion = value; }
  116. }
  117. /// <summary>
  118. /// AdMob Android App ID.
  119. /// </summary>
  120. public string AdMobAndroidAppId
  121. {
  122. get { return Instance.adMobAndroidAppId; }
  123. set { Instance.adMobAndroidAppId = value; }
  124. }
  125. /// <summary>
  126. /// AdMob iOS App ID.
  127. /// </summary>
  128. public string AdMobIosAppId
  129. {
  130. get { return Instance.adMobIosAppId; }
  131. set { Instance.adMobIosAppId = value; }
  132. }
  133. /// <summary>
  134. /// Saves the instance of the settings.
  135. /// </summary>
  136. public void SaveAsync()
  137. {
  138. EditorUtility.SetDirty(_instance);
  139. }
  140. }