You've already forked Commercialization.topon
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d653b06c8d | |||
| 9d431c66b6 | |||
| f29e06e3c5 |
@@ -10,6 +10,9 @@ namespace AnyThinkAds
|
||||
{
|
||||
public class ATAdsClientFactory
|
||||
{
|
||||
private static IATInterstitialAdClient _sharedInterstitialAdClient;
|
||||
private static IATRewardedVideoAdClient _sharedRewardedVideoAdClient;
|
||||
|
||||
public static IATBannerAdClient BuildBannerAdClient()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
@@ -27,17 +30,25 @@ namespace AnyThinkAds
|
||||
|
||||
public static IATInterstitialAdClient BuildInterstitialAdClient()
|
||||
{
|
||||
if (_sharedInterstitialAdClient != null)
|
||||
{
|
||||
return _sharedInterstitialAdClient;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Testing UNITY_EDITOR first because the editor also responds to the currently
|
||||
// selected platform.
|
||||
#elif UNITY_ANDROID
|
||||
return new AnyThinkAds.Android.ATInterstitialAdClient();
|
||||
_sharedInterstitialAdClient = new AnyThinkAds.Android.ATInterstitialAdClient();
|
||||
return _sharedInterstitialAdClient;
|
||||
#elif (UNITY_5 && UNITY_IOS) || UNITY_IPHONE
|
||||
return new AnyThinkAds.iOS.ATInterstitialAdClient();
|
||||
_sharedInterstitialAdClient = new AnyThinkAds.iOS.ATInterstitialAdClient();
|
||||
return _sharedInterstitialAdClient;
|
||||
#else
|
||||
|
||||
#endif
|
||||
return new UnityInterstitialClient();
|
||||
_sharedInterstitialAdClient = new UnityInterstitialClient();
|
||||
return _sharedInterstitialAdClient;
|
||||
}
|
||||
|
||||
public static IATNativeAdClient BuildNativeAdClient()
|
||||
@@ -72,18 +83,26 @@ namespace AnyThinkAds
|
||||
|
||||
public static IATRewardedVideoAdClient BuildRewardedVideoAdClient()
|
||||
{
|
||||
if (_sharedRewardedVideoAdClient != null)
|
||||
{
|
||||
return _sharedRewardedVideoAdClient;
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Testing UNITY_EDITOR first because the editor also responds to the currently
|
||||
// selected platform.
|
||||
|
||||
#elif UNITY_ANDROID
|
||||
return new AnyThinkAds.Android.ATRewardedVideoAdClient();
|
||||
_sharedRewardedVideoAdClient = new AnyThinkAds.Android.ATRewardedVideoAdClient();
|
||||
return _sharedRewardedVideoAdClient;
|
||||
#elif (UNITY_5 && UNITY_IOS) || UNITY_IPHONE
|
||||
return new AnyThinkAds.iOS.ATRewardedVideoAdClient();
|
||||
_sharedRewardedVideoAdClient = new AnyThinkAds.iOS.ATRewardedVideoAdClient();
|
||||
return _sharedRewardedVideoAdClient;
|
||||
#else
|
||||
|
||||
#endif
|
||||
return new UnityRewardedVideoAdClient();
|
||||
_sharedRewardedVideoAdClient = new UnityRewardedVideoAdClient();
|
||||
return _sharedRewardedVideoAdClient;
|
||||
}
|
||||
|
||||
public static IATSDKAPIClient BuildSDKAPIClient()
|
||||
|
||||
@@ -156,7 +156,7 @@ namespace AnyThinkAds.Android
|
||||
}catch(System.Exception e){
|
||||
System.Console.WriteLine("Exception caught: {0}", e);
|
||||
Debug.Log ("ATInterstitialAdClient : error."+e.Message);
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -403,6 +403,7 @@ namespace AnyThinkAds.Android
|
||||
{
|
||||
System.Console.WriteLine("Exception caught: {0}", e);
|
||||
Debug.Log("Unity: ATInterstitialAdClient:showAutoAd() : error." + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -160,7 +160,7 @@ namespace AnyThinkAds.Android
|
||||
}catch(System.Exception e){
|
||||
System.Console.WriteLine("Exception caught: {0}", e);
|
||||
Debug.Log ("ATRewardedVideoAdClient : error."+e.Message);
|
||||
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -390,6 +390,7 @@ namespace AnyThinkAds.Android
|
||||
{
|
||||
System.Console.WriteLine("Exception caught: {0}", e);
|
||||
Debug.Log("Unity: ATRewardedVideoAdClient:showAutoAd() : error." + e.Message);
|
||||
throw;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
21
CHANGELOG.md
21
CHANGELOG.md
@@ -1,3 +1,23 @@
|
||||
# [1.4.9]
|
||||
|
||||
### 新增
|
||||
|
||||
* 示例改为 `Samples~` 可选导入内容,业务项目默认引用主包时不再自动带入 sample 菜单和调试场景。
|
||||
|
||||
### 修复
|
||||
|
||||
* 重构激励视频与插屏展示阶段状态机,补齐 `show/showAutoAd` 同步异常后的失败收口,避免卡死在播放前遮罩。
|
||||
* 按官方语义调整激励视频生命周期:奖励回调只记录奖励结果,关闭回调统一完成会话结算。
|
||||
* 去除广告源级失败对主链的误判,`AdSource` 加载/竞价失败不再错误打断播放器流程。
|
||||
|
||||
# [1.4.8]
|
||||
|
||||
### 修复
|
||||
|
||||
* 统一奖励视频与插屏的 manual/auto 底层 client 回调源,修复自动加载模式下生命周期回调丢失问题。
|
||||
* 修复奖励视频播放结束后 `mask` 未正常关闭的问题。
|
||||
* 修复插屏成功关闭时误触发 `GLOBAL_ShowAwardVideoComplete` 的问题。
|
||||
|
||||
# [1.4.7]
|
||||
|
||||
### 新增
|
||||
@@ -11,4 +31,3 @@
|
||||
* 激励和插屏切换为更稳的自动加载/预热策略,补强首次播放容错。
|
||||
* 修复插屏关闭、展示失败和播放失败回调链不完整的问题。
|
||||
* 调整 debug 行为:`topon.debug=true` 仅开启日志,不再自动弹出官方 DebugUI。
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e61f19774db0d2c4489400341a504c1f
|
||||
guid: 6a68c48c5f3f3b747973e6acc508080e
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
@@ -1,10 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.unity3d.player"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<application tools:replace="android:networkSecurityConfig">
|
||||
<!--这个设置主要是为了适配9.0以上的机器(必须使用)-->
|
||||
<uses-library android:name="org.apache.http.legacy" android:required="false" />
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -1,29 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<manifest
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="com.unity3d.player"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:installLocation="preferExternal">
|
||||
<supports-screens
|
||||
android:smallScreens="true"
|
||||
android:normalScreens="true"
|
||||
android:largeScreens="true"
|
||||
android:xlargeScreens="true"
|
||||
android:anyDensity="true"/>
|
||||
|
||||
<application android:label="@string/app_name"
|
||||
android:icon="@mipmap/app_icon">
|
||||
|
||||
<provider
|
||||
android:name="com.bytedance.sdk.openadsdk.TTFileProvider"
|
||||
android:authorities="${applicationId}.TTFileProvider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true"
|
||||
tools:replace="android:authorities">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/alex_tt_file_path" />
|
||||
</provider>
|
||||
|
||||
</application>
|
||||
</manifest>
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1c49d887d5952a944a51f93410b4c40c
|
||||
TextScriptImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,29 +0,0 @@
|
||||
allprojects {
|
||||
buildscript {
|
||||
repositories {**ARTIFACTORYREPOSITORY**
|
||||
google()
|
||||
jcenter()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// If you are changing the Android Gradle Plugin version, make sure it is compatible with the Gradle version preinstalled with Unity
|
||||
// See which Gradle version is preinstalled with Unity here https://docs.unity3d.com/Manual/android-gradle-overview.html
|
||||
// See official Gradle and Android Gradle Plugin compatibility table here https://developer.android.com/studio/releases/gradle-plugin#updating-gradle
|
||||
// To specify a custom Gradle version in Unity, go do "Preferences > External Tools", uncheck "Gradle Installed with Unity (recommended)" and specify a path to a custom Gradle version
|
||||
classpath 'com.android.tools.build:gradle:4.0.1'
|
||||
**BUILD_SCRIPT_DEPS**
|
||||
}
|
||||
}
|
||||
|
||||
repositories {**ARTIFACTORYREPOSITORY**
|
||||
google()
|
||||
jcenter()
|
||||
flatDir {
|
||||
dirs "${project(':unityLibrary').projectDir}/libs"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
task clean(type: Delete) {
|
||||
delete rootProject.buildDir
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: bbc875056594cf9438be790ffcde5a38
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,5 +0,0 @@
|
||||
org.gradle.jvmargs=-Xmx**JVM_HEAP_SIZE**M
|
||||
org.gradle.parallel=true
|
||||
android.enableR8=**MINIFY_WITH_R_EIGHT**
|
||||
unityStreamingAssets=**STREAMING_ASSETS**
|
||||
**ADDITIONAL_PROPERTIES**
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6850df6d809fd9a4e8a58c0061503168
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,61 +0,0 @@
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
dependencies {
|
||||
implementation project(':unityLibrary')
|
||||
}
|
||||
|
||||
android {
|
||||
compileSdkVersion **APIVERSION**
|
||||
buildToolsVersion '**BUILDTOOLS**'
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion **MINSDKVERSION**
|
||||
targetSdkVersion **TARGETSDKVERSION**
|
||||
applicationId '**APPLICATIONID**'
|
||||
ndk {
|
||||
abiFilters **ABIFILTERS**
|
||||
}
|
||||
versionCode **VERSIONCODE**
|
||||
versionName '**VERSIONNAME**'
|
||||
|
||||
multiDexEnabled true //添加此配置,是为了当代码行数超过64k的时候设置的
|
||||
}
|
||||
|
||||
aaptOptions {
|
||||
noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')
|
||||
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
|
||||
}**SIGN**
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
buildTypes {
|
||||
debug {
|
||||
minifyEnabled **MINIFY_DEBUG**
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
|
||||
jniDebuggable true
|
||||
}
|
||||
release {
|
||||
minifyEnabled **MINIFY_RELEASE**
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt')**SIGNCONFIG**
|
||||
}
|
||||
}**PACKAGING_OPTIONS****PLAY_ASSET_PACKS****SPLITS**
|
||||
**BUILT_APK_LOCATION**
|
||||
bundle {
|
||||
language {
|
||||
enableSplit = false
|
||||
}
|
||||
density {
|
||||
enableSplit = false
|
||||
}
|
||||
abi {
|
||||
enableSplit = true
|
||||
}
|
||||
}
|
||||
}**SPLITS_VERSION_CODE****LAUNCHER_SOURCE_BUILD_SETUP**
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: dbbfc9e2efadb8c43b6c710eeff4abd9
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,75 +0,0 @@
|
||||
// Android Resolver Repos Start
|
||||
([rootProject] + (rootProject.subprojects as List)).each { project ->
|
||||
project.repositories {
|
||||
def unityProjectPath = $/file:///**DIR_UNITYPROJECT**/$.replace("\\", "/")
|
||||
maven {
|
||||
url "https://maven.google.com"
|
||||
}
|
||||
maven {
|
||||
url "https://artifact.bytedance.com/repository/pangle" // Assets/AnyThinkAds/Plugins/Android/China/Editor/Gromore/Dependencies.xml:6
|
||||
}
|
||||
maven {
|
||||
url "https://jfrog.anythinktech.com/artifactory/debugger" // Assets/Topon_Adapter/Editor/ToponTestDependencies.xml:6
|
||||
}
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
}
|
||||
}
|
||||
// Android Resolver Repos End
|
||||
apply plugin: 'com.android.library'
|
||||
**APPLY_PLUGINS**
|
||||
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
// Android Resolver Dependencies Start
|
||||
implementation 'com.android.support:appcompat-v7:28.0.0' // Assets/AnyThinkAds/Plugins/Android/China/Editor/Dependencies.xml:3
|
||||
implementation 'com.anythink.sdk:debugger-ui:1.0.0' // Assets/Topon_Adapter/Editor/ToponTestDependencies.xml:8
|
||||
implementation 'com.pangle.cn:mediation-sdk:5.6.1.6' // Assets/AnyThinkAds/Plugins/Android/China/Editor/Gromore/Dependencies.xml:8
|
||||
implementation 'com.tencent.mm.opensdk:wechat-sdk-android:6.8.0' // Assets/Topon_Adapter/Editor/WXDependencies.xml:3
|
||||
// Android Resolver Dependencies End
|
||||
**DEPS**}
|
||||
|
||||
// Android Resolver Exclusions Start
|
||||
android {
|
||||
packagingOptions {
|
||||
exclude ('/lib/arm64-v8a/*' + '*')
|
||||
exclude ('/lib/armeabi/*' + '*')
|
||||
exclude ('/lib/mips/*' + '*')
|
||||
exclude ('/lib/mips64/*' + '*')
|
||||
exclude ('/lib/x86/*' + '*')
|
||||
exclude ('/lib/x86_64/*' + '*')
|
||||
}
|
||||
}
|
||||
// Android Resolver Exclusions End
|
||||
android {
|
||||
compileSdkVersion **APIVERSION**
|
||||
buildToolsVersion '**BUILDTOOLS**'
|
||||
|
||||
compileOptions {
|
||||
sourceCompatibility JavaVersion.VERSION_1_8
|
||||
targetCompatibility JavaVersion.VERSION_1_8
|
||||
}
|
||||
|
||||
defaultConfig {
|
||||
minSdkVersion **MINSDKVERSION**
|
||||
targetSdkVersion **TARGETSDKVERSION**
|
||||
ndk {
|
||||
abiFilters **ABIFILTERS**
|
||||
}
|
||||
versionCode **VERSIONCODE**
|
||||
versionName '**VERSIONNAME**'
|
||||
consumerProguardFiles 'proguard-unity.txt'**USER_PROGUARD**
|
||||
}
|
||||
|
||||
lintOptions {
|
||||
abortOnError false
|
||||
}
|
||||
|
||||
aaptOptions {
|
||||
noCompress = **BUILTIN_NOCOMPRESS** + unityStreamingAssets.tokenize(', ')
|
||||
ignoreAssetsPattern = "!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~"
|
||||
}**PACKAGING_OPTIONS**
|
||||
}**REPOSITORIES**
|
||||
**IL_CPP_BUILD_SETUP**
|
||||
**SOURCE_BUILD_SETUP**
|
||||
**EXTERNAL_SOURCES**
|
||||
@@ -1,7 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 47364f35dc20c164fab7f26e8a03dd67
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -40,6 +40,8 @@ public sealed class IAAAdDebugSampleGui : MonoBehaviour
|
||||
private GUIStyle _logStyle;
|
||||
private bool _rewardedReadyCache;
|
||||
private bool _interstitialReadyCache;
|
||||
private bool _maskOpen;
|
||||
private string _lastEventLog = "<none>";
|
||||
private string _rewardedStatusCache = "Not refreshed yet.";
|
||||
private string _interstitialStatusCache = "Not refreshed yet.";
|
||||
private float _nextStatusRefreshTime;
|
||||
@@ -168,6 +170,8 @@ public sealed class IAAAdDebugSampleGui : MonoBehaviour
|
||||
RefreshStatusCaches();
|
||||
GUILayout.Label($"Rewarded Ready: {_rewardedReadyCache}", _textStyle);
|
||||
GUILayout.Label($"Interstitial Ready: {_interstitialReadyCache}", _textStyle);
|
||||
GUILayout.Label($"Mask Open: {_maskOpen}", _textStyle);
|
||||
GUILayout.Label($"Last EventLog: {_lastEventLog}", _textStyle);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -376,7 +380,17 @@ public sealed class IAAAdDebugSampleGui : MonoBehaviour
|
||||
}
|
||||
|
||||
_initInvoked = true;
|
||||
var controller = new ToponAdController();
|
||||
var controller = new SampleToponAdController(
|
||||
onMaskChanged: isOpen =>
|
||||
{
|
||||
_maskOpen = isOpen;
|
||||
AppendLog($"Mask changed => open={isOpen}");
|
||||
},
|
||||
onEventLog: (eventTable, eventValue, eventMessage) =>
|
||||
{
|
||||
_lastEventLog = $"{eventTable}:{eventValue}:{eventMessage}";
|
||||
AppendLog($"EventLog => table={eventTable}, value={eventValue}, message={eventMessage}");
|
||||
});
|
||||
ADManager.Instance.Init(() =>
|
||||
{
|
||||
_initCallbackReceived = true;
|
||||
@@ -612,4 +626,39 @@ public sealed class IAAAdDebugSampleGui : MonoBehaviour
|
||||
richText = false
|
||||
};
|
||||
}
|
||||
|
||||
private sealed class SampleToponAdController : IAdController
|
||||
{
|
||||
private readonly ToponAdController _inner = new ToponAdController();
|
||||
private readonly Action<bool> _onMaskChanged;
|
||||
private readonly Action<string, string, string> _onEventLog;
|
||||
|
||||
public SampleToponAdController(Action<bool> onMaskChanged, Action<string, string, string> onEventLog)
|
||||
{
|
||||
_onMaskChanged = onMaskChanged;
|
||||
_onEventLog = onEventLog;
|
||||
}
|
||||
|
||||
public void Init(ADConfig adConfig, object[] args)
|
||||
{
|
||||
_inner.Init(adConfig, args);
|
||||
}
|
||||
|
||||
public ADPlayer CreateAdPlayer(AD_Type type)
|
||||
{
|
||||
return _inner.CreateAdPlayer(type);
|
||||
}
|
||||
|
||||
public void EventLog(string eventTable, string eventValue, string eventMessage = null)
|
||||
{
|
||||
_onEventLog?.Invoke(eventTable, eventValue, eventMessage);
|
||||
_inner.EventLog(eventTable, eventValue, eventMessage);
|
||||
}
|
||||
|
||||
public void SetMask(bool isOpen)
|
||||
{
|
||||
_onMaskChanged?.Invoke(isOpen);
|
||||
_inner.SetMask(isOpen);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,166 +0,0 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using UnityEditor;
|
||||
using UnityEditor.Build.Reporting;
|
||||
using UnityEngine;
|
||||
|
||||
public static class IAAAdAndroidBuild
|
||||
{
|
||||
private const string OutputDirectory = "Build/Android";
|
||||
private const string OutputApkPath = OutputDirectory + "/IAAAdDebugSample-starveg.apk";
|
||||
private const string KeystorePath = "Build/Android/keys/starveg-test.keystore";
|
||||
private const string KeystorePassword = "Foldcc123!";
|
||||
private const string KeyAliasName = "starvegtest";
|
||||
private const string PackageName = "com.foldcc.starveg";
|
||||
|
||||
[MenuItem("Topon/Build IAA Android Test APK")]
|
||||
public static void BuildAndroidTestApk()
|
||||
{
|
||||
EnsureBuildFolders();
|
||||
ConfigurePlayerSettings();
|
||||
var resolverState = CaptureResolverState();
|
||||
|
||||
try
|
||||
{
|
||||
ApplyBatchFriendlyResolverSettings();
|
||||
|
||||
var scenes = new[] { "Assets/Samples/IAAAdDebugSample/Scenes/IAAAdDebugSample.unity" };
|
||||
var options = new BuildPlayerOptions
|
||||
{
|
||||
scenes = scenes,
|
||||
target = BuildTarget.Android,
|
||||
locationPathName = OutputApkPath,
|
||||
options = BuildOptions.None
|
||||
};
|
||||
|
||||
var report = BuildPipeline.BuildPlayer(options);
|
||||
if (report.summary.result != BuildResult.Succeeded)
|
||||
{
|
||||
throw new Exception(
|
||||
$"Android APK build failed: {report.summary.result} ({report.summary.totalErrors} errors)");
|
||||
}
|
||||
|
||||
Debug.Log($"[IAA Build] APK generated: {Path.GetFullPath(OutputApkPath)}");
|
||||
}
|
||||
finally
|
||||
{
|
||||
RestoreResolverState(resolverState);
|
||||
}
|
||||
}
|
||||
|
||||
public static void BuildAndroidTestApkInBatchMode()
|
||||
{
|
||||
BuildAndroidTestApk();
|
||||
EditorApplication.Exit(0);
|
||||
}
|
||||
|
||||
private static void ConfigurePlayerSettings()
|
||||
{
|
||||
PlayerSettings.SetApplicationIdentifier(BuildTargetGroup.Android, PackageName);
|
||||
PlayerSettings.defaultInterfaceOrientation = UIOrientation.Portrait;
|
||||
PlayerSettings.Android.targetArchitectures = AndroidArchitecture.ARMv7 | AndroidArchitecture.ARM64;
|
||||
PlayerSettings.Android.useCustomKeystore = true;
|
||||
PlayerSettings.Android.keystoreName = Path.GetFullPath(KeystorePath);
|
||||
PlayerSettings.Android.keystorePass = KeystorePassword;
|
||||
PlayerSettings.Android.keyaliasName = KeyAliasName;
|
||||
PlayerSettings.Android.keyaliasPass = KeystorePassword;
|
||||
PlayerSettings.bundleVersion = string.IsNullOrWhiteSpace(PlayerSettings.bundleVersion)
|
||||
? "1.0.0"
|
||||
: PlayerSettings.bundleVersion;
|
||||
PlayerSettings.Android.bundleVersionCode = Mathf.Max(1, PlayerSettings.Android.bundleVersionCode);
|
||||
AssetDatabase.SaveAssets();
|
||||
}
|
||||
|
||||
private static void EnsureBuildFolders()
|
||||
{
|
||||
Directory.CreateDirectory(Path.GetFullPath(OutputDirectory));
|
||||
Directory.CreateDirectory(Path.GetFullPath(Path.GetDirectoryName(KeystorePath) ?? OutputDirectory));
|
||||
}
|
||||
|
||||
private static ResolverState CaptureResolverState()
|
||||
{
|
||||
var settingsType = GetResolverSettingsType();
|
||||
return new ResolverState
|
||||
{
|
||||
EnableAutoResolution = GetResolverBool(settingsType, "EnableAutoResolution"),
|
||||
AutoResolveOnBuild = GetResolverBool(settingsType, "AutoResolveOnBuild"),
|
||||
PromptBeforeAutoResolution = GetResolverBool(settingsType, "PromptBeforeAutoResolution")
|
||||
};
|
||||
}
|
||||
|
||||
private static void ApplyBatchFriendlyResolverSettings()
|
||||
{
|
||||
var settingsType = GetResolverSettingsType();
|
||||
SetResolverBool(settingsType, "EnableAutoResolution", false);
|
||||
SetResolverBool(settingsType, "AutoResolveOnBuild", false);
|
||||
SetResolverBool(settingsType, "PromptBeforeAutoResolution", false);
|
||||
}
|
||||
|
||||
private static void RestoreResolverState(ResolverState state)
|
||||
{
|
||||
var settingsType = GetResolverSettingsType();
|
||||
SetResolverBool(settingsType, "EnableAutoResolution", state.EnableAutoResolution);
|
||||
SetResolverBool(settingsType, "AutoResolveOnBuild", state.AutoResolveOnBuild);
|
||||
SetResolverBool(settingsType, "PromptBeforeAutoResolution", state.PromptBeforeAutoResolution);
|
||||
}
|
||||
|
||||
private static Type GetResolverSettingsType()
|
||||
{
|
||||
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
|
||||
{
|
||||
var type = assembly.GetType("GooglePlayServices.SettingsDialog");
|
||||
if (type != null)
|
||||
{
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private static bool GetResolverBool(Type settingsType, string propertyName)
|
||||
{
|
||||
if (settingsType == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
var property = settingsType.GetProperty(
|
||||
propertyName,
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
|
||||
if (property == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool)property.GetValue(null, null);
|
||||
}
|
||||
|
||||
private static void SetResolverBool(Type settingsType, string propertyName, bool value)
|
||||
{
|
||||
if (settingsType == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var property = settingsType.GetProperty(
|
||||
propertyName,
|
||||
BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static);
|
||||
if (property == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
property.SetValue(null, value, null);
|
||||
}
|
||||
|
||||
private struct ResolverState
|
||||
{
|
||||
public bool EnableAutoResolution;
|
||||
public bool AutoResolveOnBuild;
|
||||
public bool PromptBeforeAutoResolution;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97e92d5544ec4fc9adf7571f9f4ea241
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,159 +0,0 @@
|
||||
#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
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c488fb4879e14f5cb366ce084ff2b748
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -1,78 +0,0 @@
|
||||
#if UNITY_EDITOR
|
||||
using System;
|
||||
using System.IO;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
|
||||
[InitializeOnLoad]
|
||||
public static class IAABatchBuildBootstrap
|
||||
{
|
||||
private const string TaskFilePath = "Temp/iaa-batch-task.txt";
|
||||
private static bool _subscribed;
|
||||
private static bool _taskRunning;
|
||||
|
||||
static IAABatchBuildBootstrap()
|
||||
{
|
||||
if (!Application.isBatchMode)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_subscribed)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_subscribed = true;
|
||||
EditorApplication.update += ExecutePendingTaskWhenReady;
|
||||
}
|
||||
|
||||
private static void ExecutePendingTaskWhenReady()
|
||||
{
|
||||
if (!Application.isBatchMode || _taskRunning)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
var fullPath = Path.GetFullPath(TaskFilePath);
|
||||
if (!File.Exists(fullPath))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (EditorApplication.isCompiling || EditorApplication.isUpdating)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_taskRunning = true;
|
||||
EditorApplication.update -= ExecutePendingTaskWhenReady;
|
||||
|
||||
var task = File.ReadAllText(fullPath).Trim();
|
||||
File.Delete(fullPath);
|
||||
|
||||
try
|
||||
{
|
||||
switch (task)
|
||||
{
|
||||
case "create-sample":
|
||||
IAAAdDebugSampleCreator.CreateOrUpdateSample();
|
||||
break;
|
||||
case "build-apk":
|
||||
IAAAdAndroidBuild.BuildAndroidTestApk();
|
||||
break;
|
||||
default:
|
||||
Debug.LogWarning($"[IAA Batch] Unknown task: {task}");
|
||||
break;
|
||||
}
|
||||
|
||||
EditorApplication.Exit(0);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
Debug.LogException(exception);
|
||||
EditorApplication.Exit(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,11 +0,0 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 33e31dbdc20d47a78340d49f58d81ef9
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -48,6 +48,15 @@ public class ADListenerAggregator
|
||||
client.onAdCloseEvent += this.onInterstitialAdClose;
|
||||
client.onAdShowEvent += this.onInterstitialAdShow;
|
||||
client.onAdShowFailureEvent += this.onInterstitialAdFailedToShow;
|
||||
client.onAdVideoStartEvent += this.onInterstitialAdStartPlayingVideo;
|
||||
client.onAdVideoEndEvent += this.onInterstitialAdEndPlayingVideo;
|
||||
client.onAdVideoFailureEvent += this.onInterstitialAdFailedToPlayVideo;
|
||||
client.onAdSourceAttemptEvent += this.startLoadingInterstitialAdSource;
|
||||
client.onAdSourceFilledEvent += this.finishLoadingInterstitialAdSource;
|
||||
client.onAdSourceLoadFailureEvent += this.failToLoadInterstitialAdSource;
|
||||
client.onAdSourceBiddingAttemptEvent += this.startBiddingInterstitialAdSource;
|
||||
client.onAdSourceBiddingFilledEvent += this.finishBiddingInterstitialAdSource;
|
||||
client.onAdSourceBiddingFailureEvent += this.failBiddingInterstitialAdSource;
|
||||
}
|
||||
|
||||
this._interstitialListener = listener;
|
||||
@@ -222,4 +231,60 @@ public class ADListenerAggregator
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.onInterstitialAdClick(atAdEventArgs.placementId,
|
||||
atAdEventArgs.callbackInfo));
|
||||
}
|
||||
|
||||
void onInterstitialAdStartPlayingVideo(object sender, ATAdEventArgs atAdEventArgs)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.onInterstitialAdStartPlayingVideo(
|
||||
atAdEventArgs.placementId, atAdEventArgs.callbackInfo));
|
||||
}
|
||||
|
||||
void onInterstitialAdEndPlayingVideo(object sender, ATAdEventArgs atAdEventArgs)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.onInterstitialAdEndPlayingVideo(
|
||||
atAdEventArgs.placementId, atAdEventArgs.callbackInfo));
|
||||
}
|
||||
|
||||
void onInterstitialAdFailedToPlayVideo(object sender, ATAdErrorEventArgs atAdErrorEventArgs)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.onInterstitialAdFailedToPlayVideo(
|
||||
atAdErrorEventArgs.placementId, atAdErrorEventArgs.errorCode, atAdErrorEventArgs.errorMessage));
|
||||
}
|
||||
|
||||
void startLoadingInterstitialAdSource(object sender, ATAdEventArgs atAdEventArgs)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.startLoadingADSource(
|
||||
atAdEventArgs.placementId, atAdEventArgs.callbackInfo));
|
||||
}
|
||||
|
||||
void finishLoadingInterstitialAdSource(object sender, ATAdEventArgs atAdEventArgs)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.finishLoadingADSource(
|
||||
atAdEventArgs.placementId, atAdEventArgs.callbackInfo));
|
||||
}
|
||||
|
||||
void failToLoadInterstitialAdSource(object sender, ATAdErrorEventArgs atAdErrorEventArgs)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.failToLoadADSource(
|
||||
atAdErrorEventArgs.placementId, atAdErrorEventArgs.callbackInfo, atAdErrorEventArgs.errorCode,
|
||||
atAdErrorEventArgs.errorMessage));
|
||||
}
|
||||
|
||||
void startBiddingInterstitialAdSource(object sender, ATAdEventArgs atAdEventArgs)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.startBiddingADSource(
|
||||
atAdEventArgs.placementId, atAdEventArgs.callbackInfo));
|
||||
}
|
||||
|
||||
void finishBiddingInterstitialAdSource(object sender, ATAdEventArgs atAdEventArgs)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.finishBiddingADSource(
|
||||
atAdEventArgs.placementId, atAdEventArgs.callbackInfo));
|
||||
}
|
||||
|
||||
void failBiddingInterstitialAdSource(object sender, ATAdErrorEventArgs atAdErrorEventArgs)
|
||||
{
|
||||
ToponUnityThread.Post(() => this._interstitialListener?.failBiddingADSource(
|
||||
atAdErrorEventArgs.placementId, atAdErrorEventArgs.callbackInfo, atAdErrorEventArgs.errorCode,
|
||||
atAdErrorEventArgs.errorMessage));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,78 +1,78 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AnyThinkAds.Api;
|
||||
using AnyThinkAds.Common;
|
||||
using AnyThinkAds.ThirdParty.LitJson;
|
||||
using Runtime.ADAggregator;
|
||||
using UnityEngine;
|
||||
|
||||
public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
public class AwardVideoPlayer : ADPlayer, ATRewardedVideoListener
|
||||
{
|
||||
private ATRewardedVideo _atRewardedVideo;
|
||||
private ATRewardedAutoVideo _atRewardedAutoVideo;
|
||||
private Action<bool> _onVideoComplete;
|
||||
private IATRewardedVideoAdClient _client;
|
||||
private Action<bool> _onVideoComplete;
|
||||
private ADListenerAggregator _aggregator;
|
||||
private bool _autoLoadRegistered;
|
||||
private bool _autoLoadRegistered;
|
||||
private bool _rewardGranted;
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
this._atRewardedVideo = ATRewardedVideo.Instance;
|
||||
this._atRewardedAutoVideo = ATRewardedAutoVideo.Instance;
|
||||
// this._atRewardedVideo.client.setListener(this); //由于新版本广告sdk弃用该方式,通过以下方式重新桥接监听事件
|
||||
this._aggregator = new ADListenerAggregator();
|
||||
this._aggregator.BindAwardVideoListener(this._atRewardedVideo.client , this);
|
||||
// var adClient = this._atRewardedVideo.client;
|
||||
// adClient.on
|
||||
_client = AnyThinkAds.ATAdsClientFactory.BuildRewardedVideoAdClient();
|
||||
_aggregator = new ADListenerAggregator();
|
||||
_aggregator.BindAwardVideoListener(_client, this);
|
||||
}
|
||||
|
||||
|
||||
public override void ShowAD(Action onClose, Action<bool> onVideoComplete)
|
||||
{
|
||||
if (this.IsReadly())
|
||||
if (!IsReadly())
|
||||
{
|
||||
this.curState = 0;
|
||||
this._onVideoComplete = onVideoComplete;
|
||||
this.adListener.onClose = onClose;
|
||||
this.adListener.onVideoComplete = this.OnVideoComplete;
|
||||
var json = new Dictionary<string, string> { { AnyThinkAds.Api.ATConst.SCENARIO, this.AdScene } };
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo.showAutoAd(this.Key, json);
|
||||
}
|
||||
else
|
||||
{
|
||||
this._atRewardedVideo.showAd(this.Key , json);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
curState = 0;
|
||||
_rewardGranted = false;
|
||||
_onVideoComplete = onVideoComplete;
|
||||
adListener.onClose = onClose;
|
||||
adListener.onVideoComplete = OnVideoComplete;
|
||||
var json = new Dictionary<string, string> { { ATConst.SCENARIO, AdScene } };
|
||||
var mapJson = JsonMapper.ToJson(json);
|
||||
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
_client.showAutoAd(Key, mapJson);
|
||||
return;
|
||||
}
|
||||
|
||||
_client.showAd(Key, mapJson);
|
||||
}
|
||||
|
||||
|
||||
private void OnVideoComplete(bool obj)
|
||||
{
|
||||
this._onVideoComplete?.Invoke(obj);
|
||||
this._onVideoComplete = null;
|
||||
_onVideoComplete?.Invoke(obj);
|
||||
_onVideoComplete = null;
|
||||
}
|
||||
|
||||
public override bool IsReadly()
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
if (this._atRewardedAutoVideo != null &&
|
||||
this._atRewardedAutoVideo.autoLoadRewardedVideoReadyForPlacementID(this.Key))
|
||||
if (_client != null && _client.autoLoadRewardedVideoReadyForPlacementID(Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
return this.curState == 2;
|
||||
return curState == 2;
|
||||
}
|
||||
|
||||
if (this.curState == 2)
|
||||
if (curState == 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (this._atRewardedVideo != null && this._atRewardedVideo.hasAdReady(this.Key))
|
||||
if (_client != null && _client.hasAdReady(Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -81,74 +81,75 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
|
||||
public override void LoadAD()
|
||||
{
|
||||
if (curState == 0)
|
||||
if (curState != 0)
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo.setAutoLocalExtra(this.Key, BuildRewardedExtra());
|
||||
this.curState = this._atRewardedAutoVideo.autoLoadRewardedVideoReadyForPlacementID(this.Key) ? 2 : 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._atRewardedVideo != null && this._atRewardedVideo.hasAdReady(this.Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
Dictionary<string,string> jsonmap = new Dictionary<string,string>();
|
||||
//ATConst.USERID_KEY必传,用于标识每个用户;ATConst.USER_EXTRA_DATA为可选参数,传入后将透传到开发者的服务器
|
||||
jsonmap = BuildRewardedExtra();
|
||||
curState = 1;
|
||||
this._atRewardedVideo.loadVideoAd(this.Key, jsonmap);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#region SDK
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
_client.setAutoLocalExtra(Key, JsonMapper.ToJson(BuildRewardedExtra()));
|
||||
curState = _client.autoLoadRewardedVideoReadyForPlacementID(Key) ? 2 : 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_client != null && _client.hasAdReady(Key))
|
||||
{
|
||||
curState = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
curState = 1;
|
||||
_client.loadVideoAd(Key, JsonMapper.ToJson(BuildRewardedExtra()));
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdLoaded(string placementId)
|
||||
{
|
||||
this.curState = 2;
|
||||
Debug.Log($"[Topon] Rewarded loaded. placementId={placementId}");
|
||||
curState = 2;
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdLoadFail(string placementId, string code, string message)
|
||||
{
|
||||
Debug.LogError($"激励视频加载失败: {message} , code:{code} , placementId: {placementId}");
|
||||
this.curState = 0;
|
||||
curState = 0;
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayStart(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Rewarded play start. placementId={placementId}");
|
||||
NotifyShowStarted();
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayEnd(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Rewarded play end. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayFail(string placementId, string code, string message)
|
||||
{
|
||||
Debug.LogError($"激励视频播放失败: {message} , code:{code} , placementId: {placementId}");
|
||||
curState = 0;
|
||||
this.adListener.OnShowError();
|
||||
adListener.OnShowError();
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayClosed(string placementId, bool isReward, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
this.adListener.OnRewardVerify(isReward , 1 , "");
|
||||
this.adListener.OnAdClose();
|
||||
Debug.Log($"[Topon] Rewarded closed. placementId={placementId}, reward={isReward}");
|
||||
adListener.OnRewardVerify(_rewardGranted || isReward, 1, "");
|
||||
adListener.OnAdClose();
|
||||
}
|
||||
|
||||
public void onRewardedVideoAdPlayClicked(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Rewarded clicked. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onReward(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
this.adListener.OnRewardVerify(true , 1 , "");
|
||||
this.adListener.OnAdClose();
|
||||
Debug.Log($"[Topon] Rewarded reward callback. placementId={placementId}");
|
||||
_rewardGranted = true;
|
||||
}
|
||||
|
||||
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo)
|
||||
@@ -161,7 +162,6 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
|
||||
public void failToLoadADSource(string placementId, ATCallbackInfo callbackInfo, string code, string message)
|
||||
{
|
||||
this.OnError(code , message);
|
||||
}
|
||||
|
||||
public void startBiddingADSource(string placementId, ATCallbackInfo callbackInfo)
|
||||
@@ -176,14 +176,12 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
{
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void OnPlayRequestStarted()
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo?.setAutoLocalExtra(this.Key, BuildRewardedExtra());
|
||||
_client?.setAutoLocalExtra(Key, JsonMapper.ToJson(BuildRewardedExtra()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -206,7 +204,7 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
return;
|
||||
}
|
||||
|
||||
this._atRewardedAutoVideo?.addAutoLoadAdPlacementID(new[] { this.Key });
|
||||
_client?.addAutoLoadAdPlacementID(new[] { Key });
|
||||
_autoLoadRegistered = true;
|
||||
}
|
||||
|
||||
@@ -229,11 +227,10 @@ public class AwardVideoPlayer : ADPlayer , ATRewardedVideoListener
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atRewardedAutoVideo?.entryAutoAdScenarioWithPlacementID(this.Key, scenario);
|
||||
_client?.entryAutoAdScenarioWithPlacementID(Key, scenario);
|
||||
return;
|
||||
}
|
||||
|
||||
this._atRewardedVideo?.entryScenarioWithPlacementID(this.Key, scenario);
|
||||
_client?.entryScenarioWithPlacementID(Key, scenario);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,147 +1,154 @@
|
||||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AnyThinkAds.Api;
|
||||
using AnyThinkAds.Common;
|
||||
using AnyThinkAds.ThirdParty.LitJson;
|
||||
using Runtime.ADAggregator;
|
||||
using UnityEngine;
|
||||
|
||||
public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
public class InteractionPlayer : ADPlayer, ATInterstitialAdListener
|
||||
{
|
||||
private ATInterstitialAd _atInterstitialAd;
|
||||
private ATInterstitialAutoAd _atInterstitialAutoAd;
|
||||
private IATInterstitialAdClient _client;
|
||||
private ADListenerAggregator _aggregator;
|
||||
private bool _autoLoadRegistered;
|
||||
|
||||
private bool _autoLoadRegistered;
|
||||
|
||||
public override void OnInit()
|
||||
{
|
||||
this._atInterstitialAd = ATInterstitialAd.Instance;
|
||||
this._atInterstitialAutoAd = ATInterstitialAutoAd.Instance;
|
||||
this._aggregator = new ADListenerAggregator();
|
||||
this._aggregator.BindInterstitialAdListener(this._atInterstitialAd.client,this);
|
||||
_client = AnyThinkAds.ATAdsClientFactory.BuildInterstitialAdClient();
|
||||
_aggregator = new ADListenerAggregator();
|
||||
_aggregator.BindInterstitialAdListener(_client, this);
|
||||
}
|
||||
|
||||
public override void ShowAD(Action onClose, Action<bool> onVideoComplete)
|
||||
{
|
||||
if (this.IsReadly())
|
||||
if (!IsReadly())
|
||||
{
|
||||
this.adListener.onClose = onClose;
|
||||
this.adListener.onVideoComplete = onVideoComplete;
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atInterstitialAutoAd.showAutoAd(this.Key, BuildInterstitialExtra());
|
||||
}
|
||||
else
|
||||
{
|
||||
ATInterstitialAd.Instance.showInterstitialAd(this.Key);
|
||||
}
|
||||
curState = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
adListener.onClose = onClose;
|
||||
adListener.onVideoComplete = onVideoComplete;
|
||||
var mapJson = JsonMapper.ToJson(BuildInterstitialExtra());
|
||||
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
_client.showAutoAd(Key, mapJson);
|
||||
}
|
||||
else
|
||||
{
|
||||
_client.showInterstitialAd(Key, mapJson);
|
||||
}
|
||||
|
||||
curState = 0;
|
||||
}
|
||||
|
||||
public override bool IsReadly()
|
||||
{
|
||||
if (this.curState == 2)
|
||||
if (curState == 2)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
if (this._atInterstitialAutoAd != null &&
|
||||
this._atInterstitialAutoAd.autoLoadInterstitialAdReadyForPlacementID(this.Key))
|
||||
if (_client != null && _client.autoLoadInterstitialAdReadyForPlacementID(Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
if (this._atInterstitialAd != null && this._atInterstitialAd.hasInterstitialAdReady(this.Key))
|
||||
if (_client != null && _client.hasInterstitialAdReady(Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
curState = 2;
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
public override void LoadAD()
|
||||
{
|
||||
if (curState == 0)
|
||||
if (curState != 0)
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atInterstitialAutoAd.setAutoLocalExtra(this.Key, BuildInterstitialExtra());
|
||||
this.curState = this._atInterstitialAutoAd.autoLoadInterstitialAdReadyForPlacementID(this.Key) ? 2 : 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (this._atInterstitialAd != null && this._atInterstitialAd.hasInterstitialAdReady(this.Key))
|
||||
{
|
||||
this.curState = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
{
|
||||
//加载广告
|
||||
Dictionary<string, object> jsonmap = new Dictionary<string, object>();
|
||||
//只针对Sigmob,Sigmob的激励视频广告源当做插屏使用
|
||||
// jsonmap.Add(AnyThinkAds.Api.ATConst.USE_REWARDED_VIDEO_AS_INTERSTITIAL, AnyThinkAds.Api.ATConst.USE_REWARDED_VIDEO_AS_INTERSTITIAL_NO);
|
||||
var width = (int) (Screen.width * 0.7f);
|
||||
ATSize atSize = new ATSize(width, (int) (width * 1.5f));
|
||||
jsonmap.Add(ATInterstitialAdLoadingExtra.kATInterstitialAdLoadingExtraInterstitialAdSizeStruct , atSize);
|
||||
curState = 1;
|
||||
this._atInterstitialAd.loadInterstitialAd(this.Key, jsonmap);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#region SDK
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
_client.setAutoLocalExtra(Key, JsonMapper.ToJson(BuildInterstitialExtra()));
|
||||
curState = _client.autoLoadInterstitialAdReadyForPlacementID(Key) ? 2 : 1;
|
||||
return;
|
||||
}
|
||||
|
||||
if (_client != null && _client.hasInterstitialAdReady(Key))
|
||||
{
|
||||
curState = 2;
|
||||
return;
|
||||
}
|
||||
|
||||
var jsonmap = new Dictionary<string, object>();
|
||||
var width = (int)(Screen.width * 0.7f);
|
||||
var atSize = new ATSize(width, (int)(width * 1.5f));
|
||||
jsonmap.Add(ATInterstitialAdLoadingExtra.kATInterstitialAdLoadingExtraInterstitialAdSizeStruct, atSize);
|
||||
curState = 1;
|
||||
_client.loadInterstitialAd(Key, JsonMapper.ToJson(jsonmap));
|
||||
}
|
||||
|
||||
public void onInterstitialAdLoad(string placementId)
|
||||
{
|
||||
this.curState = 2;
|
||||
Debug.Log($"[Topon] Interstitial loaded. placementId={placementId}");
|
||||
curState = 2;
|
||||
}
|
||||
|
||||
public void onInterstitialAdLoadFail(string placementId, string code, string message)
|
||||
{
|
||||
this.curState = 0;
|
||||
Debug.LogError($"插屏加载失败: {message} , code:{code} , placementId: {placementId}");
|
||||
curState = 0;
|
||||
}
|
||||
|
||||
public void onInterstitialAdShow(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Interstitial show. placementId={placementId}");
|
||||
NotifyShowStarted();
|
||||
}
|
||||
|
||||
public void onInterstitialAdFailedToShow(string placementId)
|
||||
{
|
||||
this.curState = 0;
|
||||
this.adListener.OnShowError();
|
||||
curState = 0;
|
||||
adListener.OnShowError();
|
||||
}
|
||||
|
||||
public void onInterstitialAdClose(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
this.adListener.OnAdClose();
|
||||
this.adListener.OnShowComplete();
|
||||
Debug.Log($"[Topon] Interstitial close. placementId={placementId}");
|
||||
adListener.OnAdClose();
|
||||
adListener.OnShowComplete();
|
||||
}
|
||||
|
||||
public void onInterstitialAdClick(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Interstitial clicked. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onInterstitialAdStartPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Interstitial video start. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onInterstitialAdEndPlayingVideo(string placementId, ATCallbackInfo callbackInfo)
|
||||
{
|
||||
Debug.Log($"[Topon] Interstitial video end. placementId={placementId}");
|
||||
}
|
||||
|
||||
public void onInterstitialAdFailedToPlayVideo(string placementId, string code, string message)
|
||||
{
|
||||
this.curState = 0;
|
||||
this.adListener.OnShowError();
|
||||
curState = 0;
|
||||
adListener.OnShowError();
|
||||
}
|
||||
|
||||
public void startLoadingADSource(string placementId, ATCallbackInfo callbackInfo)
|
||||
@@ -154,7 +161,6 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
|
||||
public void failToLoadADSource(string placementId, ATCallbackInfo callbackInfo, string code, string message)
|
||||
{
|
||||
this.OnError(code , message);
|
||||
}
|
||||
|
||||
public void startBiddingADSource(string placementId, ATCallbackInfo callbackInfo)
|
||||
@@ -167,17 +173,14 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
|
||||
public void failBiddingADSource(string placementId, ATCallbackInfo callbackInfo, string code, string message)
|
||||
{
|
||||
this.OnError(code , message);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public override void OnPlayRequestStarted()
|
||||
{
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atInterstitialAutoAd?.setAutoLocalExtra(this.Key, BuildInterstitialExtra());
|
||||
_client?.setAutoLocalExtra(Key, JsonMapper.ToJson(BuildInterstitialExtra()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -200,7 +203,7 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
return;
|
||||
}
|
||||
|
||||
this._atInterstitialAutoAd?.addAutoLoadAdPlacementID(new[] { this.Key });
|
||||
_client?.addAutoLoadAdPlacementID(new[] { Key });
|
||||
_autoLoadRegistered = true;
|
||||
}
|
||||
|
||||
@@ -208,7 +211,7 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
{
|
||||
return new Dictionary<string, string>
|
||||
{
|
||||
{ ATConst.SCENARIO, this.AdScene ?? string.Empty }
|
||||
{ ATConst.SCENARIO, AdScene ?? string.Empty }
|
||||
};
|
||||
}
|
||||
|
||||
@@ -222,10 +225,10 @@ public class InteractionPlayer : ADPlayer , ATInterstitialAdListener
|
||||
if (UseAutoLoad())
|
||||
{
|
||||
EnsureAutoLoadRegistered();
|
||||
this._atInterstitialAutoAd?.entryAutoAdScenarioWithPlacementID(this.Key, scenario);
|
||||
_client?.entryAutoAdScenarioWithPlacementID(Key, scenario);
|
||||
return;
|
||||
}
|
||||
|
||||
this._atInterstitialAd?.entryScenarioWithPlacementID(this.Key, scenario);
|
||||
_client?.entryScenarioWithPlacementID(Key, scenario);
|
||||
}
|
||||
}
|
||||
|
||||
11
package.json
11
package.json
@@ -2,7 +2,7 @@
|
||||
"name": "com.commercialization.topon",
|
||||
"displayName": "Commercialization.topon",
|
||||
"description": "基于topon的广告sdk封装,依赖基础商业化模块",
|
||||
"version": "1.4.7",
|
||||
"version": "1.4.9",
|
||||
"unity": "2021.1",
|
||||
"license": "MIT",
|
||||
"repository": {
|
||||
@@ -16,8 +16,15 @@
|
||||
},
|
||||
"dependencies":
|
||||
{
|
||||
"com.foldcc.cc-framework.commercialization" : "http://private.lightyears.ltd:18640/foldcc/CC-Framework.Commercialization.git#1.0.12"
|
||||
"com.foldcc.cc-framework.commercialization" : "http://private.lightyears.ltd:18640/foldcc/CC-Framework.Commercialization.git#1.0.14"
|
||||
},
|
||||
"samples": [
|
||||
{
|
||||
"displayName": "IAA Ad Debug Sample",
|
||||
"description": "Optional debug scene and config for validating rewarded and interstitial flows.",
|
||||
"path": "Samples~/IAAAdDebugSample"
|
||||
}
|
||||
],
|
||||
"keywords": [
|
||||
"Framework"
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user