You've already forked Commercialization.topon
160 lines
5.7 KiB
C#
160 lines
5.7 KiB
C#
#if UNITY_EDITOR
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Runtime.ADAggregator;
|
|
using UnityEditor;
|
|
using UnityEditor.SceneManagement;
|
|
using UnityEngine;
|
|
|
|
public static class IAAAdDebugSampleCreator
|
|
{
|
|
private const string SampleRoot = "Assets/Samples/IAAAdDebugSample";
|
|
private const string SampleSceneDirectory = SampleRoot + "/Scenes";
|
|
private const string SampleConfigDirectory = SampleRoot + "/Configs";
|
|
private const string SampleScenePath = SampleSceneDirectory + "/IAAAdDebugSample.unity";
|
|
private const string SampleConfigPath = SampleConfigDirectory + "/IAAAdDebugSampleConfig.asset";
|
|
|
|
[MenuItem("Topon/Create IAA IMGUI Debug Sample")]
|
|
public static void CreateOrUpdateSample()
|
|
{
|
|
EnsureDirectory(SampleRoot);
|
|
EnsureDirectory(SampleSceneDirectory);
|
|
EnsureDirectory(SampleConfigDirectory);
|
|
|
|
var config = LoadOrCreateConfig();
|
|
CreateOrUpdateScene(config);
|
|
AppendSceneToBuildSettings(SampleScenePath);
|
|
|
|
AssetDatabase.SaveAssets();
|
|
AssetDatabase.Refresh();
|
|
EditorUtility.DisplayDialog(
|
|
"IAA Sample Created",
|
|
$"Scene: {SampleScenePath}\nConfig: {SampleConfigPath}",
|
|
"OK");
|
|
}
|
|
|
|
public static void CreateOrUpdateSampleInBatchMode()
|
|
{
|
|
CreateOrUpdateSample();
|
|
EditorApplication.Exit(0);
|
|
}
|
|
|
|
private static ADConfig LoadOrCreateConfig()
|
|
{
|
|
var config = AssetDatabase.LoadAssetAtPath<ADConfig>(SampleConfigPath);
|
|
if (config == null)
|
|
{
|
|
config = ScriptableObject.CreateInstance<ADConfig>();
|
|
AssetDatabase.CreateAsset(config, SampleConfigPath);
|
|
}
|
|
|
|
config.ConfigName = "IAA Ad Debug Sample";
|
|
config.Id = string.IsNullOrWhiteSpace(config.Id) ? "fill_taku_app_id" : config.Id;
|
|
config.Key = string.IsNullOrWhiteSpace(config.Key) ? "fill_taku_app_key" : config.Key;
|
|
config.Key2 = string.IsNullOrWhiteSpace(config.Key2) ? string.Empty : config.Key2;
|
|
config.BaseAwardAdKeyValue = config.BaseAwardAdKeyValue ?? new AdKeyValue();
|
|
config.BaseAwardAdKeyValue.key = "rewarded";
|
|
config.BaseAwardAdKeyValue.value = string.IsNullOrWhiteSpace(config.BaseAwardAdKeyValue.value)
|
|
? "fill_rewarded_placement"
|
|
: config.BaseAwardAdKeyValue.value;
|
|
|
|
config.BaseInteractionAdKeyValue = config.BaseInteractionAdKeyValue ?? new AdKeyValue();
|
|
config.BaseInteractionAdKeyValue.key = "interstitial";
|
|
config.BaseInteractionAdKeyValue.value = string.IsNullOrWhiteSpace(config.BaseInteractionAdKeyValue.value)
|
|
? "fill_interstitial_placement"
|
|
: config.BaseInteractionAdKeyValue.value;
|
|
|
|
config.BaseSplashAdKeyValue = config.BaseSplashAdKeyValue ?? new AdKeyValue();
|
|
config.BaseSplashAdKeyValue.key = "splash";
|
|
config.BaseSplashAdKeyValue.value = string.IsNullOrWhiteSpace(config.BaseSplashAdKeyValue.value)
|
|
? "optional_splash_placement"
|
|
: config.BaseSplashAdKeyValue.value;
|
|
|
|
config.CommonKeyValues ??= new List<AdKeyValue>();
|
|
SetOrAddCommonKey(config, "topon.rewarded_auto_load", "true");
|
|
SetOrAddCommonKey(config, "topon.rewarded_prewarm_on_init", "true");
|
|
SetOrAddCommonKey(config, "topon.rewarded_max_load_attempts", "3");
|
|
SetOrAddCommonKey(config, "topon.rewarded_load_retry_delay_ms", "1000");
|
|
SetOrAddCommonKey(config, "topon.interstitial_auto_load", "true");
|
|
SetOrAddCommonKey(config, "topon.interstitial_prewarm_on_init", "true");
|
|
SetOrAddCommonKey(config, "topon.interstitial_max_load_attempts", "2");
|
|
SetOrAddCommonKey(config, "topon.interstitial_load_retry_delay_ms", "500");
|
|
|
|
EditorUtility.SetDirty(config);
|
|
return config;
|
|
}
|
|
|
|
private static void CreateOrUpdateScene(ADConfig config)
|
|
{
|
|
var scene = EditorSceneManager.NewScene(NewSceneSetup.DefaultGameObjects, NewSceneMode.Single);
|
|
scene.name = "IAAAdDebugSample";
|
|
|
|
var root = new GameObject("IAA Ad Debug Sample");
|
|
var gui = root.AddComponent<IAAAdDebugSampleGui>();
|
|
gui.adConfig = config;
|
|
gui.userId = "debug_user_001";
|
|
gui.rewardedScenario = "reward_debug";
|
|
gui.interstitialScenario = "interstitial_debug";
|
|
gui.autoInitialize = true;
|
|
gui.forcePortrait = true;
|
|
gui.captureUnityLogs = true;
|
|
gui.showVerboseState = true;
|
|
|
|
EditorSceneManager.SaveScene(scene, SampleScenePath);
|
|
}
|
|
|
|
private static void AppendSceneToBuildSettings(string scenePath)
|
|
{
|
|
var scenes = new List<EditorBuildSettingsScene>(EditorBuildSettings.scenes);
|
|
var exists = false;
|
|
for (var i = 0; i < scenes.Count; i++)
|
|
{
|
|
if (scenes[i].path != scenePath)
|
|
{
|
|
continue;
|
|
}
|
|
|
|
scenes[i] = new EditorBuildSettingsScene(scenePath, true);
|
|
exists = true;
|
|
break;
|
|
}
|
|
|
|
if (!exists)
|
|
{
|
|
scenes.Add(new EditorBuildSettingsScene(scenePath, true));
|
|
}
|
|
|
|
EditorBuildSettings.scenes = scenes.ToArray();
|
|
}
|
|
|
|
private static void SetOrAddCommonKey(ADConfig config, string key, string value)
|
|
{
|
|
foreach (var item in config.CommonKeyValues)
|
|
{
|
|
if (item != null && item.key == key)
|
|
{
|
|
item.value = value;
|
|
return;
|
|
}
|
|
}
|
|
|
|
config.CommonKeyValues.Add(new AdKeyValue
|
|
{
|
|
key = key,
|
|
value = value
|
|
});
|
|
}
|
|
|
|
private static void EnsureDirectory(string assetPath)
|
|
{
|
|
if (AssetDatabase.IsValidFolder(assetPath))
|
|
{
|
|
return;
|
|
}
|
|
|
|
Directory.CreateDirectory(Path.GetFullPath(assetPath));
|
|
AssetDatabase.Refresh();
|
|
}
|
|
}
|
|
#endif
|