using System; using System.Collections.Generic; using System.Diagnostics.CodeAnalysis; using System.Runtime.InteropServices; using PottingMobileSDK.MiniJSON; using UnityEngine; #if UNITY_IOS public class PottingMobileiOS : PottingMobileBase { [DllImport("__Internal")] private static extern void InitUnityAdSdk(string adUnitsJson, string appAppleId, string umengId, string appsFlyerKey,string umengChannel, string pangleAppID); [DllImport("__Internal")] private static extern void IsDebug(bool isDebug); ///开启定时自动加载广告 [DllImport("__Internal")] private static extern void AutoLoadAd(); //广告相关函数 //加载和显示Banner广告,adPostion-Banner的位置,可传规定的字符串:TopLeft, TopCenter, TopRight, Centered, BottomLeft, BottomCenter, BottomRight [DllImport("__Internal")] private static extern void LoadAndShowBannerAd(string adPostion, int adSize); //隐藏Banner广告 [DllImport("__Internal")] private static extern void HideBannerAd(); //加载Interstitial广告 [DllImport("__Internal")] private static extern void LoadInterstitialAd(); //显示Interstitial广告 [DllImport("__Internal")] private static extern void ShowInterstitialAd(); //加载RewardedVideo广告 [DllImport("__Internal")] private static extern void LoadRewardedVideoAd(); //是否有加载完成的激励视频广告 [DllImport("__Internal")] private static extern bool HasRewardedVideo(); [DllImport("__Internal")] private static extern bool hasRewardedVideo(string adId); //显示激励视频广告 [DllImport("__Internal")] private static extern void ShowRewardedVideoAd(); [DllImport("__Internal")] private static extern void consentInformationReset(); [DllImport("__Internal")] private static extern void showRewardedVideoAd(string adId); //加载插屏式激励视频广告 [DllImport("__Internal")] private static extern void LoadRewardedInterstitialAd(); //显示插屏式激励视频广告 [DllImport("__Internal")] private static extern void ShowRewardedInterstitialAd(); //加载开屏广告 [DllImport("__Internal")] private static extern void LoadAppOpenAd(); //显示开屏广告 [DllImport("__Internal")] private static extern void ShowAppOpenAd(); //统计相关函数 [DllImport("__Internal")] private static extern void CustomEvent(string key, string dicJson); //设置用户等级 (由于友盟SDK限制,现改方法已经弃用,调用无效果,如需要请自行到友盟后台自定义该事件) //[DllImport("__Internal")] //private static extern void SetUserLevelId(int level); //充值购买虚拟货币(金币、宝石、金票等), cash-现金数额,source-购买渠道,coin-虚拟货币数额 [DllImport("__Internal")] private static extern void Pay(double cash, int source, double coin); //充值购买虚拟道具, cash-现金数额,source-购买渠道,coin-虚拟货币数额 [DllImport("__Internal")] private static extern void PayItem(double cash, int source, string itemName, int amount, double price); //游戏内部货币购买道具操作,itemName-道具名称,amount-数量,price-价格 [DllImport("__Internal")] private static extern void Buy(string itemName, int amount, double price); //游戏内消耗道具操作,itemName-道具名称,amount-数量,price-价格 [DllImport("__Internal")] private static extern void Use(string itemName, int amount, double price); //开始关卡,levelName-关卡名称 [DllImport("__Internal")] private static extern void StartLevel(string levelName); //关卡完成,levelName-关卡名称 [DllImport("__Internal")] private static extern void FinishLevel(string levelName); //关卡失败,levelName-关卡名称 [DllImport("__Internal")] private static extern void FailLevel(string levelName); //得到虚拟货币奖励,coin-虚拟货币数额,source-获取渠道(例:游戏奖励、玩家赠送、节日赠送、打怪掉落等) [DllImport("__Internal")] private static extern void Bonus(double coin, int source); //得到道具奖励,itemName-道具名称,amount-数量,price-价格,source-奖励方法 [DllImport("__Internal")] private static extern void BonusItem(string itemName, int amount, double price, int source); [DllImport("__Internal")] private static extern void buyProduct(double price,string productId); [DllImport("__Internal")] private static extern void Restore(); [DllImport("__Internal")] private static extern void querySkuDetail(string prdIdsStr); [DllImport("__Internal")] private static extern void SetRepeatTime(int time); [DllImport("__Internal")] private static extern void InitApplePaySharedSecretKey(string sharedSecret); // 本地推送-设置一个seconds秒后发出的推送 [DllImport("__Internal")] private static extern void SetLocalNotification(int id, string titleStr, string bodyStr, int seconds); // 本地推送-移除某一个指定的通知 [DllImport("__Internal")] private static extern void CancleLocalNotification(int id); // 本地推送-移除所有本地通知 [DllImport("__Internal")] private static extern void CancleAllLocalNotification(); [DllImport("__Internal")] private static extern void shareText(string text); [DllImport("__Internal")] private static extern void LoginUseAppleSign(); [DllImport("__Internal")] private static extern void LoginUseFacebook(); [DllImport("__Internal")] private static extern void FacebookLogOut(); [DllImport("__Internal")] private static extern void InitServicesIsDebug(string gameId, string gameSecret, bool isdebug); [DllImport("__Internal")] private static extern void InitServices(string gameId, string gameSecret, string baseUrl); [DllImport("__Internal")] private static extern void FeedBackSubmit(string msg, string connect, string docInfo); //传入链接,弹出WebView视图 [DllImport("__Internal")] private static extern void ShowWebView(string url); //显示游戏推荐webview [DllImport("__Internal")] private static extern void ShowGameRecommend(); //显示反馈客服webview [DllImport("__Internal")] private static extern void ShowFeedBackHtml(string data); //GameCenter 登录 [DllImport("__Internal")] private static extern void GameCenterLogin(); //上传默认存档 [DllImport("__Internal")] private static extern void UploadAcrive(string data); //下载单个默认的存档 [DllImport("__Internal")] private static extern void DownloadOneSavedAcrive(); //上传指定名称存档 [DllImport("__Internal")] private static extern void UploadAcriveHasName(string name, string data); //下载指定名称存档 [DllImport("__Internal")] private static extern void DownloadOneSavedAcriveHasName(string name); //删除指定名称存档 [DllImport("__Internal")] private static extern void DeleteOneSavedAcrive(string name); //获取该游戏所有iCloud存档 [DllImport("__Internal")] private static extern void DownloadAllSavedAcrive(); //解决指定名称存档冲突的情况 [DllImport("__Internal")] private static extern void ResolveConflictingSavedGames(string name, string data); // 保存高分至某一个存档 [DllImport("__Internal")] private static extern void SaveHighScore(string leaderboardId, long score); ///显示系统排行榜 可以跳转到自定的 game 排行榜 和 跳转到那个时间段 [DllImport("__Internal")] private static extern void ShowSystomGameCenter(string leaderboardId, int time); ///获取排行榜信息 下载game center 某一排行榜中的分数及排名情况 [DllImport("__Internal")] private static extern void DownLoadHighScore(int timeType, string leaderboardId); [DllImport("__Internal")] private static extern void DownLoadMyHighScore(int timeType, string leaderboardId); //显示游戏论坛webview 游戏ID加用户ID [DllImport("__Internal")] private static extern void ShowGameForumUserID(string gameId, string userId); //显示游戏论坛webview 游戏ID加email [DllImport("__Internal")] private static extern void ShowGameForumEmail(string gameId, string email); //去App Store中撰写评论 [DllImport("__Internal")] private static extern void GotoAppStoreWriteReview(string appID); //调起系统自带应用内评分提示框 [DllImport("__Internal")] private static extern void ShowSysReview(); [DllImport("__Internal")] private static extern void AppsflyerValidate(string skuId, string transactionId); [DllImport("__Internal")] private static extern void ShareToFacebook(string imagePath); [DllImport("__Internal")] private static extern void InternalPayActive(string productId, string activeId); [DllImport("__Internal")] private static extern void UmengCustomEvent(string key, string dicJson); [DllImport("__Internal")] private static extern void FireBaseCustomEvent(string key, string dicJson); [DllImport("__Internal")] private static extern void AppsFlyerCustomEvent(string key, string dicJson); [DllImport("__Internal")] private static extern void FacebookCustomEvent(string key, string dicJson); [DllImport("__Internal")] private static extern void FacebookCustomEventSum(string key, double valueToSum, string dicJson); [DllImport("__Internal")] private static extern void UploadPhoto(string imagePath, string title); [DllImport("__Internal")] private static extern void UploadVideo(string imagePath ,string title); [DllImport("__Internal")] private static extern void OpenFriendFinderDeepLink(); static PottingMobileiOS() { InitManager(); } public static void _AppsflyerValidate(string skuId,string transactionId) { AppsflyerValidate(skuId,transactionId); } /// /// 显示webview /// /// public static void _ShowWebView(string url) { ShowWebView(url); } /// /// 打开bbs /// /// 论坛id /// 用户唯一标识 public static void _Showbbs(string bbsId, string userId) { ShowGameForumUserID(bbsId, userId); } /// /// 打开bbs /// /// 论坛id /// 用户邮箱 public static void _ShowBBSWithEmail(string bbsId, string emial) { ShowGameForumEmail(bbsId,emial); } /// /// 显示推荐界面 /// public static void _ShowGameRecommendView() { ShowGameRecommend(); } /// /// 提交反馈接口 /// /// 反馈信息 /// 联系方式 /// 存档 public static void _FeedBackSubmit(string msg, string connect, string docInfo) { FeedBackSubmit(msg, connect, docInfo); } public static void _LoginUseFacebook() { LoginUseFacebook(); } /// /// Facebook退出登录 /// public static void _LogOutFacebook() { FacebookLogOut(); } /// /// 谷歌登录 /// public static void _LoginUseGoogle() { } public static new void _LoginUseAppleSign() { LoginUseAppleSign(); } public static void _querySkuDetail(string[] skus) { var jsonString = Json.Serialize(skus); querySkuDetail(jsonString); } public static void _GetADID(){ } public static void _buyProductEvent(double price,string productId) { buyProduct(price, productId); } public static void InitializeSdk(string jsonAds, string facebookid, string app_flyers_id, string umengId,string umengChannel, string pangleAppID) { SetRepeatTime(AdManagerSettings.Instance.RepeatTime); InitUnityAdSdk(jsonAds, app_flyers_id, umengId, PottingMobileContent.APPSFLYER_DEV_KEY, umengChannel, pangleAppID); InitServices(PottingMobileContent.GameId, PottingMobileContent.GameSecret, PottingMobileContent.baseUrl); } /// /// 初始化sdk /// public static void InitializeSdk() { InitializeSdk(PottingMobileContent.AdJsonString, PottingMobileContent.FacebookAppid, PottingMobileContent.AppsFlyerAppid, PottingMobileContent.UmengAppid, PottingMobileContent.umengChannel, PottingMobileContent.PangleAppID); } /// /// 设置debug日志开关 /// /// public static void withLogDebug(bool isDebug) { IsDebug(isDebug); } /// /// 开启定时自动加载广告 /// public static void autoLoadAd() { AutoLoadAd(); } /// /// 重置同意的链接 /// public static void _consentInformationReset() { consentInformationReset(); PottingLog("ios_consentInformationReset"); } public static void _LoadAppOpenAd() { LoadAppOpenAd(); PottingLog("ios_LoadAppOpenAd"); } public static void _ShowAppOpenAd() { ShowAppOpenAd(); PottingLog("ios_ShowAppOpenAd"); } public static void _ShowInterstitialAd() { ShowInterstitialAd(); PottingLog("ios_LoadRewardedVideoAd"); } public static void _LoadInterstitialAd() { LoadInterstitialAd(); PottingLog("ios_LoadRewardedVideoAd"); } public static void _LoadRewardedInterstitialAd() { LoadRewardedInterstitialAd(); PottingLog("ios_LoadRewardedInterstitialAd"); } public static void _ShowRewardedInterstitialAd() { ShowRewardedInterstitialAd(); PottingLog("ios_ShowRewardedInterstitialAd"); } public static void _LoadRewardedVideoAd() { LoadRewardedVideoAd(); PottingLog("ios_LoadRewardedVideoAd"); } public static void _ShowRewardedVideoAd(string adid) { showRewardedVideoAd(adid); } public static void _ShowRewardedVideoAd() { ShowRewardedVideoAd(); PottingLog("ios_ShowRewardedVideoAd"); } public static bool _HasRewardedVideo() { return HasRewardedVideo(); } public static bool _HasRewardedVideo(string adId) { return hasRewardedVideo(adId); } public static void _LoadAndShowBannerAd(AdPosition adPostion) { _LoadAndShowBannerAd(adPostion, AdSize.H_50); } public static void _LoadAndShowBannerAd(AdPosition adPostion, AdSize adSize) { LoadAndShowBannerAd(adPostion.ToString(), (int)adSize); } public static void _HideBannerAd() { HideBannerAd(); } //充值购买虚拟货币(金币、宝石、金票等), cash-现金数额,source-购买渠道,coin-虚拟货币数额 public static void _Pay(double cash, int source, double coin) { Pay(cash, source, coin); PottingLog("_Pay"); } //充值购买虚拟道具, cash-现金数额,source-购买渠道,coin-虚拟货币数额 public static void _PayItem(double cash, int source, string itemName, int amount, double price) { PayItem(cash, source, itemName, amount, price); PottingLog("_PayItem"); } //游戏内部货币购买道具操作,itemName-道具名称,amount-数量,price-价格 public static void _Buy(string itemName, int amount, double price) { Buy(itemName, amount, price); PottingLog("_Buy"); } //游戏内消耗道具操作,itemName-道具名称,amount-数量,price-价格 public static void _Use(string itemName, int amount, double price) { Use(itemName, amount, price); PottingLog("_Use"); } //开始关卡,levelName-关卡名称 public static void _StartLevel(string levelName) { StartLevel(levelName); PottingLog("_StartLevel"); } //关卡完成,levelName-关卡名称 public static void _FinishLevel(string levelName) { FinishLevel(levelName); PottingLog("_FinishLevel"); } //关卡失败,levelName-关卡名称 public static void _FailLevel(string levelName) { FailLevel(levelName); PottingLog("_FailLevel"); } //得到虚拟货币奖励,coin-虚拟货币数额,source-获取渠道(例:游戏奖励、玩家赠送、节日赠送、打怪掉落等) public static void _Bonus(double coin, int source) { Bonus(coin, source); PottingLog("_Bonus"); } //得到道具奖励,itemName-道具名称,amount-数量,price-价格,source-奖励方法 public static void _BonusItem(string itemName, int amount, double price, int source) { BonusItem(itemName, amount, price, source); PottingLog("_BonusItem"); } //内购相关函数 //调起内购,productId-内购产品ID public static void _InternalPay(string productId, string actId = "",string accountId = "youloft", string profileId = "youloft") { InternalPayActive(productId,actId); } public static void _LoginUseGoogleInClient(string clientId ) { } public static void _InitApplePaySharedSecretKey(string sharedSecret) { InitApplePaySharedSecretKey(sharedSecret); } //恢复购买相关函数 public static void _Restore() { Restore(); } public static void Subscription(string productId,string actId = "") { InternalPayActive(productId,actId); } public static void CheckPurchases(string skuType) { } public static void QueryPurchases(string skuType) { } public static void QueryHistoryPurchases(string skuType) { } public static void _CustomEvent(string key, Dictionary lable) { var jsonString = Json.Serialize(lable); CustomEvent(key, jsonString); PottingLog("_CustomEvent-" + key); } /// /// facebook自定义埋点 /// /// 事件名字 /// 事件参数 public static void _CustomEventFacebook(string key, Dictionary lable) { var jsonString = Json.Serialize(lable); FacebookCustomEvent(key, jsonString); PottingLog("_CustomEvent-" + key); } public static void _CustomLogEventFacebook(string key, double valueToSum, Dictionary lable) { var jsonString = Json.Serialize(lable); FacebookCustomEventSum(key, valueToSum, jsonString); PottingLog("_CustomEvent-" + key); } /// /// firebase自定义埋点 /// /// 事件名字 /// 事件参数 public static void _CustomEventFirebase(string key, Dictionary lable) { var jsonString = Json.Serialize(lable); FireBaseCustomEvent(key, jsonString); PottingLog("_CustomEvent-" + key); } /// /// appsflyer自定义埋点 /// /// 事件名字 /// 事件参数 public static void _CustomEventAppsflyer(string key, Dictionary lable) { var jsonString = Json.Serialize(lable); AppsFlyerCustomEvent(key, jsonString); PottingLog("_CustomEvent-" + key); } /// /// umeng自定义埋点 /// /// 事件名字 /// 事件参数 public static void _CustomEventUmeng(string key, Dictionary lable) { var jsonString = Json.Serialize(lable); UmengCustomEvent(key, jsonString); PottingLog("_CustomEvent-" + key); } //本地推送 public static void _SetLocalNotification(int identifier, string title, string body, int seconds) { SetLocalNotification(identifier, title, body, seconds); } public static void _CancelLocalNotification(int noticeId) { CancleLocalNotification(noticeId); } public static void _CancelAllLocalNotification() { CancleAllLocalNotification(); } public static void _ShareText(string extraText) { shareText(extraText); } /// /// 游戏登录 /// public static void _GameLogin() { Social.localUser.Authenticate(b => { }); GameCenterLogin(); } /// /// 加载默认名称存档 /// public static void _LoadGame() { DownloadOneSavedAcrive(); } /// /// 上传默认名称存档 /// /// 存档数据 public static void _SavedGame(string data) { UploadAcrive(data); } public static void _LoadGame(string name) { DownloadOneSavedAcriveHasName(name); } public static void _SavedGame(string name, string data) { UploadAcriveHasName(name, data); } public static void _DeleteGame(string name) { DeleteOneSavedAcrive(name); } public static void _LoadAllGame() { DownloadAllSavedAcrive(); } /// /// 解决存档冲突,将同名的多个存档变为一个存档解决冲突,需要程序做判断使用那一份存档或让用户选择一份存档 /// /// 冲突的存档名称 /// 确认需要保存的存档 public static void _ResolveConflictGame(string name, string data) { ResolveConflictingSavedGames(name, data); } /// /// 显示排行榜 /// /// public static void _ShowLeaderBoard() { ShowSystomGameCenter(null, (int)TimeSpan.TIME_SPAN_ALL_TIME); } /// /// 显示指定排行榜 /// /// 排行榜id public static void _ShowLeaderBoard(string id, TimeSpan timeSpan) { ShowSystomGameCenter(id,(int)timeSpan); } /// /// 拉取排行榜个人信息 /// /// 排行榜id public static void _LoadLeaderBoard(string id, TimeSpan timeSpan) { DownLoadMyHighScore((int)timeSpan, id); } /// /// 提交排行榜分数 /// /// 排行榜id /// 分数 public static void _SubmitLeaderBoardScore(string id, long score) { SaveHighScore(id,score); } /// /// 打开谷歌应用内评论 /// public static void launchReview() { ShowSysReview(); } public static void _YouLoftGameInfo(Dictionary lable) { _CustomEvent("youloftgameinfo",lable); } public static void _ShareImgByFacebook(string path) { ShareToFacebook(path); } /// /// 邀请Facebook好友 /// public static void _openFriendFinderDeepLink() { OpenFriendFinderDeepLink(); } /// /// 上传到facebook /// /// public static void _uploadPhoto(string path) { UploadPhoto(path, ""); } /// /// 上传到facebook /// /// public static void _uploadVideo(string path) { UploadVideo(path, ""); } /// /// 打开客服反馈页面 /// public static void _showFeedBackHtml(Dictionary lable = null) { var jsonString = Json.Serialize(lable); ShowFeedBackHtml(jsonString); } /// /// /谷歌退出登录 /// public static void _LogOutGoogle() { } public static void _hideLoading() { } public static void _checkLicense() { } } #endif