fix:1、删除上一个sdk,更换新的。2、删除了max广告
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6f65ac5b34e2e421daefec3aca0c1ee3
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+14
@@ -0,0 +1,14 @@
|
||||
#if UNITY_ANDROID
|
||||
using KwaiAds.Scripts.Common;
|
||||
|
||||
namespace KwaiAds.Scripts.Platforms.Android
|
||||
{
|
||||
class AndroidClientFactory : IClientFactory
|
||||
{
|
||||
public ISDK BuildSDKClient()
|
||||
{
|
||||
return new KwaiSdkClient();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 275e0a240fbb94bbbaa5b2aef39327fe
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+22
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
namespace BigoAds.Scripts.Platforms.Android
|
||||
{
|
||||
internal static class AndroidPlatformTool
|
||||
{
|
||||
public const string ClassPackage = "com.kwai.network.sdk";
|
||||
private const string CurrentActivityMethod = "currentActivity";
|
||||
private const string UnityPlayerClassName = "com.unity3d.player.UnityPlayer";
|
||||
|
||||
public static AndroidJavaObject GetGameActivity()
|
||||
{
|
||||
return new AndroidJavaClass(UnityPlayerClassName).GetStatic<AndroidJavaObject>(CurrentActivityMethod);
|
||||
}
|
||||
|
||||
public static void CallMethodOnMainThread(Action task)
|
||||
{
|
||||
GetGameActivity()?.Call("runOnUiThread", new AndroidJavaRunnable(task));
|
||||
}
|
||||
}
|
||||
}
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 2b96b326de04d4efc86c67f33abe4f87
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+164
@@ -0,0 +1,164 @@
|
||||
#if UNITY_ANDROID
|
||||
using System;
|
||||
using BigoAds.Scripts.Platforms.Android;
|
||||
using KwaiAds.Scripts.Api;
|
||||
using KwaiAds.Scripts.Common;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KwaiAds.Scripts.Platforms.Android
|
||||
{
|
||||
public class KwaiAdSDKInit
|
||||
{
|
||||
private const string TAG = "[KwaiAdSDK-INIT]";
|
||||
private const string SDKClientClassName = AndroidPlatformTool.ClassPackage + ".KwaiAdSDK";
|
||||
private const string SDKClientBuilder = AndroidPlatformTool.ClassPackage + ".api.SdkConfig$Builder";
|
||||
private const string SDKClientInitCallback = AndroidPlatformTool.ClassPackage + ".api.KwaiInitCallback";
|
||||
|
||||
private static AndroidJavaClass kwaiAdSdkClass;
|
||||
private static KwaiAdConfig config;
|
||||
private static InitResultCallback initCallback;
|
||||
|
||||
private KwaiAdSDKInit(KwaiAdConfig kwaiAdConfig, InitResultCallback initResultCallback)
|
||||
{
|
||||
if (kwaiAdConfig == null)
|
||||
{
|
||||
throw new ArgumentNullException(nameof(kwaiAdConfig), $"{TAG}: KwaiAdConfig cannot be null.");
|
||||
}
|
||||
config = kwaiAdConfig;
|
||||
initCallback = initResultCallback;
|
||||
}
|
||||
|
||||
private class KwaiNetworkSingleton
|
||||
{
|
||||
private static volatile KwaiAdSDKInit _instance;
|
||||
private static object syncRoot = new object();
|
||||
|
||||
public static KwaiAdSDKInit Instance
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
throw new InvalidOperationException($"{TAG}: KwaiAdSDK instance has not been initialized.");
|
||||
}
|
||||
}
|
||||
}
|
||||
return _instance;
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize(KwaiAdConfig kwaiAdConfig, InitResultCallback initResultCallback)
|
||||
{
|
||||
lock (syncRoot)
|
||||
{
|
||||
if (_instance == null)
|
||||
{
|
||||
_instance = new KwaiAdSDKInit(kwaiAdConfig, initResultCallback);
|
||||
_instance.InitializeKwaiAdSDK();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void Initialize(KwaiAdConfig kwaiAdConfig, InitResultCallback initResultCallback)
|
||||
{
|
||||
KwaiNetworkSingleton.Initialize(kwaiAdConfig, initResultCallback);
|
||||
}
|
||||
|
||||
public static KwaiAdSDKInit Instance
|
||||
{
|
||||
get { return KwaiNetworkSingleton.Instance; }
|
||||
}
|
||||
|
||||
public AndroidJavaClass GetKwaiAdSDKClass()
|
||||
{
|
||||
if (kwaiAdSdkClass == null)
|
||||
{
|
||||
Debug.LogError($"{TAG}: KwaiAdSDKClass has not been initialized..");
|
||||
}
|
||||
return kwaiAdSdkClass;
|
||||
}
|
||||
|
||||
private void InitializeKwaiAdSDK()
|
||||
{
|
||||
var kwaiUnityCallback = new KwaiUnityCallback();
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
{
|
||||
Debug.LogError($"{TAG}: Kwai Ad SDK can only be initialized on Android.");
|
||||
kwaiUnityCallback.onFail(2, "Kwai Ad SDK can only be initialized on Android.");
|
||||
return;
|
||||
}
|
||||
|
||||
kwaiAdSdkClass = new AndroidJavaClass(SDKClientClassName);
|
||||
if (kwaiAdSdkClass == null)
|
||||
{
|
||||
Debug.LogError($"{TAG}: Failed to get KwaiAdSDK class.");
|
||||
kwaiUnityCallback.onFail(3, "Failed to get KwaiAdSDK class.");
|
||||
return;
|
||||
}
|
||||
|
||||
var sdkConfigBuilder = new AndroidJavaObject(SDKClientBuilder);
|
||||
if (sdkConfigBuilder == null)
|
||||
{
|
||||
Debug.LogError($"{TAG}: Failed to create SdkConfig builder.");
|
||||
kwaiUnityCallback.onFail(4, "Failed to create SdkConfig builder.");
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
if (config != null)
|
||||
{
|
||||
sdkConfigBuilder.Call<AndroidJavaObject>("appId", config.AppId);
|
||||
sdkConfigBuilder.Call<AndroidJavaObject>("token", config.Token);
|
||||
sdkConfigBuilder.Call<AndroidJavaObject>("appName", config.AppName);
|
||||
sdkConfigBuilder.Call<AndroidJavaObject>("appDomain", config.AppDomain);
|
||||
sdkConfigBuilder.Call<AndroidJavaObject>("appStoreUrl", config.AppStoreUrl);
|
||||
sdkConfigBuilder.Call<AndroidJavaObject>("setInitCallback", kwaiUnityCallback);
|
||||
sdkConfigBuilder.Call<AndroidJavaObject>("debug", config.DebugLog);
|
||||
}
|
||||
|
||||
AndroidJavaObject currentActivity = AndroidPlatformTool.GetGameActivity();
|
||||
if (currentActivity != null)
|
||||
{
|
||||
AndroidJavaObject contextObject = currentActivity.Call<AndroidJavaObject>("getApplicationContext");
|
||||
Debug.Log("Android Context: " + contextObject.Call<string>("toString"));
|
||||
kwaiAdSdkClass.CallStatic("init", contextObject, sdkConfigBuilder.Call<AndroidJavaObject>("build"));
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Current Activity not found.");
|
||||
kwaiUnityCallback.onFail(1, $"{TAG}: Current Activity not found.");
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
[System.Serializable]
|
||||
private class KwaiUnityCallback : AndroidJavaProxy
|
||||
{
|
||||
public KwaiUnityCallback() : base(SDKClientInitCallback) { }
|
||||
|
||||
public void onSuccess()
|
||||
{
|
||||
Debug.Log($"{TAG}: Kwai SDK initialized successfully.");
|
||||
if (initCallback != null)
|
||||
{
|
||||
initCallback.OnSuccess();
|
||||
}
|
||||
}
|
||||
|
||||
public void onFail(int code, string msg)
|
||||
{
|
||||
Debug.LogError($"{TAG}: Kwai SDK initialization failed. Code: {code}, Message: {msg}");
|
||||
if (initCallback != null)
|
||||
{
|
||||
initCallback.OnFail(code, msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8225807b5469a4df4a11ec59cc223f4d
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Vendored
+244
@@ -0,0 +1,244 @@
|
||||
#if UNITY_ANDROID
|
||||
using BigoAds.Scripts.Platforms.Android;
|
||||
using KwaiAds.Scripts.Api;
|
||||
using KwaiAds.Scripts.Api.Interstitial;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KwaiAds.Scripts.Platforms.Android
|
||||
{
|
||||
public class KwaiInterstitialAdController : IInterstitialAdController
|
||||
{
|
||||
private const string TAG = "[KwaiAdSDK-InterstitialAdController]";
|
||||
private const string InterstitialAdConfigBuilderClassName = AndroidPlatformTool.ClassPackage + ".loader.business.interstitial.data.KwaiInterstitialAdConfig$Builder";
|
||||
private const string KwaiInterstitialAdListenerClassName = AndroidPlatformTool.ClassPackage + ".loader.business.interstitial.interf.IKwaiInterstitialAdListener";
|
||||
private const string AdLoadListenerClassName = AndroidPlatformTool.ClassPackage + ".loader.common.interf.AdLoadListener";
|
||||
private const string KwaiInterstitialAdRequestClassName = AndroidPlatformTool.ClassPackage + ".loader.business.interstitial.data.KwaiInterstitialAdRequest";
|
||||
private const string KwaiAdLoaderManagerMethodName = "getKwaiAdLoaderManager";
|
||||
private const string WithKwaiInterstitialAdListenerMethodName = "withKwaiInterstitialAdListener";
|
||||
private const string BuildInterstitialAdLoaderMethodName = "buildInterstitialAdLoader";
|
||||
|
||||
private AndroidJavaClass _KwaiAdSDKInit;
|
||||
private AdLoadListener _AdLoadListener;
|
||||
private InterstitialAdListener _InterstitialAdListener;
|
||||
private AndroidJavaObject _KwaiInterstitialAd;
|
||||
|
||||
public bool Load(KwaiInterstitialAdRequest request, IInterstitialAdListener adListener, IInterstitialAdLoadListener adLoadListener)
|
||||
{
|
||||
_KwaiAdSDKInit = Android.KwaiAdSDKInit.Instance.GetKwaiAdSDKClass();
|
||||
if (_KwaiAdSDKInit == null)
|
||||
{
|
||||
Debug.Log($"{TAG}: kwaiAdSDKInit is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var loaderManager = _KwaiAdSDKInit.CallStatic<AndroidJavaObject>(KwaiAdLoaderManagerMethodName);
|
||||
if (loaderManager == null)
|
||||
{
|
||||
Debug.Log($"{TAG}: loaderManager is null.");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_AdLoadListener = new AdLoadListener(adLoadListener, this);
|
||||
_InterstitialAdListener = new InterstitialAdListener(adListener);
|
||||
var kwaiInterstitialAdConfig = new AndroidJavaObject(InterstitialAdConfigBuilderClassName, _AdLoadListener);
|
||||
if (kwaiInterstitialAdConfig == null)
|
||||
{
|
||||
Debug.LogError($"{TAG}: Failed to create kwaiInterstitialAdConfig builder.");
|
||||
return false;
|
||||
}
|
||||
kwaiInterstitialAdConfig.Call<AndroidJavaObject>(WithKwaiInterstitialAdListenerMethodName, _InterstitialAdListener);
|
||||
|
||||
var kwaiInterstitialAdAdLoader = loaderManager.Call<AndroidJavaObject>(BuildInterstitialAdLoaderMethodName, kwaiInterstitialAdConfig.Call<AndroidJavaObject>("build"));
|
||||
var adRequest = new AndroidJavaObject(KwaiInterstitialAdRequestClassName, request.TagId);
|
||||
string floorPrice = request.ExtParams[Constants.Request.BID_FLOOR_PRICE];
|
||||
if (floorPrice != null && floorPrice.Length != 0)
|
||||
{
|
||||
Debug.Log($"{TAG}: floorPrice: {floorPrice}.");
|
||||
adRequest.Get<AndroidJavaObject>("extParams").Call<AndroidJavaObject>("put", Constants.Request.BID_FLOOR_PRICE, floorPrice);
|
||||
}
|
||||
kwaiInterstitialAdAdLoader.Call("loadAd", adRequest);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
if (IsReady())
|
||||
{
|
||||
AndroidJavaObject currentActivity = AndroidPlatformTool.GetGameActivity();
|
||||
if (currentActivity == null)
|
||||
{
|
||||
Debug.Log($"{TAG}: Current Game Activity not found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{TAG}: start showing.");
|
||||
_KwaiInterstitialAd.Call("show", currentActivity);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{TAG}: IsLoaded: {IsLoaded()}, IsReady: {IsReady()}.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
if (_AdLoadListener != null)
|
||||
{
|
||||
_AdLoadListener.Destory();
|
||||
_AdLoadListener = null;
|
||||
}
|
||||
|
||||
if (_InterstitialAdListener != null)
|
||||
{
|
||||
_InterstitialAdListener.Destory();
|
||||
}
|
||||
|
||||
_KwaiInterstitialAd = null;
|
||||
}
|
||||
|
||||
public bool IsLoaded()
|
||||
{
|
||||
return _KwaiInterstitialAd != null;
|
||||
}
|
||||
|
||||
public bool IsReady()
|
||||
{
|
||||
return IsLoaded() && _KwaiInterstitialAd.Call<bool>("isReady");
|
||||
}
|
||||
|
||||
public void NotifyLoss(string winPrice)
|
||||
{
|
||||
if (_KwaiInterstitialAd != null)
|
||||
{
|
||||
//_KwaiInterstitialAd.Call("getBidController", "sendBidLose");
|
||||
AndroidJavaObject bidController = _KwaiInterstitialAd.Call<AndroidJavaObject>("getBidController");
|
||||
bidController?.Call("sendBidLose", "101", winPrice);
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyWin(string minWinPrice)
|
||||
{
|
||||
if (_KwaiInterstitialAd != null)
|
||||
{
|
||||
//_KwaiInterstitialAd.Call("getBidController", "sendBidWin");
|
||||
AndroidJavaObject bidController = _KwaiInterstitialAd.Call<AndroidJavaObject>("getBidController");
|
||||
bidController?.Call("sendBidWin", minWinPrice);
|
||||
}
|
||||
}
|
||||
|
||||
private class AdLoadListener : AndroidJavaProxy
|
||||
{
|
||||
private IInterstitialAdLoadListener _InterstitialAdLoadListener;
|
||||
private KwaiInterstitialAdController _KwaiInterstitialAdController;
|
||||
public AdLoadListener(IInterstitialAdLoadListener interstitialAdLoadListener, KwaiInterstitialAdController kwaiInterstitialAdController) : base(AdLoadListenerClassName)
|
||||
{
|
||||
this._InterstitialAdLoadListener = interstitialAdLoadListener;
|
||||
this._KwaiInterstitialAdController = kwaiInterstitialAdController;
|
||||
}
|
||||
|
||||
public void onAdLoadStart(string trackId)
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdLoadStart");
|
||||
if (_InterstitialAdLoadListener != null)
|
||||
{
|
||||
_InterstitialAdLoadListener.OnAdLoadStart(trackId);
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdLoadSuccess(string trackId, AndroidJavaObject kwaiInterstitialAd)
|
||||
{
|
||||
_KwaiInterstitialAdController._KwaiInterstitialAd = kwaiInterstitialAd;
|
||||
string price = kwaiInterstitialAd.Call<string>("getPrice");
|
||||
Debug.Log($"{TAG}: onAdLoaded: {kwaiInterstitialAd.Call<string>("getPrice")}");
|
||||
if (_InterstitialAdLoadListener != null)
|
||||
{
|
||||
_InterstitialAdLoadListener.OnAdLoadSuccess(trackId, price);
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdLoadFailed(string trackId, AndroidJavaObject kwaiError)
|
||||
{
|
||||
int code = kwaiError.Call<int>("getCode");
|
||||
string msg = kwaiError.Call<string>("getMsg");
|
||||
Debug.LogError($"{TAG}: onAdLoadFailed code = {code} msg = {msg}");
|
||||
if (_InterstitialAdLoadListener != null)
|
||||
{
|
||||
_InterstitialAdLoadListener.OnAdLoadFailed(trackId, code, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void Destory()
|
||||
{
|
||||
_InterstitialAdLoadListener = null;
|
||||
_KwaiInterstitialAdController = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class InterstitialAdListener : AndroidJavaProxy
|
||||
{
|
||||
private IInterstitialAdListener _InterstitialAdListener;
|
||||
|
||||
public InterstitialAdListener(IInterstitialAdListener interstitialAdListener) : base(KwaiInterstitialAdListenerClassName)
|
||||
{
|
||||
_InterstitialAdListener = interstitialAdListener;
|
||||
}
|
||||
|
||||
public void onAdShow()
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdShow");
|
||||
if (_InterstitialAdListener != null)
|
||||
{
|
||||
_InterstitialAdListener.OnAdShow();
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdShowFailed(AndroidJavaObject error)
|
||||
{
|
||||
int code = error.Call<int>("getCode");
|
||||
string msg = error.Call<string>("getMsg");
|
||||
Debug.LogError($"{TAG}: onAdShowFailed code = {code} msg = {msg}");
|
||||
if (_InterstitialAdListener != null)
|
||||
{
|
||||
_InterstitialAdListener.OnAdShowFailed(code, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdClick()
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdClick");
|
||||
if (_InterstitialAdListener != null)
|
||||
{
|
||||
_InterstitialAdListener.OnAdClick();
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdClose()
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdClose");
|
||||
if (_InterstitialAdListener != null)
|
||||
{
|
||||
_InterstitialAdListener.OnAdClose();
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdPlayComplete()
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdPlayComplete");
|
||||
if (_InterstitialAdListener != null)
|
||||
{
|
||||
_InterstitialAdListener.OnAdPlayComplete();
|
||||
}
|
||||
}
|
||||
|
||||
public void Destory()
|
||||
{
|
||||
_InterstitialAdListener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0981c7bc6c3f9404e8effcfa265e2632
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+252
@@ -0,0 +1,252 @@
|
||||
#if UNITY_ANDROID
|
||||
using BigoAds.Scripts.Platforms.Android;
|
||||
using KwaiAds.Scripts.Api;
|
||||
using KwaiAds.Scripts.Api.Reward;
|
||||
using UnityEngine;
|
||||
|
||||
namespace KwaiAds.Scripts.Platforms.Android
|
||||
{
|
||||
public class KwaiRewardAdController : IRewardAdController
|
||||
{
|
||||
private const string TAG = "[KwaiAdSDK-RewardAdController]";
|
||||
private const string RewardedAdConfigBuilderClassName = AndroidPlatformTool.ClassPackage + ".loader.business.reward.data.KwaiRewardAdConfig$Builder";
|
||||
private const string KwaiRewardAdListenerClassName = AndroidPlatformTool.ClassPackage + ".loader.business.reward.interf.IKwaiRewardAdListener";
|
||||
private const string AdLoadListenerClassName = AndroidPlatformTool.ClassPackage + ".loader.common.interf.AdLoadListener";
|
||||
private const string KwaiRewardAdRequestClassName = AndroidPlatformTool.ClassPackage + ".loader.business.reward.data.KwaiRewardAdRequest";
|
||||
private const string KwaiAdLoaderManagerMethodName = "getKwaiAdLoaderManager";
|
||||
private const string WithKwaiRewardAdListenerMethodName = "withKwaiRewardAdListener";
|
||||
private const string BuildRewardAdLoaderMethodName = "buildRewardAdLoader";
|
||||
|
||||
private AndroidJavaClass _KwaiAdSDKInit;
|
||||
private AdLoadListener _AdLoadListener;
|
||||
private RewardAdListener _RewardAdListener;
|
||||
private AndroidJavaObject _KwaiRewardAd;
|
||||
|
||||
public bool Load(KwaiRewardAdRequest request, IRewardAdListener rewardAdListener, IRewardAdLoadListener rewardAdLoadListener)
|
||||
{
|
||||
_KwaiAdSDKInit = Android.KwaiAdSDKInit.Instance.GetKwaiAdSDKClass();
|
||||
if (_KwaiAdSDKInit == null)
|
||||
{
|
||||
Debug.Log($"{TAG}: kwaiAdSDKInit is null.");
|
||||
return false;
|
||||
}
|
||||
|
||||
var loaderManager = _KwaiAdSDKInit.CallStatic<AndroidJavaObject>(KwaiAdLoaderManagerMethodName);
|
||||
if (loaderManager == null)
|
||||
{
|
||||
Debug.Log($"{TAG}: loaderManager is null.");
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
_AdLoadListener = new AdLoadListener(rewardAdLoadListener, this);
|
||||
_RewardAdListener = new RewardAdListener(rewardAdListener);
|
||||
var kwaiRewardAdConfig = new AndroidJavaObject(RewardedAdConfigBuilderClassName, _AdLoadListener);
|
||||
if (kwaiRewardAdConfig == null)
|
||||
{
|
||||
Debug.LogError($"{TAG}:Failed to create kwaiRewardAdConfig builder.");
|
||||
return false;
|
||||
}
|
||||
kwaiRewardAdConfig.Call<AndroidJavaObject>(WithKwaiRewardAdListenerMethodName, _RewardAdListener);
|
||||
|
||||
var kwaiRewardAdAdLoader = loaderManager.Call<AndroidJavaObject>(BuildRewardAdLoaderMethodName, kwaiRewardAdConfig.Call<AndroidJavaObject>("build"));
|
||||
var adRequest = new AndroidJavaObject(KwaiRewardAdRequestClassName, request.TagId);
|
||||
string floorPrice = request.ExtParams[Constants.Request.BID_FLOOR_PRICE];
|
||||
if (floorPrice != null && floorPrice.Length != 0)
|
||||
{
|
||||
Debug.Log($"{TAG}: floorPrice: {floorPrice}.");
|
||||
adRequest.Get<AndroidJavaObject>("extParams").Call<AndroidJavaObject>("put", Constants.Request.BID_FLOOR_PRICE, floorPrice);
|
||||
}
|
||||
kwaiRewardAdAdLoader.Call("loadAd", adRequest);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public void Show()
|
||||
{
|
||||
if (IsReady())
|
||||
{
|
||||
AndroidJavaObject currentActivity = AndroidPlatformTool.GetGameActivity();
|
||||
if (currentActivity == null)
|
||||
{
|
||||
Debug.Log($"{TAG}: Current Game Activity not found.");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{TAG}: start showing.");
|
||||
_KwaiRewardAd.Call("show", currentActivity);
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"{TAG}: IsLoaded: {IsLoaded()}, IsReady: {IsReady()}.");
|
||||
}
|
||||
}
|
||||
|
||||
public void Destroy()
|
||||
{
|
||||
if (_AdLoadListener != null)
|
||||
{
|
||||
_AdLoadListener.Destory();
|
||||
_AdLoadListener = null;
|
||||
}
|
||||
|
||||
if (_RewardAdListener != null)
|
||||
{
|
||||
_RewardAdListener.Destory();
|
||||
}
|
||||
|
||||
_KwaiRewardAd = null;
|
||||
}
|
||||
|
||||
public bool IsLoaded()
|
||||
{
|
||||
return _KwaiRewardAd != null;
|
||||
}
|
||||
|
||||
public bool IsReady()
|
||||
{
|
||||
return IsLoaded() && _KwaiRewardAd.Call<bool>("isReady");
|
||||
}
|
||||
|
||||
public void NotifyLoss(string winPrice)
|
||||
{
|
||||
if (_KwaiRewardAd != null)
|
||||
{
|
||||
//_KwaiRewardAd.Call("getBidController", "sendBidLose");
|
||||
AndroidJavaObject bidController = _KwaiRewardAd.Call<AndroidJavaObject>("getBidController");
|
||||
bidController?.Call("sendBidLose", "101", winPrice);
|
||||
}
|
||||
}
|
||||
|
||||
public void NotifyWin(string minWinPrice)
|
||||
{
|
||||
if (_KwaiRewardAd != null)
|
||||
{
|
||||
//_KwaiRewardAd.Call("getBidController", "sendBidWin");
|
||||
AndroidJavaObject bidController = _KwaiRewardAd.Call<AndroidJavaObject>("getBidController");
|
||||
bidController?.Call("sendBidWin", minWinPrice);
|
||||
}
|
||||
}
|
||||
|
||||
private class AdLoadListener : AndroidJavaProxy
|
||||
{
|
||||
private IRewardAdLoadListener _RewardAdLoadListener;
|
||||
private KwaiRewardAdController _KwaiRewardAdController;
|
||||
public AdLoadListener(IRewardAdLoadListener rewardAdListener, KwaiRewardAdController kwaiRewardAdController) : base(AdLoadListenerClassName)
|
||||
{
|
||||
this._RewardAdLoadListener = rewardAdListener;
|
||||
this._KwaiRewardAdController = kwaiRewardAdController;
|
||||
}
|
||||
|
||||
public void onAdLoadStart(string trackId)
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdLoadStart");
|
||||
if (_RewardAdLoadListener != null)
|
||||
{
|
||||
_RewardAdLoadListener.OnAdLoadStart(trackId);
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdLoadSuccess(string trackId, AndroidJavaObject kwaiRewardAd)
|
||||
{
|
||||
_KwaiRewardAdController._KwaiRewardAd = kwaiRewardAd;
|
||||
string price = kwaiRewardAd.Call<string>("getPrice");
|
||||
Debug.Log($"{TAG}: onAdLoaded: {kwaiRewardAd.Call<string>("getPrice")}");
|
||||
if (_RewardAdLoadListener != null)
|
||||
{
|
||||
_RewardAdLoadListener.OnAdLoadSuccess(trackId, price);
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdLoadFailed(string trackId, AndroidJavaObject kwaiError)
|
||||
{
|
||||
int code = kwaiError.Call<int>("getCode");
|
||||
string msg = kwaiError.Call<string>("getMsg");
|
||||
Debug.LogError($"{TAG}: onAdLoadFailed code = {code} msg = {msg}");
|
||||
if (_RewardAdLoadListener != null)
|
||||
{
|
||||
_RewardAdLoadListener.OnAdLoadFailed(trackId, code, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void Destory()
|
||||
{
|
||||
_RewardAdLoadListener = null;
|
||||
_KwaiRewardAdController = null;
|
||||
}
|
||||
}
|
||||
|
||||
private class RewardAdListener : AndroidJavaProxy
|
||||
{
|
||||
private IRewardAdListener _RewardAdListener;
|
||||
|
||||
public RewardAdListener(IRewardAdListener rewardAdListener) : base(KwaiRewardAdListenerClassName) {
|
||||
_RewardAdListener = rewardAdListener;
|
||||
}
|
||||
|
||||
public void onAdShow()
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdShow");
|
||||
if (_RewardAdListener != null)
|
||||
{
|
||||
_RewardAdListener.OnAdShow();
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdShowFailed(AndroidJavaObject error)
|
||||
{
|
||||
int code = error.Call<int>("getCode");
|
||||
string msg = error.Call<string>("getMsg");
|
||||
Debug.LogError($"{TAG}: onAdShowFailed code = {code} msg = {msg}");
|
||||
if (_RewardAdListener != null)
|
||||
{
|
||||
_RewardAdListener.OnAdShowFailed(code, msg);
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdClick()
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdClick");
|
||||
if (_RewardAdListener != null)
|
||||
{
|
||||
_RewardAdListener.OnAdClick();
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdPlayComplete()
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdPlayComplete");
|
||||
if (_RewardAdListener != null)
|
||||
{
|
||||
_RewardAdListener.OnAdPlayComplete();
|
||||
}
|
||||
}
|
||||
|
||||
public void onRewardEarned()
|
||||
{
|
||||
Debug.Log($"{TAG}: onRewarded");
|
||||
if (_RewardAdListener != null)
|
||||
{
|
||||
_RewardAdListener.OnRewardEarned();
|
||||
}
|
||||
}
|
||||
|
||||
public void onAdClose()
|
||||
{
|
||||
Debug.Log($"{TAG}: onAdClose");
|
||||
if (_RewardAdListener != null)
|
||||
{
|
||||
_RewardAdListener.OnAdClose();
|
||||
}
|
||||
}
|
||||
|
||||
public void Destory()
|
||||
{
|
||||
_RewardAdListener = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
Vendored
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ac60b4b82a68d4feb811961ea98ad413
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
#if UNITY_ANDROID
|
||||
using KwaiAds.Scripts.Api;
|
||||
using KwaiAds.Scripts.Api.Interstitial;
|
||||
using KwaiAds.Scripts.Api.Reward;
|
||||
using KwaiAds.Scripts.Common;
|
||||
|
||||
namespace KwaiAds.Scripts.Platforms.Android
|
||||
{
|
||||
public class KwaiSdkClient: ISDK
|
||||
{
|
||||
public void Init(KwaiAdConfig config, InitResultCallback initResultCallback)
|
||||
{
|
||||
KwaiAdSDKInit.Initialize(config, initResultCallback);
|
||||
}
|
||||
|
||||
public IRewardAdController getRewardAdController()
|
||||
{
|
||||
return new KwaiRewardAdController();
|
||||
}
|
||||
|
||||
public IInterstitialAdController getInterstitialAdController()
|
||||
{
|
||||
return new KwaiInterstitialAdController();
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
+11
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 440ab8edeedf747c48701c4009831273
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user