提交修改
This commit is contained in:
co-authored by
changyunjia
parent
d4442fc21f
commit
3ac4fe0cd0
+20
-20
@@ -1,20 +1,20 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
// ISDKInitCallback.cs
|
||||
public class ISDKInitCallback : AndroidJavaProxy
|
||||
{
|
||||
public Action<bool, string> onInitResult;
|
||||
|
||||
public ISDKInitCallback() : base("com.rixengine.unity_plugin.ISDKInit") { }
|
||||
|
||||
public void initResult(bool success, string message)
|
||||
{
|
||||
onInitResult?.Invoke(success, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
// ISDKInitCallback.cs
|
||||
public class ISDKInitCallback : AndroidJavaProxy
|
||||
{
|
||||
public Action<bool, string> onInitResult;
|
||||
|
||||
public ISDKInitCallback() : base("com.rixengine.unity_plugin.ISDKInit") { }
|
||||
|
||||
public void initResult(bool success, string message)
|
||||
{
|
||||
onInitResult?.Invoke(success, message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
Regular → Executable
+80
-80
@@ -1,80 +1,80 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoAdSDK
|
||||
{
|
||||
private static AndroidJavaClass _adClass;
|
||||
|
||||
// 初始化SDK
|
||||
public static void Initialize(string host, string token, string sid, string appId, Action<bool, string> callback)
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
{
|
||||
LogD("SDK only works on Android platform");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 创建Java回调对象
|
||||
var initCallback = new ISDKInitCallback
|
||||
{
|
||||
onInitResult = callback
|
||||
};
|
||||
|
||||
// 调用Java方法
|
||||
GetAdClass().CallStatic("init", host, token, sid, appId, initCallback);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogE($"Initialize failed: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 其他接口封装
|
||||
public static void SetDebug(bool enable) => GetAdClass().CallStatic("setDebug", enable);
|
||||
|
||||
public static void SetGDPRConsent(bool consent) => GetAdClass().CallStatic("setSubjectToGDPR", consent);
|
||||
|
||||
public static void SetUserConsent(string consent) => GetAdClass().CallStatic("setUserConsent", consent);
|
||||
|
||||
public static void SetUSPrivacy(string privacy) => GetAdClass().CallStatic("subjectToUSPrivacy", privacy);
|
||||
|
||||
public static void SetExtraParameters(Dictionary<string, object> parameters)
|
||||
{
|
||||
using AndroidJavaObject map = new AndroidJavaObject("java.util.HashMap");
|
||||
foreach (var kv in parameters)
|
||||
{
|
||||
map.Call<AndroidJavaObject>("put", kv.Key, kv.Value);
|
||||
}
|
||||
GetAdClass().CallStatic("setExtraParameters", map);
|
||||
}
|
||||
|
||||
// 获取网络信息
|
||||
public static string GetNetworkName() => GetAdClass().CallStatic<string>("getNetWorkName");
|
||||
public static string GetNetworkVersion() => GetAdClass().CallStatic<string>("getNetWorkVersion");
|
||||
|
||||
public static void LogD(string msg)
|
||||
{
|
||||
GetAdClass().CallStatic("LogD", msg);
|
||||
}
|
||||
|
||||
public static void LogE(string msg)
|
||||
{
|
||||
GetAdClass().CallStatic("LogE", msg);
|
||||
}
|
||||
|
||||
private static AndroidJavaClass GetAdClass()
|
||||
{
|
||||
if (_adClass == null)
|
||||
{
|
||||
_adClass = new AndroidJavaClass("com.rixengine.unity_plugin.RiEngineAd");
|
||||
}
|
||||
return _adClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoAdSDK
|
||||
{
|
||||
private static AndroidJavaClass _adClass;
|
||||
|
||||
// 初始化SDK
|
||||
public static void Initialize(string host, string token, string sid, string appId, Action<bool, string> callback)
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
{
|
||||
LogD("SDK only works on Android platform");
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
// 创建Java回调对象
|
||||
var initCallback = new ISDKInitCallback
|
||||
{
|
||||
onInitResult = callback
|
||||
};
|
||||
|
||||
// 调用Java方法
|
||||
GetAdClass().CallStatic("init", host, token, sid, appId, initCallback);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
LogE($"Initialize failed: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 其他接口封装
|
||||
public static void SetDebug(bool enable) => GetAdClass().CallStatic("setDebug", enable);
|
||||
|
||||
public static void SetGDPRConsent(bool consent) => GetAdClass().CallStatic("setSubjectToGDPR", consent);
|
||||
|
||||
public static void SetUserConsent(string consent) => GetAdClass().CallStatic("setUserConsent", consent);
|
||||
|
||||
public static void SetUSPrivacy(string privacy) => GetAdClass().CallStatic("subjectToUSPrivacy", privacy);
|
||||
|
||||
public static void SetExtraParameters(Dictionary<string, object> parameters)
|
||||
{
|
||||
using AndroidJavaObject map = new AndroidJavaObject("java.util.HashMap");
|
||||
foreach (var kv in parameters)
|
||||
{
|
||||
map.Call<AndroidJavaObject>("put", kv.Key, kv.Value);
|
||||
}
|
||||
GetAdClass().CallStatic("setExtraParameters", map);
|
||||
}
|
||||
|
||||
// 获取网络信息
|
||||
public static string GetNetworkName() => GetAdClass().CallStatic<string>("getNetWorkName");
|
||||
public static string GetNetworkVersion() => GetAdClass().CallStatic<string>("getNetWorkVersion");
|
||||
|
||||
public static void LogD(string msg)
|
||||
{
|
||||
GetAdClass().CallStatic("LogD", msg);
|
||||
}
|
||||
|
||||
public static void LogE(string msg)
|
||||
{
|
||||
GetAdClass().CallStatic("LogE", msg);
|
||||
}
|
||||
|
||||
private static AndroidJavaClass GetAdClass()
|
||||
{
|
||||
if (_adClass == null)
|
||||
{
|
||||
_adClass = new AndroidJavaClass("com.rixengine.unity_plugin.RiEngineAd");
|
||||
}
|
||||
return _adClass;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+157
-157
@@ -1,157 +1,157 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoInterAd
|
||||
{
|
||||
private AndroidJavaObject _interAd;
|
||||
private VosacoInterAdListenerProxy _listenerProxy;
|
||||
|
||||
public VosacoInterAd(string unitId)
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
// 创建Java插屏广告对象
|
||||
_interAd = new AndroidJavaObject("com.rixengine.unity_plugin.InterAd", unitId);
|
||||
|
||||
// 创建并设置监听器
|
||||
_listenerProxy = new VosacoInterAdListenerProxy();
|
||||
_interAd.Call("SetListener", _listenerProxy);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"InterAd creation failed: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 加载广告
|
||||
public void LoadAd()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
|
||||
try
|
||||
{
|
||||
_interAd.Call("Load");
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"LoadAd failed: {e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 显示广告
|
||||
public void ShowAd()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
try
|
||||
{
|
||||
_interAd.Call("Show");
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"ShowAd failed: {e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 检查广告是否就绪
|
||||
public bool IsAdReady()
|
||||
{
|
||||
if (!IsValid()) return false;
|
||||
|
||||
try
|
||||
{
|
||||
return _interAd.Call<bool>("IsReady");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"IsAdReady error :{e.Message}" );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取广告价格
|
||||
public double GetAdPrice()
|
||||
{
|
||||
if (!IsValid()) return 0;
|
||||
try
|
||||
{
|
||||
return _interAd.Call<double>("GetPrice");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"GetAdPrice error :{e.Message}");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 销毁广告对象
|
||||
public void Destroy()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
|
||||
try
|
||||
{
|
||||
_interAd.Call("Destroy");
|
||||
_interAd?.Dispose();
|
||||
_interAd = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"Destroy error :{e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 注册事件监听器
|
||||
public void AddLoadedListener(Action callback)
|
||||
=> _listenerProxy.OnLoaded += callback;
|
||||
|
||||
public void AddLoadFailedListener(Action callback)
|
||||
=> _listenerProxy.OnLoadFailed += callback;
|
||||
|
||||
public void AddClickedListener(Action callback)
|
||||
=> _listenerProxy.OnClicked += callback;
|
||||
|
||||
public void AddShowListener(Action callback)
|
||||
=> _listenerProxy.OnShow += callback;
|
||||
|
||||
public void AddCloseListener(Action callback)
|
||||
=> _listenerProxy.OnClose += callback;
|
||||
|
||||
public void AddVideoStartListener(Action callback)
|
||||
=> _listenerProxy.OnVideoStart += callback;
|
||||
|
||||
public void AddVideoEndListener(Action callback)
|
||||
=> _listenerProxy.OnVideoEnd += callback;
|
||||
|
||||
public void AddVideoErrorListener(Action callback)
|
||||
=> _listenerProxy.OnVideoError += callback;
|
||||
|
||||
|
||||
private bool IsValid()
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
{
|
||||
VosacoAdSDK.LogD("Interstitial ads only supported on Android");
|
||||
return false;
|
||||
}
|
||||
if (_interAd == null)
|
||||
{
|
||||
VosacoAdSDK.LogE("Interstitial ad not initialized");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoInterAd
|
||||
{
|
||||
private AndroidJavaObject _interAd;
|
||||
private VosacoInterAdListenerProxy _listenerProxy;
|
||||
|
||||
public VosacoInterAd(string unitId)
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
// 创建Java插屏广告对象
|
||||
_interAd = new AndroidJavaObject("com.rixengine.unity_plugin.InterAd", unitId);
|
||||
|
||||
// 创建并设置监听器
|
||||
_listenerProxy = new VosacoInterAdListenerProxy();
|
||||
_interAd.Call("SetListener", _listenerProxy);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"InterAd creation failed: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 加载广告
|
||||
public void LoadAd()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
|
||||
try
|
||||
{
|
||||
_interAd.Call("Load");
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"LoadAd failed: {e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 显示广告
|
||||
public void ShowAd()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
try
|
||||
{
|
||||
_interAd.Call("Show");
|
||||
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"ShowAd failed: {e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 检查广告是否就绪
|
||||
public bool IsAdReady()
|
||||
{
|
||||
if (!IsValid()) return false;
|
||||
|
||||
try
|
||||
{
|
||||
return _interAd.Call<bool>("IsReady");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"IsAdReady error :{e.Message}" );
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取广告价格
|
||||
public double GetAdPrice()
|
||||
{
|
||||
if (!IsValid()) return 0;
|
||||
try
|
||||
{
|
||||
return _interAd.Call<double>("GetPrice");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"GetAdPrice error :{e.Message}");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 销毁广告对象
|
||||
public void Destroy()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
|
||||
try
|
||||
{
|
||||
_interAd.Call("Destroy");
|
||||
_interAd?.Dispose();
|
||||
_interAd = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"Destroy error :{e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 注册事件监听器
|
||||
public void AddLoadedListener(Action callback)
|
||||
=> _listenerProxy.OnLoaded += callback;
|
||||
|
||||
public void AddLoadFailedListener(Action callback)
|
||||
=> _listenerProxy.OnLoadFailed += callback;
|
||||
|
||||
public void AddClickedListener(Action callback)
|
||||
=> _listenerProxy.OnClicked += callback;
|
||||
|
||||
public void AddShowListener(Action callback)
|
||||
=> _listenerProxy.OnShow += callback;
|
||||
|
||||
public void AddCloseListener(Action callback)
|
||||
=> _listenerProxy.OnClose += callback;
|
||||
|
||||
public void AddVideoStartListener(Action callback)
|
||||
=> _listenerProxy.OnVideoStart += callback;
|
||||
|
||||
public void AddVideoEndListener(Action callback)
|
||||
=> _listenerProxy.OnVideoEnd += callback;
|
||||
|
||||
public void AddVideoErrorListener(Action callback)
|
||||
=> _listenerProxy.OnVideoError += callback;
|
||||
|
||||
|
||||
private bool IsValid()
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
{
|
||||
VosacoAdSDK.LogD("Interstitial ads only supported on Android");
|
||||
return false;
|
||||
}
|
||||
if (_interAd == null)
|
||||
{
|
||||
VosacoAdSDK.LogE("Interstitial ad not initialized");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
Regular → Executable
Vendored
Regular → Executable
+71
-71
@@ -1,71 +1,71 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoInterAdListenerProxy : AndroidJavaProxy
|
||||
{
|
||||
|
||||
public event Action OnLoaded;
|
||||
public event Action OnLoadFailed;
|
||||
public event Action OnClicked;
|
||||
public event Action OnShow;
|
||||
public event Action OnClose;
|
||||
public event Action OnVideoStart;
|
||||
public event Action OnVideoEnd;
|
||||
public event Action OnVideoError;
|
||||
|
||||
public VosacoInterAdListenerProxy()
|
||||
: base("com.rixengine.unity_plugin.IInterAdListener") { }
|
||||
|
||||
public void onLoaded()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onLoaded");
|
||||
OnLoaded?.Invoke();
|
||||
}
|
||||
|
||||
public void onLoadFailed()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onLoadFailed");
|
||||
OnLoadFailed?.Invoke();
|
||||
}
|
||||
|
||||
public void onClicked()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onClicked");
|
||||
OnClicked?.Invoke();
|
||||
}
|
||||
|
||||
public void onShow()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onShow");
|
||||
OnShow?.Invoke();
|
||||
}
|
||||
|
||||
public void onClose()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onClose");
|
||||
OnClose?.Invoke();
|
||||
}
|
||||
|
||||
public void onVideoStart()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onVideoStart");
|
||||
OnVideoStart?.Invoke();
|
||||
}
|
||||
|
||||
public void onVideoEnd()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onVideoEnd");
|
||||
OnVideoEnd?.Invoke();
|
||||
}
|
||||
|
||||
public void onVideoError()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onVideoError");
|
||||
OnVideoError?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoInterAdListenerProxy : AndroidJavaProxy
|
||||
{
|
||||
|
||||
public event Action OnLoaded;
|
||||
public event Action OnLoadFailed;
|
||||
public event Action OnClicked;
|
||||
public event Action OnShow;
|
||||
public event Action OnClose;
|
||||
public event Action OnVideoStart;
|
||||
public event Action OnVideoEnd;
|
||||
public event Action OnVideoError;
|
||||
|
||||
public VosacoInterAdListenerProxy()
|
||||
: base("com.rixengine.unity_plugin.IInterAdListener") { }
|
||||
|
||||
public void onLoaded()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onLoaded");
|
||||
OnLoaded?.Invoke();
|
||||
}
|
||||
|
||||
public void onLoadFailed()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onLoadFailed");
|
||||
OnLoadFailed?.Invoke();
|
||||
}
|
||||
|
||||
public void onClicked()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onClicked");
|
||||
OnClicked?.Invoke();
|
||||
}
|
||||
|
||||
public void onShow()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onShow");
|
||||
OnShow?.Invoke();
|
||||
}
|
||||
|
||||
public void onClose()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onClose");
|
||||
OnClose?.Invoke();
|
||||
}
|
||||
|
||||
public void onVideoStart()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onVideoStart");
|
||||
OnVideoStart?.Invoke();
|
||||
}
|
||||
|
||||
public void onVideoEnd()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onVideoEnd");
|
||||
OnVideoEnd?.Invoke();
|
||||
}
|
||||
|
||||
public void onVideoError()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY INTER Call : onVideoError");
|
||||
OnVideoError?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
Regular → Executable
+155
-155
@@ -1,155 +1,155 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoRewardAd
|
||||
{
|
||||
private AndroidJavaObject _rewardAd;
|
||||
private VosacoRewardAdListenerProxy _listenerProxy;
|
||||
|
||||
public VosacoRewardAd(string unitId)
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
// 创建Java插屏广告对象
|
||||
_rewardAd = new AndroidJavaObject("com.rixengine.unity_plugin.RewardAd", unitId);
|
||||
|
||||
// 创建并设置监听器
|
||||
_listenerProxy = new VosacoRewardAdListenerProxy();
|
||||
_rewardAd.Call("SetListener", _listenerProxy);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"RewardAd creation failed: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 加载广告
|
||||
public void LoadAd()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
|
||||
try
|
||||
{
|
||||
_rewardAd.Call("Load");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"LoadAd failed: {e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 显示广告
|
||||
public void ShowAd()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
try
|
||||
{
|
||||
_rewardAd.Call("Show");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"ShowAd failed: {e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 检查广告是否就绪
|
||||
public bool IsAdReady()
|
||||
{
|
||||
if (!IsValid()) return false;
|
||||
|
||||
try
|
||||
{
|
||||
return _rewardAd.Call<bool>("IsReady");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"IsAdReady error :{e.Message}");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取广告价格
|
||||
public double GetAdPrice()
|
||||
{
|
||||
if (!IsValid()) return 0;
|
||||
try
|
||||
{
|
||||
return _rewardAd.Call<double>("GetPrice");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"GetAdPrice error :{e.Message}");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 销毁广告对象
|
||||
public void Destroy()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
|
||||
try
|
||||
{
|
||||
_rewardAd.Call("Destroy");
|
||||
_rewardAd?.Dispose();
|
||||
_rewardAd = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"Destroy error :{e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 注册事件监听器
|
||||
public void AddLoadedListener(Action callback)
|
||||
=> _listenerProxy.OnLoaded += callback;
|
||||
|
||||
public void AddLoadFailedListener(Action callback)
|
||||
=> _listenerProxy.OnLoadFailed += callback;
|
||||
|
||||
public void AddClickedListener(Action callback)
|
||||
=> _listenerProxy.OnClicked += callback;
|
||||
|
||||
public void AddRewardListener(Action callback)
|
||||
=> _listenerProxy.OnReward += callback;
|
||||
|
||||
public void AddCloseListener(Action callback)
|
||||
=> _listenerProxy.OnClose += callback;
|
||||
|
||||
public void AddVideoStartListener(Action callback)
|
||||
=> _listenerProxy.OnVideoStart += callback;
|
||||
|
||||
public void AddVideoEndListener(Action callback)
|
||||
=> _listenerProxy.OnVideoEnd += callback;
|
||||
|
||||
public void AddVideoErrorListener(Action callback)
|
||||
=> _listenerProxy.OnVideoError += callback;
|
||||
|
||||
|
||||
private bool IsValid()
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
{
|
||||
VosacoAdSDK.LogD("Interstitial ads only supported on Android");
|
||||
return false;
|
||||
}
|
||||
if (_rewardAd == null)
|
||||
{
|
||||
VosacoAdSDK.LogE("Interstitial ad not initialized");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoRewardAd
|
||||
{
|
||||
private AndroidJavaObject _rewardAd;
|
||||
private VosacoRewardAdListenerProxy _listenerProxy;
|
||||
|
||||
public VosacoRewardAd(string unitId)
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
// 创建Java插屏广告对象
|
||||
_rewardAd = new AndroidJavaObject("com.rixengine.unity_plugin.RewardAd", unitId);
|
||||
|
||||
// 创建并设置监听器
|
||||
_listenerProxy = new VosacoRewardAdListenerProxy();
|
||||
_rewardAd.Call("SetListener", _listenerProxy);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"RewardAd creation failed: {e.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
// 加载广告
|
||||
public void LoadAd()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
|
||||
try
|
||||
{
|
||||
_rewardAd.Call("Load");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"LoadAd failed: {e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 显示广告
|
||||
public void ShowAd()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
try
|
||||
{
|
||||
_rewardAd.Call("Show");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"ShowAd failed: {e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 检查广告是否就绪
|
||||
public bool IsAdReady()
|
||||
{
|
||||
if (!IsValid()) return false;
|
||||
|
||||
try
|
||||
{
|
||||
return _rewardAd.Call<bool>("IsReady");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"IsAdReady error :{e.Message}");
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
// 获取广告价格
|
||||
public double GetAdPrice()
|
||||
{
|
||||
if (!IsValid()) return 0;
|
||||
try
|
||||
{
|
||||
return _rewardAd.Call<double>("GetPrice");
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"GetAdPrice error :{e.Message}");
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// 销毁广告对象
|
||||
public void Destroy()
|
||||
{
|
||||
if (!IsValid()) return;
|
||||
|
||||
try
|
||||
{
|
||||
_rewardAd.Call("Destroy");
|
||||
_rewardAd?.Dispose();
|
||||
_rewardAd = null;
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
VosacoAdSDK.LogE($"Destroy error :{e.Message}");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
// 注册事件监听器
|
||||
public void AddLoadedListener(Action callback)
|
||||
=> _listenerProxy.OnLoaded += callback;
|
||||
|
||||
public void AddLoadFailedListener(Action callback)
|
||||
=> _listenerProxy.OnLoadFailed += callback;
|
||||
|
||||
public void AddClickedListener(Action callback)
|
||||
=> _listenerProxy.OnClicked += callback;
|
||||
|
||||
public void AddRewardListener(Action callback)
|
||||
=> _listenerProxy.OnReward += callback;
|
||||
|
||||
public void AddCloseListener(Action callback)
|
||||
=> _listenerProxy.OnClose += callback;
|
||||
|
||||
public void AddVideoStartListener(Action callback)
|
||||
=> _listenerProxy.OnVideoStart += callback;
|
||||
|
||||
public void AddVideoEndListener(Action callback)
|
||||
=> _listenerProxy.OnVideoEnd += callback;
|
||||
|
||||
public void AddVideoErrorListener(Action callback)
|
||||
=> _listenerProxy.OnVideoError += callback;
|
||||
|
||||
|
||||
private bool IsValid()
|
||||
{
|
||||
if (Application.platform != RuntimePlatform.Android)
|
||||
{
|
||||
VosacoAdSDK.LogD("Interstitial ads only supported on Android");
|
||||
return false;
|
||||
}
|
||||
if (_rewardAd == null)
|
||||
{
|
||||
VosacoAdSDK.LogE("Interstitial ad not initialized");
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
Regular → Executable
Vendored
Regular → Executable
+73
-73
@@ -1,73 +1,73 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoRewardAdListenerProxy : AndroidJavaProxy
|
||||
{
|
||||
public event Action OnLoaded;
|
||||
public event Action OnLoadFailed;
|
||||
public event Action OnClicked;
|
||||
public event Action OnReward;
|
||||
public event Action OnClose;
|
||||
public event Action OnVideoStart;
|
||||
public event Action OnVideoEnd;
|
||||
public event Action OnVideoError;
|
||||
|
||||
public VosacoRewardAdListenerProxy()
|
||||
: base("com.rixengine.unity_plugin.IRewardListener")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void onLoaded()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onLoaded");
|
||||
OnLoaded?.Invoke();
|
||||
}
|
||||
|
||||
public void onLoadFailed()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onLoadFailed");
|
||||
OnLoadFailed?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardPlayStart()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardPlayStart");
|
||||
OnVideoStart?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardPlayEnd()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardPlayEnd");
|
||||
OnVideoEnd?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardPlayFailed()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardPlayFailed");
|
||||
OnVideoError?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardClosed()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardClosed");
|
||||
OnClose?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardClicked()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardClicked");
|
||||
OnClicked?.Invoke();
|
||||
}
|
||||
|
||||
public void onReward()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onReward");
|
||||
OnReward?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AD.VosacoSDK
|
||||
{
|
||||
public class VosacoRewardAdListenerProxy : AndroidJavaProxy
|
||||
{
|
||||
public event Action OnLoaded;
|
||||
public event Action OnLoadFailed;
|
||||
public event Action OnClicked;
|
||||
public event Action OnReward;
|
||||
public event Action OnClose;
|
||||
public event Action OnVideoStart;
|
||||
public event Action OnVideoEnd;
|
||||
public event Action OnVideoError;
|
||||
|
||||
public VosacoRewardAdListenerProxy()
|
||||
: base("com.rixengine.unity_plugin.IRewardListener")
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public void onLoaded()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onLoaded");
|
||||
OnLoaded?.Invoke();
|
||||
}
|
||||
|
||||
public void onLoadFailed()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onLoadFailed");
|
||||
OnLoadFailed?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardPlayStart()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardPlayStart");
|
||||
OnVideoStart?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardPlayEnd()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardPlayEnd");
|
||||
OnVideoEnd?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardPlayFailed()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardPlayFailed");
|
||||
OnVideoError?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardClosed()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardClosed");
|
||||
OnClose?.Invoke();
|
||||
}
|
||||
|
||||
public void onRewardClicked()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onRewardClicked");
|
||||
OnClicked?.Invoke();
|
||||
}
|
||||
|
||||
public void onReward()
|
||||
{
|
||||
VosacoAdSDK.LogD($"UNITY Reward Call : onReward");
|
||||
OnReward?.Invoke();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
Regular → Executable
Reference in New Issue
Block a user