2026-04-20 13:49:36 +08:00
//
// 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
{
2026-05-08 11:03:00 +08:00
private const string SettingsExportPath = "MaxSdk/Resources/AppLovinSettings.asset" ;
2026-04-20 13:49:36 +08:00
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 ;
}
string settingsFilePath ;
// The settings file should be under the Assets/ folder so that it can be version controlled and cannot be overriden when updating.
2026-05-08 11:03:00 +08:00
// If the plugin is outside the Assets folder or if there is no existing AppLovinSettings asset, create the settings asset at the default location.
2026-04-20 13:49:36 +08:00
if ( AppLovinIntegrationManager . IsPluginInPackageManager )
{
2026-05-08 11:03:00 +08:00
// Note: Can't use absolute path when calling `CreateAsset`. Should use path relative to Assets/ directory.
settingsFilePath = MaxSdkUtils . NormalizeToUnityPath ( Path . Combine ( "Assets" , SettingsExportPath ) ) ;
2026-04-20 13:49:36 +08:00
2026-05-08 11:03:00 +08:00
var maxSdkDir = MaxSdkUtils . NormalizeToUnityPath ( Path . Combine ( Application . dataPath , "MaxSdk" ) ) ;
2026-04-20 13:49:36 +08:00
if ( ! Directory . Exists ( maxSdkDir ) )
{
Directory . CreateDirectory ( maxSdkDir ) ;
}
}
else
{
2026-05-08 11:03:00 +08:00
settingsFilePath = MaxSdkUtils . NormalizeToUnityPath ( Path . Combine ( AppLovinIntegrationManager . PluginParentDirectory , SettingsExportPath ) ) ;
2026-04-20 13:49:36 +08:00
}
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 ) ;
}
}