using System; using GoogleMobileAds.Api; using UnityEngine; // using UnityEditor.Media; namespace WZ { /// /// 提供广告SDK功能的统一接口 /// public interface IAdService { /// /// 获取广告客户端名称 /// string ClientName { get; } PlatformType Platfrom { get; } void RefreshAdsData(); /// /// 初始化广告SDK /// void Initialize(); #region 横幅广告功能 /// /// 加载横幅广告 /// void LoadBanner(); /// /// 检查横幅广告是否可用 /// bool IsBannerAvailable(); /// /// 显示横幅广告 /// void DisplayBanner(); /// /// 隐藏横幅广告 /// void HideBanner(); /// /// 获取横幅广告收益信息 /// double GetBannerRevenue(); #endregion #region 插页广告功能 /// /// 加载插页广告 /// void LoadInterstitial(); /// /// 检查插页广告是否可用 /// bool IsInterstitialAvailable(); /// /// 显示插页广告 /// void DisplayInterstitial(string _adPos, IvType _IvType = IvType.IV1, Action _closeCallback = null); /// /// 获取插页广告收益信息 /// double GetInterstitialRevenue(); #endregion #region 激励广告功能 /// /// 加载激励广告 /// void LoadRewarded(); /// /// 检查激励广告是否可用 /// bool IsRewardedAvailable(); /// /// 显示激励广告 /// void DisplayRewarded(string _adPos, Action _rewardCallback = null, Action _showFailedCallback = null); /// /// 获取激励广告收益信息 /// double GetRewardedRevenue(); #endregion #region 开屏广告功能 /// /// 加载开屏广告 /// void LoadSplash(); /// /// 检查开屏广告是否可用 /// bool IsSplashAvailable(); /// /// 显示开屏广告 /// void DisplaySplash(); /// /// 获取开屏广告收益信息 /// double GetSplashRevenue(); #endregion #region 原生广告功能 /// /// 加载原生广告 /// void LoadNative(); /// /// 检查原生广告是否可用 /// bool IsNativeAvailable(string adUnitId); /// /// 显示原生广告 /// /// 广告位置和尺寸信息 void DisplayNative(string _adPos, string adUnitId, NativeAdPosition position); /// /// 移除原生广告 /// void RemoveNative(string adUnitId); /// /// 获取原生广告收益信息 /// double GetNativeRevenue(string adUnitId); #endregion } /// /// 表示处理回调的信息 /// [Serializable] public struct CallbackResult { /// /// 回调消息 /// public string Message; /// /// 指示广告是否准备就绪 /// public bool IsReady; } /// /// 表示原生广告的位置和尺寸 /// [Serializable] public class NativeAdPosition { /// /// X坐标 /// public int X; /// /// Y坐标 /// public int Y; /// /// 广告宽度 /// public int Width; /// /// 广告高度 /// public int Height; public NativeTemplateStyle NativeTemplateStyle; 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 { X = PX2DP.PxToDp(tTopLeft.x), Y = PX2DP.PxToDp(Screen.height - tTopLeft.y), Width = (int)tWidth, Height = (int)tHeight, NativeTemplateStyle = nativeTemplateStyle }; } } [System.Serializable] public struct HandCallbackInfo { public string msg; public bool isReady; } }