| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200 |
- #if UNITY_IOS
- using System.Runtime.InteropServices;
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using System.Text;
- using qsdk;
- public class YouYiSDKiOS : SDKBase
- {
- private YouYiListener m_YouYiListener;
- public QKGame qKGamesdk;
- private QSdkListener qListenter;
- public YouYiSDKiOS()
- {
- SDKName = "XUAN_YOU_IOS";
- m_YouYiListener = SDKMgr.Instance.gameObject.AddComponent<YouYiListener>();
- qListenter = SDKMgr.Instance.gameObject.AddComponent<QSdkListener>();
- qKGamesdk = new QKGame();
- //YouYi_SetCallbackGoName(SDKMgr.Instance.gameObject.name);
- qListenter.InitListener(m_YouYiListener);
- QSdkMgr.SetListener(qListenter.gameObject.name);
- }
- public override void Init()
- {
- base.Init();
- //YouYi_Init();
- if (QSdkMgr.InitState == QKSDKInitState.Success)
- {
- CallInitSuccessCB();
- return;
- }
- QSdkMgr.Init();
- }
- public override void OnApplicationFocus(bool focusStatus)
- {
- base.OnApplicationFocus(focusStatus);
- }
- public override void Login()
- {
- QSdkMgr.Login();
- }
- public override void Logout()
- {
- //YouYi_Logout();
- QSdkMgr.Logout();
- }
- public override void SwitchAccount()
- {
- //YouYi_SwitchAccount();
-
- }
- public override void Pay(int goodsId, string goodsName, string goodsDesc, int count, float amount, string cpOrderId, string extrasParams)
- {
- GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
-
- if (gameRoleInfo == null || !gameRoleInfo.Valid())
- {
- Debug.LogError("[YISDK][Pay] GameRoleInfo is null or not valid !!!");
- m_YouYiListener.OnPayFailed();
- return;
- }
- Dictionary<string, SDKMgr.ProductInfo> cfgs = SDKMgr.Instance.ProductInfos;
- int itemp = Mathf.FloorToInt(amount);
- string pice = "";
- if ((itemp + 0.005f) > amount)
- {
- pice = itemp.ToString();
- }
- else
- {
- pice = amount.ToString("F2");
- }
- Debug.Log("价格 = " + pice);
- if (cfgs.ContainsKey(pice))
- {
- Debug.Log("有 价格 = " + pice);
- SDKMgr.ProductInfo productInfo = cfgs[pice];
- //Debug.Log($"=========================={productInfo.ID}======={productInfo.Name}");
- object extraInfo =JsonUtility.FromJson(extrasParams, typeof(SDKOrderExtraInfo));
- if (extraInfo != null)
- {
- SDKOrderExtraInfo ext = (SDKOrderExtraInfo)extraInfo;
- ext.orderNo = cpOrderId;
- ext.serverId = gameRoleInfo.serverId;
- ext.platform = SDKName;
- extrasParams = JsonUtility.ToJson(ext);
- }
- QSdkMgr.Pay(productInfo.ID, productInfo.Name, amount.ToString(), cpOrderId, goodsName,
- extrasParams, Application.productName, gameRoleInfo.serverName, goodsDesc,
- gameRoleInfo.serverId.ToString(), m_YouYiListener.UID,gameRoleInfo.roleId,gameRoleInfo.roleLv.ToString());
- }
- else
- {
- Debug.Log("没有 价格 = " + pice);
- m_YouYiListener.OnPayFailed();
- }
- }
- public override void CreateRole()
- {
- GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
- if (gameRoleInfo == null || !gameRoleInfo.Valid())
- {
- return;
- }
- QSdkMgr.UpdateRoleInfo(0,gameRoleInfo,"");
- }
- public override void EnterGame()
- {
- GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
- if (gameRoleInfo == null || !gameRoleInfo.Valid())
- {
- return;
- }
- QSdkMgr.UpdateRoleInfo(1, gameRoleInfo, "");
- }
- public override void UpdateRoleLv()
- {
- GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
- if (gameRoleInfo == null || !gameRoleInfo.Valid())
- {
- return;
- }
- QSdkMgr.UpdateRoleInfo(2, gameRoleInfo, "");
- }
- public override void ExitGame()
- {
- }
- public override bool Exit()
- {
- return false;
- }
- public override bool Quit()
- {
- return false;
- }
- public override bool IsReportAction() { return true; }
- public override void ReportAction(Dictionary<object, object> datas)
- {
- base.ReportAction(datas);
- GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
- if (gameRoleInfo == null || !gameRoleInfo.Valid())
- {
- return;
- }
- StringBuilder stringBuilder = new StringBuilder();
- int count = 0;
- foreach (var item in datas)
- {
- count++;
- if (count == datas.Count)
- stringBuilder.Append(item.Key.ToString()).Append(",").Append(item.Value.ToString());
- else
- stringBuilder.Append(item.Key.ToString()).Append(",").Append(item.Value.ToString()).Append(",");
- }
- QSdkMgr.UpdateRoleInfo(4, gameRoleInfo, stringBuilder.ToString());
- }
- public override void CallInitSuccessCB()
- {
- m_YouYiListener.OnInitSuccess();
- }
- public override void CallLoginSuccessCB()
- {
- m_YouYiListener.StartCheckLogin();
- }
- }
- #endif
|