SDK_UnityMoney/Assets/Script/Common/IAdService.cs

233 lines
5.5 KiB
C#
Raw Normal View History

2025-08-30 09:24:58 +00:00
using System;
2025-09-01 15:57:10 +00:00
using GoogleMobileAds.Api;
2025-09-02 02:07:10 +00:00
using UnityEngine;
// using UnityEditor.Media;
2025-08-31 13:19:46 +00:00
2025-09-01 10:32:50 +00:00
namespace WZ
2025-08-30 09:24:58 +00:00
{
/// <summary>
/// 提供广告SDK功能的统一接口
/// </summary>
public interface IAdService
{
/// <summary>
/// 获取广告客户端名称
/// </summary>
string ClientName { get; }
2025-09-01 07:14:26 +00:00
PlatformType Platfrom { get; }
2025-09-01 12:53:08 +00:00
void RefreshAdsData();
2025-08-30 09:24:58 +00:00
/// <summary>
/// 初始化广告SDK
/// </summary>
void Initialize();
#region 广
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 加载横幅广告
/// </summary>
void LoadBanner();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 检查横幅广告是否可用
/// </summary>
bool IsBannerAvailable();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 显示横幅广告
/// </summary>
void DisplayBanner();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 隐藏横幅广告
/// </summary>
void HideBanner();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 获取横幅广告收益信息
/// </summary>
double GetBannerRevenue();
#endregion
#region 广
/// <summary>
/// 加载插页广告
/// </summary>
void LoadInterstitial();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 检查插页广告是否可用
/// </summary>
bool IsInterstitialAvailable();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 显示插页广告
/// </summary>
2025-09-01 14:14:33 +00:00
void DisplayInterstitial(string _adPos, IvType _IvType = IvType.IV1, Action<double> _closeCallback = null);
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 获取插页广告收益信息
/// </summary>
double GetInterstitialRevenue();
#endregion
#region 广
/// <summary>
/// 加载激励广告
/// </summary>
void LoadRewarded();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 检查激励广告是否可用
/// </summary>
bool IsRewardedAvailable();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 显示激励广告
/// </summary>
2025-09-01 14:14:33 +00:00
void DisplayRewarded(string _adPos, Action<bool,double> _rewardCallback = null, Action _showFailedCallback = null);
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 获取激励广告收益信息
/// </summary>
double GetRewardedRevenue();
#endregion
#region 广
/// <summary>
/// 加载开屏广告
/// </summary>
void LoadSplash();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 检查开屏广告是否可用
/// </summary>
bool IsSplashAvailable();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 显示开屏广告
/// </summary>
void DisplaySplash();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 获取开屏广告收益信息
/// </summary>
double GetSplashRevenue();
#endregion
#region 广
/// <summary>
/// 加载原生广告
/// </summary>
void LoadNative();
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 检查原生广告是否可用
/// </summary>
2025-09-02 02:07:10 +00:00
bool IsNativeAvailable(string adUnitId);
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 显示原生广告
/// </summary>
/// <param name="position">广告位置和尺寸信息</param>
2025-09-02 02:07:10 +00:00
void DisplayNative(string _adPos, string adUnitId, NativeAdPosition position);
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 移除原生广告
/// </summary>
2025-09-02 02:07:10 +00:00
void RemoveNative(string adUnitId);
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 获取原生广告收益信息
/// </summary>
2025-09-02 02:07:10 +00:00
double GetNativeRevenue(string adUnitId);
2025-08-30 09:24:58 +00:00
#endregion
}
/// <summary>
/// 表示处理回调的信息
/// </summary>
[Serializable]
public struct CallbackResult
{
/// <summary>
/// 回调消息
/// </summary>
public string Message;
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 指示广告是否准备就绪
/// </summary>
public bool IsReady;
}
/// <summary>
/// 表示原生广告的位置和尺寸
/// </summary>
[Serializable]
public class NativeAdPosition
{
/// <summary>
/// X坐标
/// </summary>
public int X;
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// Y坐标
/// </summary>
public int Y;
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 广告宽度
/// </summary>
public int Width;
2025-08-31 05:15:14 +00:00
2025-08-30 09:24:58 +00:00
/// <summary>
/// 广告高度
/// </summary>
public int Height;
2025-09-01 15:57:10 +00:00
public NativeTemplateStyle NativeTemplateStyle;
2025-09-02 02:07:10 +00:00
public static NativeAdPosition Create(NativeTemplateStyle nativeTemplateStyle,RectTransform pRect, Camera pCam = null)
{
var tWorldCorners = new Vector3[4];
pRect.GetWorldCorners(tWorldCorners);
var tTopLeft = RectTransformUtility.WorldToScreenPoint(pCam, tWorldCorners[1]);
var tBottomRight = RectTransformUtility.WorldToScreenPoint(pCam, tWorldCorners[3]);
var tWidth = Mathf.Abs(tBottomRight.x - tTopLeft.x);
var tHeight = Mathf.Abs(tBottomRight.y - tTopLeft.y);
return new NativeAdPosition
{
2025-09-02 02:56:23 +00:00
X = PX2DP.PxToDp(tTopLeft.x),
Y = PX2DP.PxToDp(Screen.height - tTopLeft.y),
2025-09-02 02:07:10 +00:00
Width = (int)tWidth,
Height = (int)tHeight,
NativeTemplateStyle = nativeTemplateStyle
};
}
2025-08-30 09:24:58 +00:00
}
2025-08-31 05:15:14 +00:00
[System.Serializable]
public struct HandCallbackInfo
{
public string msg;
public bool isReady;
}
2025-08-30 09:24:58 +00:00
}