123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160 |
- //
- // AppLovinSettings.cs
- // AppLovin MAX Unity Plugin
- //
- // Created by Santosh Bagadi on 1/27/20.
- // Copyright © 2019 AppLovin. All rights reserved.
- //
- using AppLovinMax.Scripts.IntegrationManager.Editor;
- using System.IO;
- using UnityEditor;
- using UnityEngine;
- using UnityEngine.Serialization;
- /// <summary>
- /// A <see cref="ScriptableObject"/> representing the AppLovin Settings that can be set in the Integration Manager Window.
- ///
- /// The scriptable object asset is created with the name <c>AppLovinSettings.asset</c> and is placed under the directory <c>Assets/MaxSdk/Resources</c>.
- ///
- /// NOTE: Not name spacing this class since it is reflected upon by the Google adapter and will break compatibility.
- /// </summary>
- public class AppLovinSettings : ScriptableObject
- {
- private const string SettingsExportPath = "MaxSdk/Resources/AppLovinSettings.asset";
- private static AppLovinSettings _instance;
- [SerializeField] private bool qualityServiceEnabled = true;
- [SerializeField] private string sdkKey;
- [SerializeField] private string customGradleVersionUrl;
- [SerializeField] private string customGradleToolsVersion;
- [SerializeField] private string adMobAndroidAppId = string.Empty;
- [SerializeField] private string adMobIosAppId = string.Empty;
- /// <summary>
- /// An instance of AppLovin Setting.
- /// </summary>
- public static AppLovinSettings Instance
- {
- get
- {
- if (_instance == null)
- {
- // Check for an existing AppLovinSettings somewhere in the project
- var guids = AssetDatabase.FindAssets("AppLovinSettings t:ScriptableObject");
- if (guids.Length > 1)
- {
- MaxSdkLogger.UserWarning("Multiple AppLovinSettings found. This may cause unexpected results.");
- }
- if (guids.Length != 0)
- {
- var path = AssetDatabase.GUIDToAssetPath(guids[0]);
- _instance = AssetDatabase.LoadAssetAtPath<AppLovinSettings>(path);
- return _instance;
- }
- // If there is no existing AppLovinSettings asset, create one in the default location
- string settingsFilePath;
- // The settings file should be under the Assets/ folder so that it can be version controlled and cannot be overriden when updating.
- // If the plugin is outside the Assets folder, create the settings asset at the default location.
- if (AppLovinIntegrationManager.IsPluginInPackageManager)
- {
- // Note: Can't use absolute path when calling `CreateAsset`. Should use relative path to Assets/ directory.
- settingsFilePath = Path.Combine("Assets", SettingsExportPath);
- var maxSdkDir = Path.Combine(Application.dataPath, "MaxSdk");
- if (!Directory.Exists(maxSdkDir))
- {
- Directory.CreateDirectory(maxSdkDir);
- }
- }
- else
- {
- settingsFilePath = Path.Combine(AppLovinIntegrationManager.PluginParentDirectory, SettingsExportPath);
- }
- var settingsDir = Path.GetDirectoryName(settingsFilePath);
- if (!Directory.Exists(settingsDir))
- {
- Directory.CreateDirectory(settingsDir);
- }
- // On script reload AssetDatabase.FindAssets() can fail and will overwrite AppLovinSettings without this check
- if (!File.Exists(settingsFilePath))
- {
- _instance = CreateInstance<AppLovinSettings>();
- AssetDatabase.CreateAsset(_instance, settingsFilePath);
- MaxSdkLogger.D("Creating new AppLovinSettings asset at path: " + settingsFilePath);
- }
- }
- return _instance;
- }
- }
- /// <summary>
- /// Whether or not to install Quality Service plugin.
- /// </summary>
- public bool QualityServiceEnabled
- {
- get { return Instance.qualityServiceEnabled; }
- set { Instance.qualityServiceEnabled = value; }
- }
- /// <summary>
- /// AppLovin SDK Key.
- /// </summary>
- public string SdkKey
- {
- get { return Instance.sdkKey; }
- set { Instance.sdkKey = value; }
- }
- /// <summary>
- /// A URL to set the distributionUrl in the gradle-wrapper.properties file (ex: https\://services.gradle.org/distributions/gradle-6.9.3-bin.zip)
- /// </summary>
- public string CustomGradleVersionUrl
- {
- get { return Instance.customGradleVersionUrl; }
- set { Instance.customGradleVersionUrl = value; }
- }
- /// <summary>
- /// A string to set the custom gradle tools version (ex: com.android.tools.build:gradle:4.2.0)
- /// </summary>
- public string CustomGradleToolsVersion
- {
- get { return Instance.customGradleToolsVersion; }
- set { Instance.customGradleToolsVersion = value; }
- }
- /// <summary>
- /// AdMob Android App ID.
- /// </summary>
- public string AdMobAndroidAppId
- {
- get { return Instance.adMobAndroidAppId; }
- set { Instance.adMobAndroidAppId = value; }
- }
- /// <summary>
- /// AdMob iOS App ID.
- /// </summary>
- public string AdMobIosAppId
- {
- get { return Instance.adMobIosAppId; }
- set { Instance.adMobIosAppId = value; }
- }
- /// <summary>
- /// Saves the instance of the settings.
- /// </summary>
- public void SaveAsync()
- {
- EditorUtility.SetDirty(_instance);
- }
- }
|