// // 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; namespace AppLovinMax.Scripts.IntegrationManager.Editor { public enum Platform { All, Android, iOS } } /// /// A representing the AppLovin Settings that can be set in the Integration Manager Window. /// /// The scriptable object asset is created with the name AppLovinSettings.asset and is placed under the directory Assets/MaxSdk/Resources. /// /// NOTE: Not name spacing this class since it is reflected upon by the Google adapter and will break compatibility. /// public class AppLovinSettings : ScriptableObject { public const string SettingsExportPath = "MaxSdk/Resources/AppLovinSettings.asset"; public const string DefaultUserTrackingDescriptionEnV0 = "Pressing \\\"Allow\\\" uses device info for more relevant ad content"; public const string DefaultUserTrackingDescriptionEnV1 = "This only uses device info for less annoying, more relevant ads"; public const string DefaultUserTrackingDescriptionEnV2 = "This only uses device info for more interesting and relevant ads"; public const string DefaultUserTrackingDescriptionEnV3 = "This uses device info for more personalized ads and content"; public const string DefaultUserTrackingDescriptionDe = "\\\"Erlauben\\\" drücken benutzt Gerätinformationen für relevantere Werbeinhalte"; public const string DefaultUserTrackingDescriptionEs = "Presionando \\\"Permitir\\\", se usa la información del dispositivo para obtener contenido publicitario más relevante"; public const string DefaultUserTrackingDescriptionFr = "\\\"Autoriser\\\" permet d'utiliser les infos du téléphone pour afficher des contenus publicitaires plus pertinents"; public const string DefaultUserTrackingDescriptionJa = "\\\"許可\\\"をクリックすることで、デバイス情報を元により最適な広告を表示することができます"; public const string DefaultUserTrackingDescriptionKo = "\\\"허용\\\"을 누르면 더 관련성 높은 광고 콘텐츠를 제공하기 위해 기기 정보가 사용됩니다"; public const string DefaultUserTrackingDescriptionZhHans = "点击\\\"允许\\\"以使用设备信息获得更加相关的广告内容"; public const string DefaultUserTrackingDescriptionZhHant = "點擊\\\"允許\\\"以使用設備信息獲得更加相關的廣告內容"; /// /// A placeholder constant to be replaced with the actual default localization or an empty string based on whether or not localization is enabled when when the getter is called. /// protected const string DefaultLocalization = "default_localization"; private static AppLovinSettings instance; [SerializeField] private bool qualityServiceEnabled = true; [SerializeField] private string sdkKey; [SerializeField] private bool setAttributionReportEndpoint; [SerializeField] private bool addApsSkAdNetworkIds; [SerializeField] private string customGradleVersionUrl; [SerializeField] private string customGradleToolsVersion; [SerializeField] private bool consentFlowEnabled; [SerializeField] private Platform consentFlowPlatform; [SerializeField] private string consentFlowPrivacyPolicyUrl = string.Empty; [SerializeField] private string consentFlowTermsOfServiceUrl = string.Empty; [FormerlySerializedAs("userTrackingUsageDescription")] [SerializeField] private string userTrackingUsageDescriptionEn = string.Empty; [SerializeField] private bool userTrackingUsageLocalizationEnabled; [SerializeField] private string userTrackingUsageDescriptionDe = string.Empty; [SerializeField] private string userTrackingUsageDescriptionEs = string.Empty; [SerializeField] private string userTrackingUsageDescriptionFr = string.Empty; [SerializeField] private string userTrackingUsageDescriptionJa = string.Empty; [SerializeField] private string userTrackingUsageDescriptionKo = string.Empty; [SerializeField] private string userTrackingUsageDescriptionZhHans = string.Empty; [SerializeField] private string userTrackingUsageDescriptionZhHant = DefaultLocalization; [SerializeField] private string adMobAndroidAppId = string.Empty; [SerializeField] private string adMobIosAppId = string.Empty; [SerializeField] private bool showInternalSettingsInIntegrationManager; /// /// An instance of AppLovin Setting. /// 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(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.IsPluginOutsideAssetsDirectory) { // 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(); AssetDatabase.CreateAsset(instance, settingsFilePath); MaxSdkLogger.D("Creating new AppLovinSettings asset at path: " + settingsFilePath); } } return instance; } } /// /// Whether or not to install Quality Service plugin. /// public bool QualityServiceEnabled { get { return Instance.qualityServiceEnabled; } set { Instance.qualityServiceEnabled = value; } } /// /// AppLovin SDK Key. /// public string SdkKey { get { return Instance.sdkKey; } set { Instance.sdkKey = value; } } /// /// Whether or not to set `NSAdvertisingAttributionReportEndpoint` in Info.plist. /// public bool SetAttributionReportEndpoint { get { return Instance.setAttributionReportEndpoint; } set { Instance.setAttributionReportEndpoint = value; } } /// /// Whether or not to add Amazon Publisher Services SKAdNetworkID's. /// public bool AddApsSkAdNetworkIds { get { return Instance.addApsSkAdNetworkIds; } set { Instance.addApsSkAdNetworkIds = value; } } /// /// A URL to set the distributionUrl in the gradle-wrapper.properties file (ex: https\://services.gradle.org/distributions/gradle-6.9.3-bin.zip) /// public string CustomGradleVersionUrl { get { return Instance.customGradleVersionUrl; } set { Instance.customGradleVersionUrl = value; } } /// /// A string to set the custom gradle tools version (ex: com.android.tools.build:gradle:4.2.0) /// public string CustomGradleToolsVersion { get { return Instance.customGradleToolsVersion; } set { Instance.customGradleToolsVersion = value; } } /// /// Whether or not AppLovin Consent Flow is enabled. /// public bool ConsentFlowEnabled { get { // Update the default EN description if an old version of the description is still being used. if (DefaultUserTrackingDescriptionEnV0.Equals(Instance.UserTrackingUsageDescriptionEn) || DefaultUserTrackingDescriptionEnV1.Equals(Instance.UserTrackingUsageDescriptionEn) || DefaultUserTrackingDescriptionEnV2.Equals(Instance.UserTrackingUsageDescriptionEn)) { Instance.UserTrackingUsageDescriptionEn = DefaultUserTrackingDescriptionEnV3; } return Instance.consentFlowEnabled; } set { var previousValue = Instance.consentFlowEnabled; Instance.consentFlowEnabled = value; if (value) { // If the value didn't change, we don't need to update anything. if (previousValue) return; Instance.UserTrackingUsageDescriptionEn = DefaultUserTrackingDescriptionEnV3; Instance.UserTrackingUsageLocalizationEnabled = true; } else { Instance.ConsentFlowPlatform = Platform.All; Instance.ConsentFlowPrivacyPolicyUrl = string.Empty; Instance.ConsentFlowTermsOfServiceUrl = string.Empty; Instance.UserTrackingUsageDescriptionEn = string.Empty; Instance.UserTrackingUsageLocalizationEnabled = false; } } } public Platform ConsentFlowPlatform { get { return Instance.consentFlowEnabled ? Instance.consentFlowPlatform : Platform.All; } set { Instance.consentFlowPlatform = value; } } /// /// A URL pointing to the Privacy Policy for the app to be shown when prompting the user for consent. /// public string ConsentFlowPrivacyPolicyUrl { get { return Instance.consentFlowPrivacyPolicyUrl; } set { Instance.consentFlowPrivacyPolicyUrl = value; } } /// /// An optional URL pointing to the Terms of Service for the app to be shown when prompting the user for consent. /// public string ConsentFlowTermsOfServiceUrl { get { return Instance.consentFlowTermsOfServiceUrl; } set { Instance.consentFlowTermsOfServiceUrl = value; } } /// /// A User Tracking Usage Description in English to be shown to users when requesting permission to use data for tracking. /// For more information see Apple's documentation. /// public string UserTrackingUsageDescriptionEn { get { return Instance.userTrackingUsageDescriptionEn; } set { Instance.userTrackingUsageDescriptionEn = value; } } /// /// Whether or not to localize User Tracking Usage Description. /// For more information see Apple's documentation. /// public bool UserTrackingUsageLocalizationEnabled { get { return Instance.userTrackingUsageLocalizationEnabled; } set { var previousValue = Instance.userTrackingUsageLocalizationEnabled; Instance.userTrackingUsageLocalizationEnabled = value; if (value) { // If the value didn't change or the english localization text is not the default one, we don't need to update anything. if (previousValue || !DefaultUserTrackingDescriptionEnV3.Equals(Instance.UserTrackingUsageDescriptionEn)) return; Instance.UserTrackingUsageDescriptionDe = DefaultUserTrackingDescriptionDe; Instance.UserTrackingUsageDescriptionEs = DefaultUserTrackingDescriptionEs; Instance.UserTrackingUsageDescriptionFr = DefaultUserTrackingDescriptionFr; Instance.UserTrackingUsageDescriptionJa = DefaultUserTrackingDescriptionJa; Instance.UserTrackingUsageDescriptionKo = DefaultUserTrackingDescriptionKo; Instance.UserTrackingUsageDescriptionZhHans = DefaultUserTrackingDescriptionZhHans; Instance.UserTrackingUsageDescriptionZhHant = DefaultUserTrackingDescriptionZhHant; } else { Instance.UserTrackingUsageDescriptionDe = string.Empty; Instance.UserTrackingUsageDescriptionEs = string.Empty; Instance.UserTrackingUsageDescriptionFr = string.Empty; Instance.UserTrackingUsageDescriptionJa = string.Empty; Instance.UserTrackingUsageDescriptionKo = string.Empty; Instance.UserTrackingUsageDescriptionZhHans = string.Empty; Instance.UserTrackingUsageDescriptionZhHant = string.Empty; } } } /// /// A User Tracking Usage Description in German to be shown to users when requesting permission to use data for tracking. /// For more information see Apple's documentation. /// public string UserTrackingUsageDescriptionDe { get { return Instance.userTrackingUsageDescriptionDe; } set { Instance.userTrackingUsageDescriptionDe = value; } } /// /// A User Tracking Usage Description in Spanish to be shown to users when requesting permission to use data for tracking. /// For more information see Apple's documentation. /// public string UserTrackingUsageDescriptionEs { get { return Instance.userTrackingUsageDescriptionEs; } set { Instance.userTrackingUsageDescriptionEs = value; } } /// /// A User Tracking Usage Description in French to be shown to users when requesting permission to use data for tracking. /// For more information see Apple's documentation. /// public string UserTrackingUsageDescriptionFr { get { return Instance.userTrackingUsageDescriptionFr; } set { Instance.userTrackingUsageDescriptionFr = value; } } /// /// A User Tracking Usage Description in Japanese to be shown to users when requesting permission to use data for tracking. /// For more information see Apple's documentation. /// public string UserTrackingUsageDescriptionJa { get { return Instance.userTrackingUsageDescriptionJa; } set { Instance.userTrackingUsageDescriptionJa = value; } } /// /// A User Tracking Usage Description in Korean to be shown to users when requesting permission to use data for tracking. /// For more information see Apple's documentation. /// public string UserTrackingUsageDescriptionKo { get { return Instance.userTrackingUsageDescriptionKo; } set { Instance.userTrackingUsageDescriptionKo = value; } } /// /// A User Tracking Usage Description in Chinese (Simplified) to be shown to users when requesting permission to use data for tracking. /// For more information see Apple's documentation. /// public string UserTrackingUsageDescriptionZhHans { get { return Instance.userTrackingUsageDescriptionZhHans; } set { Instance.userTrackingUsageDescriptionZhHans = value; } } /// /// A User Tracking Usage Description in Chinese (Traditional) to be shown to users when requesting permission to use data for tracking. /// For more information see Apple's documentation. /// public string UserTrackingUsageDescriptionZhHant { get { // Since this localization has been added separate from the other localizations, // we use a placeholder constant to be replaced with the actual value or an empty string based on whether or not the localization was enabled by the publisher. if (DefaultLocalization.Equals(Instance.userTrackingUsageDescriptionZhHant)) { Instance.userTrackingUsageDescriptionZhHant = Instance.UserTrackingUsageLocalizationEnabled ? DefaultUserTrackingDescriptionZhHant : string.Empty; } return Instance.userTrackingUsageDescriptionZhHant; } set { Instance.userTrackingUsageDescriptionZhHant = value; } } /// /// AdMob Android App ID. /// public string AdMobAndroidAppId { get { return Instance.adMobAndroidAppId; } set { Instance.adMobAndroidAppId = value; } } /// /// AdMob iOS App ID. /// public string AdMobIosAppId { get { return Instance.adMobIosAppId; } set { Instance.adMobIosAppId = value; } } public bool ShowInternalSettingsInIntegrationManager { get { return Instance.showInternalSettingsInIntegrationManager; } set { Instance.showInternalSettingsInIntegrationManager = value; } } /// /// Saves the instance of the settings. /// public void SaveAsync() { EditorUtility.SetDirty(instance); } }