142 lines
4.3 KiB
C#
142 lines
4.3 KiB
C#
//
|
|
// 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;
|
|
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 = "ProjectSettings/Packages/com.bywaystudios.applovin/AppLovinSettings.json";
|
|
|
|
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) return instance;
|
|
|
|
instance = CreateInstance<AppLovinSettings>();
|
|
|
|
var projectRootPath = Path.GetDirectoryName(Application.dataPath);
|
|
var settingsFilePath = Path.Combine(projectRootPath, SettingsExportPath);
|
|
if (!File.Exists(settingsFilePath))
|
|
{
|
|
instance.SaveAsync();
|
|
return instance;
|
|
}
|
|
|
|
var settingsJson = File.ReadAllText(settingsFilePath);
|
|
if (string.IsNullOrEmpty(settingsJson))
|
|
{
|
|
instance.SaveAsync();
|
|
return instance;
|
|
}
|
|
|
|
JsonUtility.FromJsonOverwrite(settingsJson, instance);
|
|
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()
|
|
{
|
|
var settingsJson = JsonUtility.ToJson(instance);
|
|
try
|
|
{
|
|
var projectRootPath = Path.GetDirectoryName(Application.dataPath);
|
|
var settingsFilePath = Path.Combine(projectRootPath, SettingsExportPath);
|
|
File.WriteAllText(settingsFilePath, settingsJson);
|
|
}
|
|
catch (Exception exception)
|
|
{
|
|
MaxSdkLogger.UserError("Failed to save settings.");
|
|
Console.WriteLine(exception);
|
|
}
|
|
}
|
|
}
|