MobSDK.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. using System;
  2. using System.IO;
  3. using System.Text;
  4. using UnityEngine;
  5. using System.Reflection;
  6. using System.Collections;
  7. using System.Collections.Generic;
  8. namespace cn.sharesdk.unity3d {
  9. public class MobSDK : MonoBehaviour
  10. {
  11. #if UNITY_IPHONE || UNITY_IOS
  12. public getPolicyHandle getPolicy;
  13. #endif
  14. public MobSDKImpl sdk;
  15. public OnSubmitPolicyGrantResultCallback onSubmitPolicyGrantResultCallback;
  16. public delegate void OnSubmitPolicyGrantResultCallback(bool success);
  17. void Awake() {
  18. #if UNITY_IPHONE
  19. sdk = new iOSMobSDKImpl(gameObject);
  20. #elif UNITY_ANDROID
  21. sdk = new AndroidMobSDKImpl(gameObject);
  22. #endif
  23. }
  24. private void _PolicyGrantResultCallback(bool success) {
  25. onSubmitPolicyGrantResultCallback(success);
  26. }
  27. /// <summary>
  28. /// 提交用户授权结果给MobSDK
  29. /// <summary>
  30. public Boolean submitPolicyGrantResult(bool granted) {
  31. return sdk.submitPolicyGrantResult(granted);
  32. }
  33. /// <summary>
  34. /// 是否允许展示二次确认框
  35. /// <summary>
  36. public void setAllowDialog(bool allowDialog) {
  37. sdk.setAllowDialog(allowDialog);
  38. }
  39. /// <summary>
  40. /// 设置二次确认框样式
  41. /// <summary>
  42. public void setPolicyUi(string backgroundColorRes, string positiveBtnColorRes, string negativeBtnColorRes) {
  43. sdk.setPolicyUi(backgroundColorRes, positiveBtnColorRes, negativeBtnColorRes);
  44. }
  45. #if UNITY_IPHONE || UNITY_IOS
  46. public delegate void getPolicyHandle(string content);
  47. public void getPrivacyPolicy(bool url, string language) {
  48. sdk.getPrivacyPolicy(url, language);
  49. }
  50. public string getDeviceCurrentLanguage() {
  51. return sdk.getDeviceCurrentLanguage();
  52. }
  53. private void _Callback(string data) {
  54. if (data == null) {
  55. return;
  56. }
  57. Hashtable res = (Hashtable)MiniJSON.jsonDecode(data);
  58. if (res == null || res.Count <= 0) {
  59. return;
  60. }
  61. int status = Convert.ToInt32(res["status"]);
  62. int action = Convert.ToInt32(res["action"]);
  63. switch(status) {
  64. case 1: {
  65. Console.WriteLine(data);
  66. Hashtable resp = (Hashtable) res["res"];
  67. if (action == 1) {
  68. if (getPolicy != null) {
  69. getPolicy((string)resp["url"]);
  70. }
  71. }
  72. break;
  73. }
  74. case 2: {
  75. break;
  76. }
  77. case 3: {
  78. break;
  79. }
  80. }
  81. }
  82. #endif
  83. #if UNITY_ANDROID
  84. public string getPrivacyPolicy(bool url, string language) {
  85. return sdk.getPrivacyPolicy(url, language);
  86. }
  87. #endif
  88. //回调定义
  89. }
  90. }