| | |
| | | using System.Collections.Generic; |
| | | using System.IO; |
| | | using System; |
| | | using UnityEngine.Android; |
| | | |
| | | |
| | | public class SDKUtils : SingletonMonobehaviour<SDKUtils> |
| | | { |
| | |
| | | |
| | | public void Init() |
| | | { |
| | | ynmbxxjUtil.Instance.Init(); |
| | | Device = new DeviceInfo(); |
| | | string uid = LocalSave.GetString("Device_uniqueID"); |
| | | //Debug.Log(Math.Abs(System.Environment.TickCount)); |
| | |
| | | |
| | | public void HandleMsgWithSDK(string jsonString) |
| | | { |
| | | // Debug.Log("收到SDK发来的信息: " + jsonString); |
| | | // var _json = JsonMapper.ToObject(jsonString); |
| | | // var _code = (int)_json["code"]; |
| | | // switch (_code) |
| | | // { |
| | | // case CodeA2U.DeviceInfo: |
| | | Debug.Log("收到SDK发来的信息: " + jsonString); |
| | | var _json = JsonMapper.ToObject(jsonString); |
| | | var _code = (int)_json["code"]; |
| | | switch (_code) |
| | | { |
| | | case CodeA2U.DeviceInfo: |
| | | |
| | | |
| | | // //Device.uniqueID = _json["unique_id"].ToString(); |
| | | // Device.androidID = _json["android_id"].ToString();// ios平台下为idfa |
| | | // Device.userAgent = _json["userAgent"].ToString(); |
| | | // #if UNITY_ANDROID |
| | | // Device.macAddress = _json["mac"].ToString(); |
| | | // if (_json["imei"] != null) |
| | | // { |
| | | // Device.imei = _json["imei"].ToString(); |
| | | // } |
| | | // else |
| | | // { |
| | | // Device.imei = Device.uniqueID; |
| | | // } |
| | | // Device.totalMemory = (int)_json["memoryTotal"]; |
| | | // #endif |
| | | // if (OnDeviceInfoChanged != null) |
| | | // { |
| | | // OnDeviceInfoChanged(Device); |
| | | // } |
| | | //Device.uniqueID = _json["unique_id"].ToString(); |
| | | Device.androidID = _json["android_id"].ToString();// ios平台下为idfa |
| | | Device.userAgent = _json["userAgent"].ToString(); |
| | | #if UNITY_ANDROID |
| | | Device.macAddress = _json["mac"].ToString(); |
| | | if (_json["imei"] != null) |
| | | { |
| | | Device.imei = _json["imei"].ToString(); |
| | | } |
| | | else |
| | | { |
| | | Device.imei = Device.uniqueID; |
| | | } |
| | | Device.totalMemory = (int)_json["memoryTotal"]; |
| | | #endif |
| | | if (OnDeviceInfoChanged != null) |
| | | { |
| | | OnDeviceInfoChanged(Device); |
| | | } |
| | | |
| | | // break; |
| | | // case CodeA2U.AssetCopyFinished: |
| | | // AssetCopyFinished = true; |
| | | // break; |
| | | // case CodeA2U.BatteryLevel: |
| | | break; |
| | | case CodeA2U.AssetCopyFinished: |
| | | AssetCopyFinished = true; |
| | | break; |
| | | case CodeA2U.BatteryLevel: |
| | | |
| | | // BatteryLevel = (int)_json["level"]; |
| | | // if (OnBatteryLevelChanged != null) |
| | | // { |
| | | // OnBatteryLevelChanged(BatteryLevel); |
| | | // } |
| | | BatteryLevel = (int)_json["level"]; |
| | | if (OnBatteryLevelChanged != null) |
| | | { |
| | | OnBatteryLevelChanged(BatteryLevel); |
| | | } |
| | | |
| | | // break; |
| | | // case CodeA2U.BatteryCharging: |
| | | break; |
| | | case CodeA2U.BatteryCharging: |
| | | |
| | | // ChargingType = (E_ChargingType)((int)_json["status"]); |
| | | // if (OnChargingTypeChanged != null) |
| | | // { |
| | | // OnChargingTypeChanged(ChargingType); |
| | | // } |
| | | ChargingType = (E_ChargingType)((int)_json["status"]); |
| | | if (OnChargingTypeChanged != null) |
| | | { |
| | | OnChargingTypeChanged(ChargingType); |
| | | } |
| | | |
| | | // break; |
| | | // case CodeA2U.SdkInitComplete: |
| | | // InitFinished = true; |
| | | // var _dict = _json as IDictionary; |
| | | // if (_dict != null && _dict.Contains("channelPlatform")) |
| | | // { |
| | | // var _channelPlatform = _json["channelPlatform"].ToString(); |
| | | // if (!string.IsNullOrEmpty(_channelPlatform)) |
| | | // { |
| | | // if (_channelPlatform.Equals("hygame")) |
| | | // { |
| | | // ChannelPlatform = E_ChannelPlatform.Hy; |
| | | // } |
| | | // else if (_channelPlatform.Equals("quick")) |
| | | // { |
| | | // ChannelPlatform = E_ChannelPlatform.Quick; |
| | | // } |
| | | // else if (_channelPlatform.Equals("hyyn")) |
| | | // { |
| | | // ChannelPlatform = E_ChannelPlatform.newyn; |
| | | // } |
| | | // else if (_channelPlatform.Equals("hygtgame")) |
| | | // { |
| | | // ChannelPlatform = E_ChannelPlatform.hygt; |
| | | // } |
| | | // else if (_channelPlatform.Equals("hyenglish")) |
| | | // { |
| | | // ChannelPlatform = E_ChannelPlatform.en; |
| | | // } |
| | | // } |
| | | // } |
| | | break; |
| | | case CodeA2U.SdkInitComplete: |
| | | InitFinished = true; |
| | | var _dict = _json as IDictionary; |
| | | if (_dict != null && _dict.Contains("channelPlatform")) |
| | | { |
| | | var _channelPlatform = _json["channelPlatform"].ToString(); |
| | | if (!string.IsNullOrEmpty(_channelPlatform)) |
| | | { |
| | | if (_channelPlatform.Equals("hygame")) |
| | | { |
| | | ChannelPlatform = E_ChannelPlatform.Hy; |
| | | } |
| | | else if (_channelPlatform.Equals("quick")) |
| | | { |
| | | ChannelPlatform = E_ChannelPlatform.Quick; |
| | | } |
| | | |
| | | // //Sdk 可能会修改渠道信息,所以需要重新获取 |
| | | // if (_dict.Contains("yj_appid")) |
| | | // { |
| | | // Yj_AppID = _json["yj_appid"].ToString(); |
| | | // } |
| | | } |
| | | } |
| | | |
| | | // if (_dict.Contains("yj_spid")) |
| | | // { |
| | | // Yj_SpID = _json["yj_spid"].ToString(); |
| | | // } |
| | | //Sdk 可能会修改渠道信息,所以需要重新获取 |
| | | if (_dict.Contains("yj_appid")) |
| | | { |
| | | Yj_AppID = _json["yj_appid"].ToString(); |
| | | } |
| | | |
| | | // if (_dict.Contains("banhao")) |
| | | // { |
| | | // Yj_BanHao = _json["banhao"].ToString(); |
| | | // } |
| | | if (_dict.Contains("yj_spid")) |
| | | { |
| | | Yj_SpID = _json["yj_spid"].ToString(); |
| | | } |
| | | |
| | | // break; |
| | | // case CodeA2U.PushClientID: |
| | | // RegistrationID = _json["clientID"].ToString(); |
| | | // break; |
| | | // case CodeA2U.ExternalStorage: |
| | | // DeviceRootPath = _json["path"].ToString(); |
| | | // break; |
| | | // case CodeA2U.PermissionCallBack: |
| | | // { |
| | | // var state = (int)_json["state"]; |
| | | // var permission = (string)_json["permission"]; |
| | | // onPermissionCallBack?.Invoke(permission, state); |
| | | // onPermissionCallBack = null; |
| | | // break; |
| | | // } |
| | | // case CodeA2U.FreePlatformInitOk: |
| | | if (_dict.Contains("banhao")) |
| | | { |
| | | Yj_BanHao = _json["banhao"].ToString(); |
| | | } |
| | | |
| | | // if (onFreePlatformInitOk != null) |
| | | // { |
| | | // onFreePlatformInitOk(); |
| | | // } |
| | | break; |
| | | case CodeA2U.PushClientID: |
| | | RegistrationID = _json["clientID"].ToString(); |
| | | break; |
| | | case CodeA2U.ExternalStorage: |
| | | DeviceRootPath = _json["path"].ToString(); |
| | | break; |
| | | case CodeA2U.PermissionCallBack: |
| | | { |
| | | var state = (int)_json["state"]; |
| | | var permission = (string)_json["permission"]; |
| | | onPermissionCallBack?.Invoke(permission, state); |
| | | onPermissionCallBack = null; |
| | | break; |
| | | } |
| | | case CodeA2U.FreePlatformInitOk: |
| | | |
| | | // break; |
| | | // case CodeA2U.FreePlatformInitFail: |
| | | // if (onFreePlatformInitFail != null) |
| | | // { |
| | | // onFreePlatformInitFail(); |
| | | // } |
| | | // break; |
| | | // case CodeA2U.FreePlatformRegisterOk: |
| | | // // HandleFreePlatformRegisteOk(_json); |
| | | if (onFreePlatformInitOk != null) |
| | | { |
| | | onFreePlatformInitOk(); |
| | | } |
| | | |
| | | break; |
| | | case CodeA2U.FreePlatformInitFail: |
| | | if (onFreePlatformInitFail != null) |
| | | { |
| | | onFreePlatformInitFail(); |
| | | } |
| | | break; |
| | | case CodeA2U.FreePlatformRegisterOk: |
| | | // HandleFreePlatformRegisteOk(_json); |
| | | // OperationLogCollect.Instance.RecordEvent(5); |
| | | // var values = new JsonData(); |
| | | // if (_json.Keys.Contains("reg_type")) |
| | | // values["af_registration_method"] = _json["reg_type"]; |
| | | // break; |
| | | // case CodeA2U.FreePlatformLoginOk: |
| | | // HandleFreePlatformLoginOk(_json["info"]); |
| | | var values = new JsonData(); |
| | | if (_json.Keys.Contains("reg_type")) |
| | | values["af_registration_method"] = _json["reg_type"]; |
| | | break; |
| | | case CodeA2U.FreePlatformLoginOk: |
| | | HandleFreePlatformLoginOk(_json["info"]); |
| | | // OperationLogCollect.Instance.RecordEvent(6); |
| | | // break; |
| | | // case CodeA2U.FreePlatformLoginFail: |
| | | // if (onFreePlatformLoginFail != null) |
| | | // { |
| | | // onFreePlatformLoginFail(); |
| | | // } |
| | | // break; |
| | | // case CodeA2U.FreePlatformLogoutOk: |
| | | // if (onFreePlatformLogoutOk != null) |
| | | // { |
| | | // onFreePlatformLogoutOk(); |
| | | // } |
| | | // FreePlatformInfo = null; |
| | | // break; |
| | | // case CodeA2U.FreePlatformSwitchAccountOk: |
| | | // BuildFreePlatformInfo(_json["info"]); |
| | | // if (onFreePlatformLogoutOk != null) |
| | | // { |
| | | // onFreePlatformLogoutOk(); |
| | | // } |
| | | // FreePlatformInfo = null; |
| | | // break; |
| | | // case CodeA2U.FreePlatformLogoutFail: |
| | | // if (onFreePlatformLogoutFail != null) |
| | | // { |
| | | // onFreePlatformLogoutFail(); |
| | | // } |
| | | // break; |
| | | // case CodeA2U.FreePlatformPayOk: |
| | | // if (onFreePlatformPayOk != null) |
| | | // { |
| | | // onFreePlatformPayOk(); |
| | | // } |
| | | // //SnxxzGame.Instance.StartCoroutine(DelayQueryRecharge()); |
| | | // break; |
| | | // case CodeA2U.FreePlatformPayFail: |
| | | // if (onFreePlatformPayFail != null) |
| | | // { |
| | | // onFreePlatformPayFail(); |
| | | // } |
| | | // break; |
| | | // case CodeA2U.FreePlatformPayCancel: |
| | | // if (onFreePlatformPayCancel != null) |
| | | // { |
| | | // onFreePlatformPayCancel(); |
| | | // } |
| | | // break; |
| | | // case CodeA2U.ShareCallBack: |
| | | // { |
| | | // var state = int.Parse(_json["state"].ToString()); |
| | | // if (state == CallBackState.Success) |
| | | // LocalSave.SetInt("ShareToFBDay" + PlayerDatas.Instance.baseData.PlayerID, TimeUtility.ServerNow.DayOfYear); |
| | | break; |
| | | case CodeA2U.FreePlatformLoginFail: |
| | | if (onFreePlatformLoginFail != null) |
| | | { |
| | | onFreePlatformLoginFail(); |
| | | } |
| | | break; |
| | | case CodeA2U.FreePlatformLogoutOk: |
| | | if (onFreePlatformLogoutOk != null) |
| | | { |
| | | onFreePlatformLogoutOk(); |
| | | } |
| | | FreePlatformInfo = null; |
| | | break; |
| | | case CodeA2U.FreePlatformSwitchAccountOk: |
| | | BuildFreePlatformInfo(_json["info"]); |
| | | if (onFreePlatformLogoutOk != null) |
| | | { |
| | | onFreePlatformLogoutOk(); |
| | | } |
| | | FreePlatformInfo = null; |
| | | break; |
| | | case CodeA2U.FreePlatformLogoutFail: |
| | | if (onFreePlatformLogoutFail != null) |
| | | { |
| | | onFreePlatformLogoutFail(); |
| | | } |
| | | break; |
| | | case CodeA2U.FreePlatformPayOk: |
| | | if (onFreePlatformPayOk != null) |
| | | { |
| | | onFreePlatformPayOk(); |
| | | } |
| | | //SnxxzGame.Instance.StartCoroutine(DelayQueryRecharge()); |
| | | break; |
| | | case CodeA2U.FreePlatformPayFail: |
| | | if (onFreePlatformPayFail != null) |
| | | { |
| | | onFreePlatformPayFail(); |
| | | } |
| | | break; |
| | | case CodeA2U.FreePlatformPayCancel: |
| | | if (onFreePlatformPayCancel != null) |
| | | { |
| | | onFreePlatformPayCancel(); |
| | | } |
| | | break; |
| | | case CodeA2U.ShareCallBack: |
| | | { |
| | | var state = int.Parse(_json["state"].ToString()); |
| | | if (state == CallBackState.Success) |
| | | LocalSave.SetInt("ShareToFBDay" + PlayerDatas.Instance.baseData.PlayerID, TimeUtility.ServerNow.DayOfYear); |
| | | |
| | | // onShareFBResult?.Invoke(); |
| | | // break; |
| | | // } |
| | | // case CodeA2U.ExitGame: |
| | | // if (ChannelPlatform == E_ChannelPlatform.Free) |
| | | // { |
| | | onShareFBResult?.Invoke(); |
| | | break; |
| | | } |
| | | case CodeA2U.ExitGame: |
| | | if (ChannelPlatform == E_ChannelPlatform.Free) |
| | | { |
| | | // WindowCenter.Instance.Open<ExitGameWin>(); |
| | | // } |
| | | // else |
| | | // { |
| | | // //默认都是退出游戏 |
| | | // Application.Quit(); |
| | | // } |
| | | // break; |
| | | // } |
| | | // onSdkMsg?.Invoke(_code, _json); |
| | | } |
| | | else |
| | | { |
| | | //默认都是退出游戏 |
| | | Application.Quit(); |
| | | } |
| | | break; |
| | | } |
| | | onSdkMsg?.Invoke(_code, _json); |
| | | } |
| | | |
| | | #endregion |