using System.Collections; using System.Collections.Generic; using UnityEngine; using PottingMobileSDK.MiniJSON; using System; using System.IO; using PottingMobileSDK; using UnityEngine.UI; public class Ptest : MonoBehaviour { //事件名称 string loadVideo = "load\nRewarded"; string loadInters = "load\nInterstitial"; string loadBanner = "load\nbanner"; string loadAppOpen = "load\nApp Open"; string showAppOpen = "Show\nApp Open"; string showVideo = "Show\nRewarded Video"; string showInters = "show\nInterstitial"; string gameCenterLogin = "GameCenter 登录"; string sev_login = "Login"; string sev_UploadScore = "Upload\nScore"; string sev_GetUserRank = "Get\nUserRank"; string sev_DedeemConsume = "dedeem\nConsume"; string sev_HeartBeat = "Heart\nbeat"; string sev_PayGetAppVersion = "channel\nPayGetAppVersion"; string sev_getActivitiesWithChannel = "getActivitiesWithChannel"; string sev_channelPayOrder = "channel\nPayOrder"; string sev_userSync = "userSync"; string sev_feedback = "feedback"; string sev_userResumePurchase = "userResume\npurchase"; string sev_userConsume = "userConsume"; string sev_redeemConsume = "redeemConsume"; string sev_userQueryOrder = "userQueryOrdery"; string sev_configSync = "config\nSync"; string shareFB = "shareFB\nimg"; string sev_redeemUserConsume = "redeemUser\nConsume"; string InternalPay = "Internal\nPay"; string sev_Serverinfo = "Server\ninfo"; string loadInterstitialRewarded = "load\nInterstitialRewarded"; string showInterstitialRewarded = "show\nInterstitialRewarded"; string loadGame = "load\ngame"; string uploadGame = "upload\ngame"; string deleGame = "dele\ngame"; string loadAllGame = "load all\ngame"; string resloveGame = "reslove\ngame"; public static string[] PlaySearchStr = { "com.ccgame.dartordie_1", "com.ccgame.dartordie_2", "com.ccgame.dartordie_3", "com.ccgame.dartordie_4", "awards_per_month" }; private void Awake() { } // Start is called before the first frame update void Start() { //创建滚动视图 string[] nameArr = { loadAppOpen, showAppOpen, loadInterstitialRewarded, showInterstitialRewarded, loadVideo, showVideo, loadInters, showInters, loadBanner, shareFB, InternalPay, gameCenterLogin, sev_login, sev_UploadScore, sev_GetUserRank, sev_DedeemConsume, sev_redeemUserConsume, sev_HeartBeat, sev_PayGetAppVersion, sev_getActivitiesWithChannel, sev_channelPayOrder, sev_userSync, sev_feedback, sev_userResumePurchase, sev_userConsume, sev_redeemConsume, sev_userQueryOrder, sev_configSync, sev_Serverinfo, loadGame, uploadGame, deleGame, loadAllGame, resloveGame }; #if UNITY_EDITOR GameObject canvas = GameObject.Find("Canvas"); Vector2 size = new Vector2(canvas.GetComponent().sizeDelta.x, canvas.GetComponent().sizeDelta.y / 2.0f); #else Vector2 size = new Vector2(Screen.width - 20, (float)(Screen.height * 0.5)); #endif Debug.Log("当前屏幕分辨率:" + Screen.currentResolution + " ,屏幕宽高:(" + Screen.width + "," + Screen.height + ")" + " ,DPI:" + Screen.dpi); Debug.Log("ScrollView大小为:" + size); ScroolTest.Instance.InitScrollview(nameArr, new Vector3(Screen.width / 2, Screen.height / 3, 0), size, new Vector2((size.x - 10) * 0.5f, 100)); //设置滚动视图回调 ScroolTest.Instance.ButtonBeClickEvent += ButtonBeClickEvent; //文本视图 //广告SDK PottingMobile.InitializeSdk(); PottingMobile.withLogDebug(true); PottingMobileManger.Instance.MGetADIDEvent += MGetADIDEvent; PottingMobileManger.Instance.MhasRewardedVideoEvent += MhasRewardedVideoEvent; PottingMobileManger.Instance.MloginDidCompleteEvent += MloginDidCompleteEvent; PottingMobileManger.Instance.MOnSkuDetailEvent += MOnSkuDetailEvent; PottingMobileManger.Instance.MOnConversionDataEvent += MOnConversionDataEvent; PottingMobileManger.Instance.MOnImpressionDataEvent += MOnImpressionDataEvent; PottingMobileManger.Instance.MOnRewardedVideoLoadedEvent += MOnRewardedVideoLoadedEvent; PottingMobileManger.Instance.MOnRewardedVideoReceivedRewardEvent += MOnRewardedVideoReceivedRewardEvent; PottingMobileManger.Instance.MOnRewardedVideoClosedEvent += MOnRewardedVideoClosedEvent; PottingMobileManger.Instance.MOnInterstitialShownEvent += MOnInterstitialShownEvent; PottingMobileManger.Instance.MloginUseFacebookEvent += MloginUseFacebookEvent; PottingMobileManger.Instance.MloginGameEvent += MloginGameCenterEvent; //google服务 gameCenter PottingMobileServicesManger.Instance.LoginStatusEvent += LoginStatusEvent; PottingMobileServicesManger.Instance.UserLoginResponsesEvent += UserLoginResponsesEvent; PottingMobileServicesManger.Instance.UserUploadScoreResponsesEvent += UserUploadScoreResponsesEvent; PottingMobileServicesManger.Instance.UserGetUserRankResponsesEvent += UserGetUserRankResponsesEvent; PottingMobileServicesManger.Instance.DedeemConsumeResponsesEvent += DedeemConsumeResponsesEvent; PottingMobileServicesManger.Instance.UserHeartbeatResponsesEvent += UserHeartbeatResponsesEvent; PottingMobileServicesManger.Instance.ConfigSyncResponsesEvent += ConfigSyncResponsesEvent; PottingMobileServicesManger.Instance.ChannelpayGetAppVersionResponsesEvent += ChannelpayGetAppVersionResponsesEvent; PottingMobileServicesManger.Instance.GetActivitiesWithChannelkEvent += GetActivitiesWithChannelkEvent; PottingMobileServicesManger.Instance.GameAnoncementsWithChannelEvent += GameAnoncementsWithChannelEvent; //存档 PottingMobileManger.Instance.MloadGameEvent += MloadGameEvent; PottingMobileManger.Instance.MsaveGameEvent += MsaveGameEvent; PottingMobileManger.Instance.MdeleteGameEvent += MdeleteGameEvent; PottingMobileManger.Instance.MloadAllGameEvent += MloadAllGameEvent; PottingMobileManger.Instance.MresolveConflictGameEvent += MresolveConflictGameEvent; //接口测试 PottingMobileServicesManger.Instance.ChannelpayOrderResponsesEvent += ChannelpayOrderResponsesEvent; PottingMobileServicesManger.Instance.UserSyncResponsesEvent += UserSyncResponsesEvent; PottingMobileServicesManger.Instance.UserOrderResponsesEvent += UserOrderResponsesEvent; PottingMobileServicesManger.Instance.UserResumepurchaseResponsesEvent += UserResumepurchaseResponsesEvent; PottingMobileServicesManger.Instance.UserConsumeResponsesEvent += UserConsumeResponsesEvent; PottingMobileServicesManger.Instance.UserQueryOrderResponsesEvent += UserQueryOrderResponsesEvent; PottingMobileServicesManger.Instance.RedeemConsumeEvent += RedeemConsumeEvent; PottingMobileServicesManger.Instance.RedeemUserConsumeEvent += RedeemUserConsumeEvent; PottingMobileServicesManger.Instance.ServerinfoEvent += ServerinfoEvent; PottingMobileManger.Instance.MShareCompleteEvent += MShareCompleteEvent; PottingMobileManger.Instance.MOnPayResultEvent += MOnPayResultEvent; PottingMobileManger.Instance.MValidateEvent += MValidateEvent; PottingMobileManger.Instance.MOnRewardedInterstitialClosedEvent += MOnRewardedInterstitialClosedEvent; PottingMobileManger.Instance.MOnRewardedInterstitialReceivedRewardEvent += MOnRewardedInterstitialReceivedRewardEvent; PottingMobileManger.Instance.MOnRewardedInterstitialLoadedEvent += MOnRewardedInterstitialLoadedEvent; PottingMobileManger.Instance.MOnRewardedInterstitialFailedEvent += MOnRewardedInterstitialFailedEvent; PottingMobileManger.Instance.MOnAppOpenAdLoadedEvent += MOnAppOpenAdLoadedEvent; PottingMobileManger.Instance.MOnAppOpenAdFailedEvent += MOnAppOpenAdFailedEvent; PottingMobileManger.Instance.MOnAppOpenAdShownEvent += MOnAppOpenAdShownEvent; PottingMobileManger.Instance.MOnAppOpenAdClosedEvent += MOnAppOpenAdClosedEvent; //string json = "[\n" + // " {\n" + // " \"orderId\" : \"1000000627660493\",\n" + // " \"purchaseTime\" : \"2020-02-17 10:38:28\",\n" + // " \"productId\" : \"com.youloft.mummy.99\"\n" + // " }\n" + // "]"; //var data = Json.Deserialize(json) as List; //foreach (var i in data) { // var dict = i as Dictionary; // string orderId=(string)dict["orderId"]; // string purchaseTime= (string)dict["purchaseTime"]; // string productId = (string)dict["productId"]; //} PottingMobile._querySkuDetail(PlaySearchStr); PottingMobileManger.Instance.MGetADIDEvent += MGetADIDEvent; PottingMobile._GetADID(); } private void MGetADIDEvent(string obj) { Debug.Log("MGetADIDEvent--" + obj); addText("MGetADIDEvent--" + obj); } private void MloadGameEvent(string obj) { Debug.Log("MloadGameEvent--" + obj); addText("MloadGameEvent--" + obj); } private void MsaveGameEvent(string obj) { Debug.Log("MsaveGameEvent--" + obj); addText("MsaveGameEvent--" + obj); } private void MdeleteGameEvent(string obj) { Debug.Log("MdeleteGameEvent--" + obj); addText("MdeleteGameEvent--" + obj); } private void MloadAllGameEvent(string obj) { Debug.Log("MloadAllGameEvent--" + obj); addText("MloadAllGameEvent--" + obj); } private void MresolveConflictGameEvent(string obj) { Debug.Log("MresolveConflictGameEvent--" + obj); addText("MresolveConflictGameEvent--" + obj); } private void MOnAppOpenAdLoadedEvent(string obj) { Debug.Log("MOnAppOpenAdLoadedEvent--" + obj); addText("MOnAppOpenAdLoadedEvent--" + obj); } private void MOnAppOpenAdFailedEvent(string obj, string errs) { Debug.Log("MOnAppOpenAdFailedEvent--" + obj); addText("MOnAppOpenAdFailedEvent--" + obj); } private void MOnAppOpenAdShownEvent(string obj) { Debug.Log("MOnAppOpenAdShownEvent--" + obj); addText("MOnAppOpenAdShownEvent--" + obj); } private void MOnAppOpenAdClosedEvent(string obj) { Debug.Log("MOnAppOpenAdClosedEvent--" + obj); addText("MOnAppOpenAdClosedEvent--" + obj); } private void MOnRewardedInterstitialReceivedRewardEvent(string arg1, string arg2, float arg3) { Debug.Log("MOnRewardedInterstitialReceivedRewardEvent--"); addText("MOnRewardedInterstitialReceivedRewardEvent--"); } private void MOnRewardedInterstitialFailedEvent(string arg1, string arg2) { Debug.Log("MOnRewardedInterstitialFailedEvent--" + arg1); addText("MOnRewardedInterstitialFailedEvent--" + arg1); } private void MOnRewardedInterstitialLoadedEvent(string obj) { Debug.Log("MOnRewardedInterstitialLoadedEvent--" + obj); addText("MOnRewardedInterstitialLoadedEvent--" + obj); } private void MOnRewardedInterstitialClosedEvent(string obj) { Debug.Log("MOnRewardedInterstitialClosedEvent--" + obj); addText("MOnRewardedInterstitialClosedEvent--" + obj); } private void ServerinfoEvent(string obj) { Debug.Log("ServerinfoEvent--" + obj); addText("ServerinfoEvent--" + obj); } private void MValidateEvent(string obj) { Debug.Log("MValidateEvent--" + obj); addText("MValidateEvent--" + obj); } private void MOnPayResultEvent(string obj) { Debug.Log("MOnPayResultEvent--" + obj); addText("MOnPayResultEvent--" + obj); } private void RedeemUserConsumeEvent(string obj) { Debug.Log("RedeemUserConsumeEvent--" + obj); addText("RedeemUserConsumeEvent--" + obj); } private void MShareCompleteEvent(string obj) { addText("MShareCompleteEvent--" + obj); } private void MloginUseFacebookEvent(string obj) { Debug.Log("MloginUseFacebookEvent--" + obj); addText("MloginUseFacebookEvent--" + obj); } private void MloginGameCenterEvent(string obj) { Debug.Log("MloginGameCenterEvent--" + obj); addText("MloginGameCenterEvent--" + obj); } private void MOnImpressionDataEvent(string obj) { Debug.Log("ImpressionData--" + obj); } private void MOnConversionDataEvent(string obj) { Debug.Log("onversionData--" + obj); } private void MOnSkuDetailEvent(string obj) { Debug.Log("sku价格回调--" + obj); } private void MloginDidCompleteEvent(string obj) { Debug.Log("登录的回调--" + obj); } private void MhasRewardedVideoEvent(Dictionary obj) { foreach (var item in obj) { Debug.Log(item.Key + "的值" + item.Value); Debug.Log(item.Key + "---" + PottingMobile._HasRewardedVideo(item.Key)); } } private void MOnInterstitialShownEvent(string obj) { addText("MOnInterstitialShownEvent--"); } private void MOnRewardedVideoClosedEvent(string obj) { addText("MOnRewardedVideoClosedEvent--"); } private void MOnRewardedVideoReceivedRewardEvent(string arg1, string arg2, float arg3) { addText("MOnRewardedVideoReceivedRewardEvent--"); } private void MOnRewardedVideoLoadedEvent(string obj) { addText("MOnRewardedVideoLoadedEvent--广告加载完成"); PottingMobile._SetLocalNotification(1, "广告加载完成", "广告已经加载成功", 1); } private void GameAnoncementsWithChannelEvent(string obj) { Debug.Log("GameAnoncementsWithChannelEvent--" + obj); } private void GetActivitiesWithChannelkEvent(string obj) { Debug.Log("GetActivitiesWithChannelkEvent--" + obj); } private void ChannelpayGetAppVersionResponsesEvent(string obj) { Debug.Log("ChannelpayGetAppVersionResponsesEvent--" + obj); } private void ConfigSyncResponsesEvent(string obj) { Debug.Log("ConfigSyncResponsesEvent--" + obj); } private void UserLoginResponsesEvent(string obj) { Debug.Log("UserLoginResponsesEvent--" + obj); } private void UserHeartbeatResponsesEvent(string obj) { Debug.Log("UserHeartbeatResponsesEvent--" + obj); } private void DedeemConsumeResponsesEvent(string obj) { Debug.Log("DedeemConsumeResponsesEvent--" + obj); } private void UserGetUserRankResponsesEvent(string obj) { Debug.Log("UserGetUserRankResponsesEvent--" + obj); } private void UserUploadScoreResponsesEvent(string obj) { Debug.Log("UserUploadScoreResponsesEvent--" + obj); } private void LoginStatusEvent(string obj) { Debug.Log("LoginStatusEvent--" + obj); } //接口回调 private void RedeemConsumeEvent(string obj) { Debug.Log("RedeemConsumeEvent--" + obj); } private void UserQueryOrderResponsesEvent(string obj) { Debug.Log("UserQueryOrderResponsesEvent--" + obj); } private void UserConsumeResponsesEvent(string obj) { Debug.Log("UserConsumeResponsesEvent--" + obj); } private void UserResumepurchaseResponsesEvent(string obj) { Debug.Log("UserResumepurchaseResponsesEvent--" + obj); } private void UserOrderResponsesEvent(string obj) { Debug.Log("UserOrderResponsesEvent--" + obj); } private void UserSyncResponsesEvent(string obj) { Debug.Log("UserSyncResponsesEvent--" + obj); } private void ChannelpayOrderResponsesEvent(string obj) { Debug.Log("ChannelpayOrderResponsesEvent--" + obj); } //滚动视图回调 private void ButtonBeClickEvent(int idx, string btnName) { Debug.Log("ButtonBeClickEvent--" + btnName); if (btnName.Equals(loadAppOpen)) { PottingMobile._LoadAppOpenAd(); } if (btnName.Equals(showAppOpen)) { PottingMobile._ShowAppOpenAd(); } if (btnName.Equals(loadInterstitialRewarded)) { PottingMobile._LoadRewardedInterstitialAd(); } if (btnName.Equals(showInterstitialRewarded)) { PottingMobile._ShowRewardedInterstitialAd(); } if (btnName.Equals(sev_Serverinfo)) { PottingMobileServices._Serverinfo(); } if (btnName.Equals(loadVideo)) { PottingMobile._LoadRewardedVideoAd(); addText("load ..Rewarded"); } if (btnName.Equals(loadInters)) { PottingMobile._LoadInterstitialAd(); addText("load ..Interstitial"); } if (btnName.Equals(loadBanner)) { PottingMobile._LoadAndShowBannerAd(PottingMobileBase.AdPosition.BottomCenter, PottingMobileBase.AdSize.H_50); addText("load ..banner"); } if (btnName.Equals(showVideo)) { Debug.Log("hasvideo--" + PottingMobile._HasRewardedVideo()); //这个函数是unity函数 PottingMobile._ShowRewardedVideoAd(); addText("Show ..Rewarded Video"); } if (btnName.Equals(showInters)) { PottingMobile._ShowInterstitialAd(); addText("Show ..Interstitial"); } if (btnName.Equals(gameCenterLogin)) { PottingMobile._GameLogin(); addText("GameCenter 登录"); } //服务 if (btnName.Equals(sev_login)) { PottingMobileServices._userLogin("test", 0, "test", "test"); } if (btnName.Equals(sev_UploadScore)) { PottingMobileServices._userUploadScore(10, "测试排行榜描述第10名", "900a4b40-783e-4c1e-b77d-d75570ae23ce"); } if (btnName.Equals(sev_GetUserRank)) { PottingMobileServices._userGetUserRank("900a4b40-783e-4c1e-b77d-d75570ae23ce"); } if (btnName.Equals(sev_DedeemConsume)) { PottingMobileServices._dedeemConsume("TEST000309"); } if (btnName.Equals(sev_HeartBeat)) { PottingMobileServices._userHeartbeat(); } if (btnName.Equals(sev_PayGetAppVersion)) { PottingMobileServices._channelPayGetAppVersion(3); } if (btnName.Equals(sev_getActivitiesWithChannel)) { Debug.Log("Potting-->getActivitiesWithChannel"); PottingMobileServices._getActivitiesWithChannel("0", "CN"); PottingMobileServices._getGameAnoncementsWithChannel("3", "2.0", "CN"); } if (btnName.Equals(sev_channelPayOrder)) { #if UNITY_EDITOR PottingMobileServices._channelPayOrder(7, "900a0733-2e50-4479-99b9-df331e4fbab8"); #elif UNITY_ANDROID PottingMobileServices._channelPayOrder(7, "900a0733-2e50-4479-99b9-df331e4fbab8"); #else #endif } if (btnName.Equals(sev_userSync)) { PottingMobileServices._userSync("", 11); } if (btnName.Equals(sev_feedback)) { PottingMobile._showFeedBackHtml(); } if (btnName.Equals(sev_userResumePurchase)) { PottingMobileServices._userResumepurchase(); } if (btnName.Equals(sev_userConsume)) { PottingMobileServices._userConsume("900a0733-2e50-4479-99b9-df331e4fbab8", "c8ac1773-ab8b-4728-952d-ab7901127006"); } if (btnName.Equals(sev_redeemConsume)) { PottingMobileServices._redeemConsume("202006031603", "3"); } if (btnName.Equals(sev_userQueryOrder)) { PottingMobileServices._userQueryOrder("900a0733-2e50-4479-99b9-df331e4fbab8", "915b9ad0-bb55-47c9-81b2-ab7900f1b81e"); } if (btnName.Equals(sev_configSync)) { PottingMobileServices._configSync("11", 10); } if (btnName.Equals(shareFB)) { SaveScreenShot(this, new Rect(0, 0, Screen.width, Screen.height), (s) => { PottingMobile._uploadPhoto(s); }); } if (btnName.Equals(sev_redeemUserConsume)) { PottingMobileServices._redeemUserConsume("TEST000309", "0", ""); } if (btnName.Equals(InternalPay)) { PottingMobile._InternalPay("com.ccgame.dartordie_1"); } if (btnName.Equals(loadGame)) { PottingMobile._LoadGame("UserData"); } if (btnName.Equals(uploadGame)) { PottingMobile._SavedGame("UserData", "qwewqe122dadqweqwe"); PottingMobile._SavedGame("GameConfig", "ckxzjkljkweq564786478"); PottingMobile._SavedGame("ObjcConfig", "faxzwqewwfagaxzcaaczwqeqqgvaczdsadqwrqxzlkcjklasdklv,nza shdakdhoqwhczsblk"); } if (btnName.Equals(deleGame)) { PottingMobile._DeleteGame("UserData"); } if (btnName.Equals(loadAllGame)) { PottingMobile._LoadAllGame(); } if (btnName.Equals(resloveGame)) { PottingMobile._ResolveConflictGame("UserData", "change by func: ResolveConflictGame"); } } // Update is called once per frame void Update() { } //unity渲染截图 左下起点 (0,0) public static IEnumerator ScreenShot(Rect rect, Action outTextrue) { //只在每一帧渲染完成后才读取屏幕信息 yield return new WaitForEndOfFrame(); // 先创建一个的空纹理,大小可根据实现需要来设置 Texture2D screenShot = new Texture2D((int)(rect.width - rect.x), (int)(rect.height - rect.y), TextureFormat.RGB24, false); // 读取屏幕像素信息并存储为纹理数据, screenShot.ReadPixels(rect, 0, 0); screenShot.Apply(); outTextrue?.Invoke(screenShot); } //保存图片的app目录下 public static void SaveScreenShot(MonoBehaviour behaviour, Rect rect, Action outPath = null) { behaviour.StartCoroutine(ScreenShot(rect, texture2D => { string imgDir = Application.persistentDataPath + "/IMG"; if (!Directory.Exists(imgDir)) Directory.CreateDirectory(imgDir); string fileName = $"{Application.productName}_1111.png"; string imgPath = Path.Combine(imgDir, fileName); byte[] imgData = texture2D.EncodeToPNG(); File.WriteAllBytes(imgPath, imgData); outPath?.Invoke(imgPath); })); } private void addText(string s) { } }