YouYiSDKiOS.cs 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. #if UNITY_IOS
  2. using System.Runtime.InteropServices;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using System.Text;
  7. using qsdk;
  8. public class YouYiSDKiOS : SDKBase
  9. {
  10. private YouYiListener m_YouYiListener;
  11. public QKGame qKGamesdk;
  12. private QSdkListener qListenter;
  13. public YouYiSDKiOS()
  14. {
  15. SDKName = "XUAN_YOU_IOS";
  16. m_YouYiListener = SDKMgr.Instance.gameObject.AddComponent<YouYiListener>();
  17. qListenter = SDKMgr.Instance.gameObject.AddComponent<QSdkListener>();
  18. qKGamesdk = new QKGame();
  19. //YouYi_SetCallbackGoName(SDKMgr.Instance.gameObject.name);
  20. qListenter.InitListener(m_YouYiListener);
  21. QSdkMgr.SetListener(qListenter.gameObject.name);
  22. }
  23. public override void Init()
  24. {
  25. base.Init();
  26. //YouYi_Init();
  27. if (QSdkMgr.InitState == QKSDKInitState.Success)
  28. {
  29. CallInitSuccessCB();
  30. return;
  31. }
  32. QSdkMgr.Init();
  33. }
  34. public override void OnApplicationFocus(bool focusStatus)
  35. {
  36. base.OnApplicationFocus(focusStatus);
  37. }
  38. public override void Login()
  39. {
  40. QSdkMgr.Login();
  41. }
  42. public override void Logout()
  43. {
  44. //YouYi_Logout();
  45. QSdkMgr.Logout();
  46. }
  47. public override void SwitchAccount()
  48. {
  49. //YouYi_SwitchAccount();
  50. }
  51. public override void Pay(int goodsId, string goodsName, string goodsDesc, int count, float amount, string cpOrderId, string extrasParams)
  52. {
  53. GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
  54. if (gameRoleInfo == null || !gameRoleInfo.Valid())
  55. {
  56. Debug.LogError("[YISDK][Pay] GameRoleInfo is null or not valid !!!");
  57. m_YouYiListener.OnPayFailed();
  58. return;
  59. }
  60. Dictionary<string, SDKMgr.ProductInfo> cfgs = SDKMgr.Instance.ProductInfos;
  61. int itemp = Mathf.FloorToInt(amount);
  62. string pice = "";
  63. if ((itemp + 0.005f) > amount)
  64. {
  65. pice = itemp.ToString();
  66. }
  67. else
  68. {
  69. pice = amount.ToString("F2");
  70. }
  71. Debug.Log("价格 = " + pice);
  72. if (cfgs.ContainsKey(pice))
  73. {
  74. Debug.Log("有 价格 = " + pice);
  75. SDKMgr.ProductInfo productInfo = cfgs[pice];
  76. //Debug.Log($"=========================={productInfo.ID}======={productInfo.Name}");
  77. object extraInfo =JsonUtility.FromJson(extrasParams, typeof(SDKOrderExtraInfo));
  78. if (extraInfo != null)
  79. {
  80. SDKOrderExtraInfo ext = (SDKOrderExtraInfo)extraInfo;
  81. ext.orderNo = cpOrderId;
  82. ext.serverId = gameRoleInfo.serverId;
  83. ext.platform = SDKName;
  84. extrasParams = JsonUtility.ToJson(ext);
  85. }
  86. QSdkMgr.Pay(productInfo.ID, productInfo.Name, amount.ToString(), cpOrderId, goodsName,
  87. extrasParams, Application.productName, gameRoleInfo.serverName, goodsDesc,
  88. gameRoleInfo.serverId.ToString(), m_YouYiListener.UID,gameRoleInfo.roleId,gameRoleInfo.roleLv.ToString());
  89. }
  90. else
  91. {
  92. Debug.Log("没有 价格 = " + pice);
  93. m_YouYiListener.OnPayFailed();
  94. }
  95. }
  96. public override void CreateRole()
  97. {
  98. GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
  99. if (gameRoleInfo == null || !gameRoleInfo.Valid())
  100. {
  101. return;
  102. }
  103. QSdkMgr.UpdateRoleInfo(0,gameRoleInfo,"");
  104. }
  105. public override void EnterGame()
  106. {
  107. GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
  108. if (gameRoleInfo == null || !gameRoleInfo.Valid())
  109. {
  110. return;
  111. }
  112. QSdkMgr.UpdateRoleInfo(1, gameRoleInfo, "");
  113. }
  114. public override void UpdateRoleLv()
  115. {
  116. GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
  117. if (gameRoleInfo == null || !gameRoleInfo.Valid())
  118. {
  119. return;
  120. }
  121. QSdkMgr.UpdateRoleInfo(2, gameRoleInfo, "");
  122. }
  123. public override void ExitGame()
  124. {
  125. }
  126. public override bool Exit()
  127. {
  128. return false;
  129. }
  130. public override bool Quit()
  131. {
  132. return false;
  133. }
  134. public override bool IsReportAction() { return true; }
  135. public override void ReportAction(Dictionary<object, object> datas)
  136. {
  137. base.ReportAction(datas);
  138. GameRoleInfo gameRoleInfo = SDKMgr.Instance.GetGameRoleInfo();
  139. if (gameRoleInfo == null || !gameRoleInfo.Valid())
  140. {
  141. return;
  142. }
  143. StringBuilder stringBuilder = new StringBuilder();
  144. int count = 0;
  145. foreach (var item in datas)
  146. {
  147. count++;
  148. if (count == datas.Count)
  149. stringBuilder.Append(item.Key.ToString()).Append(",").Append(item.Value.ToString());
  150. else
  151. stringBuilder.Append(item.Key.ToString()).Append(",").Append(item.Value.ToString()).Append(",");
  152. }
  153. QSdkMgr.UpdateRoleInfo(4, gameRoleInfo, stringBuilder.ToString());
  154. }
  155. public override void CallInitSuccessCB()
  156. {
  157. m_YouYiListener.OnInitSuccess();
  158. }
  159. public override void CallLoginSuccessCB()
  160. {
  161. m_YouYiListener.StartCheckLogin();
  162. }
  163. }
  164. #endif