| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Reflection;
- using UnityEngine;
- public partial class SDKMgr : MonoBehaviour
- {
- internal string httpCheckUrl = string.Empty;
- internal GameObject sdkMgrObj;
- private string sDKName = "";
- public void SetHttpCheckUrl(string value)
- {
- if (!string.IsNullOrEmpty(value))
- {
- httpCheckUrl = value;
- }
- }
- protected static SDKMgr instance;
- public static SDKMgr Instance
- {
- get
- {
- if (instance == null)
- {
- //初次调用时,因为java回调需要一个实例对象,
- GameObject a = new GameObject("SDKMgr");
- instance = a.AddComponent<SDKMgr>();
- DontDestroyOnLoad(a);
- }
- return instance;
- }
- }
- public SDKBase sdk;
- private ISDKCallBack listener;
- //TODO:后续将与回调一样的写法
- private SDKReportBase m_SDKReport;
- public SDKReportBase SDKReport
- {
- get
- {
- #if UNITY_ANDROID && NTSDK && !UNITY_EDITOR
- if (m_SDKReport == null)
- {
- m_SDKReport = new NTReport();
- }
- #endif
- return m_SDKReport;
- }
- }
- /// <summary>
- /// sdk初始化 同时初始化回调事件 需要在初始化完成后在回调方法中设置初始化状态为true
- /// </summary>
- public void Init()
- {
- if (sdk == null)
- {
- #if UNITY_EDITOR || NULLSDK
- //listener = new NULLSDKCBListener();
- sdk = new NULLSDKAndroid();
- //sdk.Init(listener, "");
- //#elif UNITY_ANDROID && NBSDK
- // listener = new NBSDKCBListener();
- // sdk = new NBSDKAndroid();
- // sdk.Init(listener , "SDKNB");
- //#elif UNITY_ANDROID && NTSDK
- // listener = new NTSDKCBListener();
- // sdk = new NTSDKAndroid();
- // sdk.Init(listener, "SDKUni");
- #else
- var types = Assembly.GetExecutingAssembly().GetTypes();
- var baseType = typeof(SDKBase);
- List<SDKBase> processors = new List<SDKBase>();
- foreach (var t in types)
- {
- var tmp = t.BaseType;
- while (tmp != null)
- {
- if (tmp == baseType && Type.GetType(t.FullName, true) != typeof(NULLSDKAndroid))
- {
- //Debug.Log(t.BaseType);
- SDKBase obj = MethodMaker.CreateObject(t.FullName) as SDKBase;
- if (obj != null)
- {
- processors.Add(obj);
- sdk = obj;
- }
- break;
- }
- else
- {
- tmp = tmp.BaseType;
- }
- }
- }
- #endif
- }
- if (sdk == null)
- return;
-
- if (!string.IsNullOrEmpty(sDKName))
- {
- sdk.SDKName= sDKName;
- }
- if (sdk.GetInited())
- {
- sdk.CallInitSuccessCB();
- }
- else
- {
- sdk.Init();
- }
- }
- public void SetSDKName(string name)
- {
- sDKName = name;
- //Debug.Log(name);
- }
- private void OnApplicationFocus(bool focusStatus)
- {
- if (sdk == null) return;
- sdk.OnApplicationFocus(focusStatus);
- }
- /// <summary>
- /// sdk登录 登陆后需要在回调中设置登陆状态为true
- /// </summary>
- public void Login()
- {
- ReportLoginUI(GetInt64TimeStamp());
- if (sdk == null) return;
- if (sdk.GetLogined())
- {
- sdk.CallLoginSuccessCB();
- return;
- }
- sdk.Login();
- }
- public void Logout()
- {
-
- if (sdk == null) return;
-
- sdk.Logout();
- }
- public void Pay(int goodsId, string goodsName, string goodsDesc,
- int count, float amount,
- string cpOrderId, string extrasParams)
- {
- if (sdk == null) return;
- if (m_GameRoleInfo == null) return;
- OrderExtraInfo data = new OrderExtraInfo()
- {
- subPlatform = GetChannelName(),
- serverId = m_GameRoleInfo.serverId,
- platform = ((sdk == null || string.IsNullOrEmpty(sdk.SDKName)) ? "" : sdk.SDKName),
- };
- try
- {
-
- string extraParams = JsonUtility.ToJson(data);
- sdk.Pay(goodsId, goodsName, goodsDesc,
- count, amount,
- cpOrderId, extraParams);
- }
- catch (Exception e)
- {
- Debug.LogException(e);
- Debug.LogError("Pay Fail");
- }
- }
- public void EnterGame()
- {
- SyncInfoToFairGuard();
- SyncInfoToBugly();
- if (sdk == null) return;
- sdk.EnterGame();
- }
- public void CreateRole()
- {
- if (sdk == null) return;
- sdk.CreateRole();
- }
- public void ExitGame()
- {
- if (sdk == null) return;
- sdk.ExitGame();
- }
- public void UpdateRoleLv()
- {
- if (sdk == null) return;
- sdk.UpdateRoleLv();
- }
- public void SwitchAccount()
- {
- if (sdk == null) return;
- sdk.SwitchAccount();
- }
- public bool Exit()
- {
- if (sdk == null) return false;
- return sdk.Exit();
- }
- public bool Quit()
- {
- if (sdk == null) return false;
- return sdk.Quit();
- }
- public bool IsReportAction()
- {
- if (sdk == null) return false;
- return sdk.IsReportAction();
- }
- public void ReportAction(Dictionary<object, object> datas)
- {
- if (sdk == null) return;
- sdk.ReportAction(datas);
- }
- public string GetSDKName()
- {
- if (sdk == null) return "";
- return sdk.GetSDKName();
- }
- public void SetLogined(bool value)
- {
- if (sdk == null) return;
- sdk.SetLogined(value);
- }
- /// <summary>
- /// 设置sdk的初始化状态显示
- /// </summary>
- /// <param name="value"></param>
- public void SetInited(bool value)
- {
- if (sdk == null) return;
- sdk.SetInited(value);
- }
- /// <summary>
- /// 获取sdk的登陆状态
- /// </summary>
- /// <returns></returns>
- public bool GetLogined()
- {
- if (sdk == null) return false;
- return sdk.GetLogined();
- }
- /// <summary>
- /// 获取sdk的初始化状态
- /// </summary>
- /// <returns></returns>
- public bool GetInited()
- {
- if (sdk == null) return false;
- return sdk.GetInited();
- }
- /// <summary>
- /// 检查屏蔽言论,具体需要的逻辑由各sdk内部重写
- /// </summary>
- /// <param name="level">玩家等级</param>
- /// <param name="channel">聊天频道</param>
- /// <param name="cont">言论内容</param>
- /// <returns></returns>
- public bool CheckSpeech(string level, ChannelType channel, string cont)
- {
- if (sdk == null) return true;
- return sdk.EnvReviewLan(level, channel.ToString(), cont);
- }
- /// <summary>
- /// 检查屏蔽昵称,具体需要的逻辑由各sdk内部重写
- /// </summary>
- /// <param name="name"></param>
- /// <returns></returns>
- public bool CheckName(string name)
- {
- if (sdk == null) return true;
- return sdk.EnvReviewName(name);
- }
- /// <summary>
- /// 此为服务器回的信息的解码,具体需要的逻辑由各sdk内部重写
- /// </summary>
- /// <param name="code"></param>
- public void Decode(string code)
- {
- if (sdk == null) return;
- sdk.Decode(code);
- }
- /// <summary>
- /// 检查sdk中是否包含此功能模块,用于判断游戏中是否需要打开UI
- /// </summary>
- /// <param name="needCheckModulType"></param>
- /// <returns></returns>
- public bool CheckHasModul(SDKModulType needCheckModulType)
- {
- if (sdk == null) return false;
- return sdk.CheckHasModul(needCheckModulType);
- }
- /// <summary>
- /// 用于游戏内的UI打开SDK中的功能模块
- /// </summary>
- public void OpenModul(SDKModulType sDKModulType)
- {
- if (sdk == null) return;
- sdk.OpenModul(sDKModulType);
- }
- /// <summary>
- /// 打开sdk中的网页
- /// </summary>
- /// <param name="url">网址</param>
- public void OpenWebview(string url)
- {
- if (sdk == null) return;
- sdk.OpenWebview(url);
- }
- /// <summary>
- /// 打开客服页面
- /// </summary>
- public void OpenGM()
- {
- if (sdk == null) return;
- sdk.OpenGM();
- }
- /// <summary>
- /// 关闭客服页面
- /// </summary>
- public void CloseGM()
- {
- if (sdk == null) return;
- sdk.CloseGM();
- }
- ///// <summary>
- ///// 打开实名认证倒计时
- ///// </summary>
- //public void OpenRealNameCountDown()
- //{
- // if (sdk == null) return;
- // sdk.OpenReakNameCountDown();
- //}
- ///// <summary>
- ///// 关闭实名认证倒计时
- ///// </summary>
- //public void CloseRealNameCountDown()
- //{
- // if (sdk == null) return;
- // sdk.CloseRealNameCountDown();
- //}
- /// <summary>
- /// 打开用户协议
- /// </summary>
- /// <param name="showState">false 为一次性 true 为可无限打开</param>
- public void OpenCompactView(bool showState)
- {
- if (sdk == null) return;
- sdk.OpenCompactView(showState);
- }
- public bool HasCanEnterServerJudge()
- {
- if (sdk == null) return false;
- return sdk.HasCanEnterServerJudge();
- }
- public void CanEnterServerJudge(string serverId, string serverName)
- {
- if (sdk == null) return;
- sdk.CanEnterServerJudge(serverId, serverName);
- }
- public Int64 GetInt64TimeStamp()
- {
- return DateTime.Now.Ticks;
- }
- private string m_ChannelName = string.Empty;
- public string GetChannelName()
- {
- if (string.IsNullOrEmpty(m_ChannelName))
- {
- m_ChannelName = "";//Wenting.Lebian.LeBianSDK.instance.GetClientChId();
- }
- return m_ChannelName;
- }
- private DeviceSystemData m_DeviceSystemData;
- public DeviceSystemData GetDeviceSystemData()
- {
- if (sdk == null) return null;
- DeviceSystemData deviceSystemData = sdk.GetDeviceSystemData();
- if (deviceSystemData != null)
- {
- return deviceSystemData;
- }
- if (m_DeviceSystemData == null)
- {
- m_DeviceSystemData = new DeviceSystemData()
- {
- deviceModel = SystemInfo.deviceModel,
- // deviceWidth = 0,
- // deviceHeight = 0,
- osName = SystemInfo.operatingSystemFamily.ToString(),
- osVer = SystemInfo.operatingSystem,
- // macAddr = "",
- // udid = "",
- // isp = "",
- // network = "",
- // appChannel = "",
- // appVer = "",
- // transId = "",
- deviceId = SystemInfo.deviceUniqueIdentifier,
- // isEmulator = 0,
- // isRoot = 0,
- // accountId = "",
- // oldAccountId = "",
- // imei = "",
- // countryCode = "",
- // oaid = "",
- engineVer = Application.unityVersion,
- };
- }
- return m_DeviceSystemData;
- }
- private GameRoleInfo m_GameRoleInfo;
- public GameRoleInfo GetGameRoleInfo()
- {
- if (sdk == null && SDKReport == null) return null;
- if (m_GameRoleInfo == null)
- {
- m_GameRoleInfo = new GameRoleInfo();
- }
- return m_GameRoleInfo;
- }
- private class FairGuardData
- {
- public string openId;
- public string subPlatform;
- public int serverId;
- public string serverName;
- public string roleId;
- public string deviceId;
- public string platform;
- }
- private void SyncInfoToFairGuard()
- {
- #if FAIR_GUARD
- if (m_GameRoleInfo != null)
- {
- DeviceSystemData systemData = GetDeviceSystemData();
- FairGuardData data = new FairGuardData()
- {
- openId = m_GameRoleInfo.openId,
- subPlatform = GetChannelName(),
- serverId = m_GameRoleInfo.serverId,
- serverName = m_GameRoleInfo.serverName,
- roleId = m_GameRoleInfo.roleId,
- deviceId = (systemData != null ? systemData.deviceId : SystemInfo.deviceUniqueIdentifier),
- platform = ((sdk == null || string.IsNullOrEmpty(sdk.SDKName)) ? "" : sdk.SDKName),
- };
- string extraStr = JsonUtility.ToJson(data);
- FairGuard.Init();
- FairGuard.setUserInfoEx(m_GameRoleInfo.roleName, m_GameRoleInfo.openId, m_GameRoleInfo.roleId, m_GameRoleInfo.serverName, GetChannelName(), extraStr);
- }
- #endif
- }
- private void SyncInfoToBugly()
- {
- #if BUGLY
- if (m_GameRoleInfo == null) return;
- string userId = "";
- if (!string.IsNullOrEmpty (m_GameRoleInfo.openId))
- {
- userId = userId + m_GameRoleInfo.openId;
- }
- userId = userId + "_" + m_GameRoleInfo.serverId;
- BuglyAgent.SetUserId (userId);
- #endif
- }
- public class ProductInfo
- {
- public string ID;
- public string Name;
- public string CID;
- public string Other;
- }
- public Dictionary<string, ProductInfo> ProductInfos = new Dictionary<string, ProductInfo>()
- {
- { "0.99",new ProductInfo(){ CID = "1",Name = "0.99禮包"} },
- { "1.99",new ProductInfo(){ CID = "2",Name = "1.99禮包"} },
- { "2.99",new ProductInfo(){ CID = "3",Name = "2.99禮包"} },
- { "4.99",new ProductInfo(){ CID = "4",Name = "4.99禮包"} },
- { "9.99",new ProductInfo(){ CID = "5",Name = "9.99禮包"} },
- { "14.99",new ProductInfo(){ CID = "6",Name = "14.99禮包"} },
- { "19.99",new ProductInfo(){ CID = "7",Name = "19.99禮包"} },
- { "49.99",new ProductInfo(){ CID = "8",Name = "49.99禮包"} },
- { "99.99",new ProductInfo(){ CID = "9",Name = "99.99禮包"} },
- };
- public void InitProductCfg(Dictionary<string, Dictionary<string, string>> cfg)
- {
- foreach (var item in cfg)
- {
- string id = item.Key;
- string pid = item.Value["productID"];
- string name = item.Value["productName"];
- string amount = item.Value["amount"];
- string other = item.Value["other"];
- if (ProductInfos.ContainsKey(amount))
- {
- ProductInfos[amount].ID = pid;
- ProductInfos[amount].Name = name;
- ProductInfos[amount].Other = other;
- }
- else
- {
- ProductInfos.Add(amount, new ProductInfo()
- {
- ID= pid,
- CID = id,
- Name = name,
- Other = other,
- });
- // Debug.Log($"===== 添加 商品配置 {name} ====== 价格 = {amount}");
- }
- //Debug.Log($"===== 商品配置 {name} ====== 价格 = {amount}");
- }
- }
- }
- public class MethodMaker
- {
- /// <summary>
- /// 创建对象(当前程序集)
- /// </summary>
- /// <param name="typeName">类型名</param>
- /// <returns>创建的对象,失败返回 null</returns>
- public static object CreateObject(string typeName)
- {
- object obj = null;
- try
- {
- Type objType = Type.GetType(typeName, true);
- obj = Activator.CreateInstance(objType);
- }
- catch (Exception ex)
- {
- Debug.Log(ex);
- }
- return obj;
- }
- /// <summary>
- /// 创建对象(外部程序集)
- /// </summary>
- /// <param name="path"></param>
- /// <param name="typeName">类型名</param>
- /// <returns>创建的对象,失败返回 null</returns>
- public static object CreateObject(string path, string typeName)
- {
- object obj = null;
- try
- {
- obj = Assembly.Load(path).CreateInstance(typeName);
- }
- catch (Exception ex)
- {
- //Debug.Write(ex);
- }
- return obj;
- }
- }
|