123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269 |
- using FrameWork;
- using FrameWork.SDKManager;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Reflection;
- using UnityEngine;
- namespace FrameWork.SDKManager
- {
- public static class SDKManager
- {
- static bool isInit = false;
- #if UNITY_ANDROID
- public const string c_ConfigName = "SDKConfig_Android";
- #elif UNITY_IOS
- public const string c_ConfigName = "SDKConfig_IOS";
- #else
- public const string c_ConfigName = "SDKConfig";
- #endif
- public const string c_KeyName = "SDKInfo";
- static List<LoginInterface> s_loginServiceList = null;
- static List<PayInterface> s_payServiceList = null;
- static List<ADInterface> s_ADServiceList = null;
- static List<LogInterface> s_logServiceList = null;
- static List<OtherSDKInterface> s_otherServiceList = null;
- private static PayCallBack s_payCallBack;
- private static ADCallBack s_adCallBack;
- static Dictionary<string, OtherCallBack> s_callBackDict = new Dictionary<string, OtherCallBack>();
- static bool s_useNewSDKManager = false; //是否使用新版本SDKManager
- #region 属性
- public static LoginCallBack LoginCallBack { get; set; }
- public static PayCallBack PayCallBack
- {
- get
- {
- return s_payCallBack;
- }
- set
- {
- s_payCallBack = value;
- }
- }
- public static ADCallBack ADCallBack
- {
- get
- {
- return s_adCallBack;
- }
- set
- {
- s_adCallBack = value;
- }
- }
- #endregion
- #region 外部调用
- #region 初始化
- /// <summary>
- /// 初始化
- /// </summary>
- public static void Init()
- {
- if (!isInit)
- {
- isInit = true;
- try
- {
- if (ConfigManager.GetIsExistConfig(c_ConfigName))
- {
- SchemeData data = LoadGameSchemeConfig();
- s_useNewSDKManager = data.UseNewSDKManager;
- if (s_useNewSDKManager)
- {
- SDKManagerNew.Init();
- }
- Debug.Log("SDKManager Init");
- LoadService(data);
- InitSDK();
- AutoListenerInit();
- }
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Init Exception: " + e.ToString());
- }
- }
- }
- /// <summary>
- /// 额外初始化,SDKName == null时初始化全体
- /// </summary>
- public static void ExtraInit(SDKType type, string sdkName = null, string tag = null)
- {
- if (sdkName != null)
- {
- switch (type)
- {
- case SDKType.AD:
- GetADService(sdkName).ExtraInit(tag); break;
- case SDKType.Log:
- GetLogService(sdkName).ExtraInit(tag); break;
- case SDKType.Login:
- GetLoginService(sdkName).ExtraInit(tag); break;
- case SDKType.Other:
- GetOtherService(sdkName).ExtraInit(tag); break;
- case SDKType.Pay:
- GetPayService(sdkName).ExtraInit(tag); break;
- }
- }
- else
- {
- switch (type)
- {
- case SDKType.AD:
- AllExtraInit(s_ADServiceList, tag); break;
- case SDKType.Log:
- AllExtraInit(s_logServiceList, tag); break;
- case SDKType.Login:
- AllExtraInit(s_loginServiceList, tag); break;
- case SDKType.Other:
- AllExtraInit(s_otherServiceList, tag); break;
- case SDKType.Pay:
- AllExtraInit(s_payServiceList, tag); break;
- }
- }
- }
- static void AllExtraInit<T>(List<T> list, string tag = null) where T : SDKInterfaceBase
- {
- for (int i = 0; i < list.Count; i++)
- {
- try
- {
- list[i].ExtraInit(tag);
- }
- catch (Exception e)
- {
- Debug.LogError("AllExtraInit Exception " + list[i].m_SDKName + " " + e.ToString());
- }
- }
- }
- static void CheckInit()
- {
- if(!isInit)
- {
- throw new Exception("SDKManager not init !");
- }
- }
- #endregion
- #region 获取SDKInterface
- public static LoginInterface GetLoginService<T>() where T : LoginInterface
- {
- return GetLoginService(typeof(T).Name);
- }
- public static LoginInterface GetLoginService(string SDKName)
- {
- return GetSDKService(s_loginServiceList, SDKName);
- }
- public static LoginInterface GetLoginService(int index)
- {
- if (s_loginServiceList.Count <= index)
- {
- throw new Exception("GetLoginService error index->" + index + " count->" + s_loginServiceList.Count);
- }
- return s_loginServiceList[index];
- }
- public static PayInterface GetPayService<T>() where T : PayInterface
- {
- return GetPayService(typeof(T).Name);
- }
- public static PayInterface GetPayService(string SDKName)
- {
- return GetSDKService(s_payServiceList, SDKName);
- }
- public static PayInterface GetPayService(int index)
- {
- if (s_payServiceList.Count <= index)
- {
- throw new Exception("GetPayService error index->" + index + " count->" + s_payServiceList.Count);
- }
- return s_payServiceList[index];
- }
- public static ADInterface GetADService<T>() where T : ADInterface
- {
- return GetADService(typeof(T).Name);
- }
- public static ADInterface GetADService(string SDKName)
- {
- return GetSDKService(s_ADServiceList, SDKName);
- }
- public static ADInterface GetADService(int index)
- {
- if (s_ADServiceList.Count <= index)
- {
- throw new Exception("GetADService error index->" + index + " count->" + s_ADServiceList.Count);
- }
- return s_ADServiceList[index];
- }
- public static LogInterface GetLogService<T>() where T : LogInterface
- {
- return GetLogService(typeof(T).Name);
- }
- public static LogInterface GetLogService(string SDKName)
- {
- return GetSDKService(s_logServiceList, SDKName);
- }
- public static LogInterface GetLogService(int index)
- {
- if (s_logServiceList.Count <= index)
- {
- throw new Exception("GetLogService error index->" + index + " count->" + s_logServiceList.Count);
- }
- return s_logServiceList[index];
- }
- public static OtherSDKInterface GetOtherService<T>() where T : OtherSDKInterface
- {
- return GetOtherService(typeof(T).Name);
- }
- public static OtherSDKInterface GetOtherService(string SDKName)
- {
- return GetSDKService(s_otherServiceList, SDKName);
- }
- public static OtherSDKInterface GetOtherService(int index)
- {
- if (s_otherServiceList.Count <= index)
- {
- throw new Exception("GetOtherService error index->" + index + " count->" + s_otherServiceList.Count);
- }
- return s_otherServiceList[index];
- }
- #endregion
- #region 登录
- static void InitLogin(List<LoginInterface> list)
- {
- for (int i = 0; i < list.Count; i++)
- {
- try
- {
- //list[i].m_SDKName = list[i].GetType().Name;
- list[i].Init();
- //s_loginCallBack += list[i].m_callBack;
- }
- catch (Exception e)
- {
- Debug.LogError("Init LoginInterface SDK Exception:\n" + e.ToString());
- }
- }
- }
- /// <summary>
- /// 登陆,默认访问第一个接口
- /// </summary>
- public static void Login(string tag = "")
- {
- if (s_useNewSDKManager)
- {
- SDKManagerNew.Login();
- }
- else
- {
- try
- {
- GetLoginService(0).Login(tag);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Login Exception: " + e.ToString());
- }
- }
- }
- /// <summary>
- /// 登陆
- /// </summary>
- public static void LoginBySDKName(string SDKName, string tag = "")
- {
- if (s_useNewSDKManager)
- {
- SDKManagerNew.Login(SDKName, tag);
- }
- else
- {
- try
- {
- GetLoginService(SDKName).Login(tag);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Login Exception: " + SDKName + "===" + e.ToString());
- }
- }
- }
- /// <summary>
- /// 登陆
- /// </summary>
- public static void LoginByPlatform(LoginPlatform loginPlatform, string tag = "")
- {
- try
- {
- bool isHave = false;
- foreach (var item in s_loginServiceList)
- {
- if (item.GetPlatform().Contains(Application.platform) && item.GetLoginPlatform() == loginPlatform)
- {
- item.Login(tag);
- isHave = true;
- }
- }
- if (!isHave)
- {
- if (s_useNewSDKManager)
- {
- SDKManagerNew.Login(loginPlatform.ToString(), tag);
- }
- else
- {
- Debug.LogError("SDKManager Login dont find class by platform:" + Application.platform + " loginPlatform:" + loginPlatform);
- }
- }
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Login Exception: " + e.ToString());
- }
- }
- public static List<LoginPlatform> GetSupportLoginPlatform()
- {
- List<LoginPlatform> platforms = new List<LoginPlatform>();
- try
- {
- foreach (var item in s_loginServiceList)
- {
- if (item.GetPlatform().Contains(Application.platform))
- {
- platforms.Add(item.GetLoginPlatform());
- }
- }
- if (s_useNewSDKManager)
- {
- List<LoginPlatform> newList = SDKManagerNew.GetSupportLoginPlatform();
- for (int i = 0; i < newList.Count; i++)
- {
- if (!platforms.Contains(newList[i]))
- {
- platforms.Add(newList[i]);
- }
- }
- }
- if (platforms.Count == 0)
- {
- Debug.LogError("SDKManager Login dont find class by platform:" + Application.platform + " please check config");
- }
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Login Exception: " + e.ToString());
- }
- return platforms;
- }
- #endregion
- #region 支付
- static void InitPay(List<PayInterface> list)
- {
- for (int i = 0; i < list.Count; i++)
- {
- try
- {
- //list[i].m_SDKName = list[i].GetType().Name;
- list[i].Init();
- //list[i].m_PayResultCallBack= s_payCallBack;
- Debug.Log("初始化支付回调");
- }
- catch (Exception e)
- {
- Debug.LogError("Init PayInterface SDK Exception:\n" + e.ToString());
- }
- }
- }
- /// <summary>
- /// 支付,默认访问第一个接口
- /// </summary>
- public static void Pay(PayInfo payInfo)
- {
- //优先使用本地配置的SDK
- if (s_payServiceList.Count > 0)
- {
- try
- {
- GetPayService(0).Pay(payInfo.goodsID, payInfo.tag);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Pay Exception: " + e.ToString());
- }
- }
- else if (s_useNewSDKManager)
- {
- SDKManagerNew.Pay(payInfo);
- }
- else
- {
- Debug.Log("支付SDK 没有配置! ");
- }
- }
- /// <summary>
- /// 支付
- /// </summary>
- public static void Pay(string SDKName, PayInfo payInfo )
- {
- Debug.Log("Pay SDKname " + SDKName + " GetHasSDKService " + GetHasSDKService(s_payServiceList, SDKName));
- //优先使用本地配置的SDK
- if (GetHasSDKService(s_payServiceList, SDKName))
- {
- try
- {
- GetPayService(SDKName).Pay(payInfo.goodsID, payInfo.tag);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Pay Exception: " + e.ToString());
- }
- }
- else if (s_useNewSDKManager)
- {
- SDKManagerNew.Pay(SDKName, payInfo);
- }
- else
- {
- Debug.LogError("支付SDK 没有配置! ");
- }
- }
- /// <summary>
- /// 支付,默认访问第一个接口
- /// </summary>
- public static void ConfirmPay(string orderID, string tag = "")
- {
- try
- {
- GetPayService(0).ConfirmPay(orderID, tag);
-
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Pay Exception: " + e.ToString());
- }
- }
- /// <summary>
- /// 支付
- /// </summary>
- public static void ConfirmPay(string SDKName, string orderID, string tag = "")
- {
- try
- {
- GetPayService(SDKName).ConfirmPay(orderID, tag);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Pay Exception: " + e.ToString());
- }
- }
- public static LocalizedGoodsInfo GetGoodsInfo(string goodsID, string tag = "")
- {
- try
- {
- return GetPayService(0).GetGoodsInfo(goodsID);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager GetGoodsInfo Exception: " + e.ToString());
- }
- return null;
- }
- public static LocalizedGoodsInfo GetGoodsInfo(string SDKName, string goodsID, string tag = "")
- {
- try
- {
- return GetPayService(SDKName).GetGoodsInfo(goodsID);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager GetGoodsInfo Exception: " + e.ToString());
- }
- return null;
- }
- public static List<LocalizedGoodsInfo> GetAllGoodsInfo(string tag = "")
- {
- try
- {
- return GetPayService(0).GetAllGoodsInfo();
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager GetGoodsInfo Exception: " + e.ToString());
- }
- return null;
- }
- public static List<LocalizedGoodsInfo> GetAllGoodsInfo(string SDKName, string tag = "")
- {
- try
- {
- return GetPayService(SDKName).GetAllGoodsInfo();
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager GetGoodsInfo Exception: " + e.ToString());
- }
- return null;
- }
- #endregion
- #region 广告
- /// <summary>
- /// 加载广告,默认访问第一个接口
- /// </summary>
- public static void LoadAD(ADType adType, string tag = "")
- {
- if (s_ADServiceList.Count > 0)
- {
- GetADService(0).LoadAD(adType, tag);
- }
- else
- {
- if (s_useNewSDKManager)
- {
- SDKManagerNew.LoadAD(adType, tag);
- }
- else
- {
- Debug.LogError("SDKManager LoadAD s_ADServiceList count is 0");
- }
- }
- }
- /// <summary>
- /// 加载广告
- /// </summary>
- public static void LoadAD(string SDKName, ADType adType, string tag = "")
- {
- if (s_useNewSDKManager)
- {
- SDKManagerNew.LoadAD(SDKName, adType, tag);
- }
- else
- {
- try
- {
- GetADService(SDKName).LoadAD(adType, tag);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager LoadAD Exception: " + e.ToString());
- }
- }
- }
- /// <summary>
- /// 广告已加载成功,默认访问第一个接口
- /// </summary>
- public static bool ADIsLoaded(ADType adType, string tag = "")
- {
- if (s_useNewSDKManager)
- {
- return true;
- }
- else
- {
- try
- {
- return GetADService(0).IsLoaded(adType, tag);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager LoadAD Exception: " + e.ToString());
- return false;
- }
- }
- }
- /// <summary>
- /// 加载广告成功
- /// </summary>
- public static bool ADIsLoaded(string SDKName, ADType adType, string tag = "")
- {
- try
- {
- if (GetHasSDKService(s_ADServiceList, SDKName))
- {
- return GetADService(SDKName).IsLoaded(adType, tag);
- }
- else
- {
- if (s_useNewSDKManager)
- {
- //TODO
- return true;
- }
- else
- {
- Debug.LogError("SDKManager ADIsLoaded Not find: " + SDKName);
- return false;
- }
- }
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager ADIsLoaded Exception: " + e.ToString());
- return false;
- }
- }
- /// <summary>
- /// 显示广告
- /// </summary>
- public static void PlayAD(ADType adType, string tag = "")
- {
- if (s_ADServiceList.Count > 0)
- {
- GetADService(0).PlayAD(adType, tag);
- }
- else
- {
- if (s_useNewSDKManager)
- {
- SDKManagerNew.PlayAD(adType, tag);
- }
- else
- {
- Debug.LogError("SDKManager PlayAD s_ADServiceList count is 0");
- }
- }
- }
- /// <summary>
- /// 显示广告
- /// </summary>
- public static void PlayAD(string SDKName, ADType adType, string tag = "")
- {
- try
- {
- if (GetHasSDKService(s_ADServiceList, SDKName))
- {
- GetADService(SDKName).PlayAD(adType, tag);
- }
- else
- {
- if (s_useNewSDKManager)
- {
- SDKManagerNew.PlayAD(SDKName, adType, tag);
- }
- else
- {
- Debug.LogError("SDKManager PlayAD Not find: " + SDKName);
- }
- }
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager PlayAD Exception: " + e.ToString());
- }
- }
- /// <summary>
- /// 隐藏广告
- /// </summary>
- /// <param name="adType"></param>
- public static void CloseAD(ADType adType, string tag = "")
- {
- if (s_ADServiceList.Count > 0)
- {
- GetADService(0).CloseAD(adType, tag);
- }
- else
- {
- if (s_useNewSDKManager)
- {
- SDKManagerNew.CloseAD(adType, tag);
- }
- else
- {
- Debug.LogError("SDKManager CloseAD s_ADServiceList count is 0");
- }
- }
- }
- /// <summary>
- /// 隐藏广告
- /// </summary>
- /// <param name="adType"></param>
- public static void CloseAD(string SDKName, ADType adType, string tag = "")
- {
- if (GetHasSDKService(s_ADServiceList, SDKName))
- {
- GetADService(SDKName).CloseAD(adType, tag);
- }
- else
- {
- if (s_useNewSDKManager)
- {
- SDKManagerNew.CloseAD(SDKName, adType, tag);
- }
- else
- {
- Debug.LogError("SDKManager CloseAD Not find: " + SDKName);
- }
- }
- }
- #endregion
- #region 数据上报
- /// <summary>
- /// 数据上报
- /// </summary>
- /// <param name="data"></param>
- public static void Log(string eventID, Dictionary<string, string> data)
- {
- CheckInit();
- if (s_useNewSDKManager)
- {
- SDKManagerNew.Log(eventID, data);
- }
- for (int i = 0; i < s_logServiceList.Count; i++)
- {
- try
- {
- s_logServiceList[i].Log(eventID, data);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager Log Exception: " + e.ToString());
- }
- }
- }
- public static void LogLogin(string accountID, Dictionary<string, string> data = null)
- {
- CheckInit();
- if (s_useNewSDKManager)
- {
- SDKManagerNew.LogLogin(accountID, data);
- }
- for (int i = 0; i < s_logServiceList.Count; i++)
- {
- try
- {
- s_logServiceList[i].LogLogin(accountID, data);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager LogLogin Exception: " + e.ToString());
- }
- }
- }
- public static void LogLoginOut(string accountID)
- {
- CheckInit();
- if (s_useNewSDKManager)
- {
- SDKManagerNew.LogLoginOut(accountID);
- }
- for (int i = 0; i < s_logServiceList.Count; i++)
- {
- try
- {
- s_logServiceList[i].LogLoginOut(accountID);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager LogLoginOut Exception: " + e.ToString());
- }
- }
- }
- public static void LogPay(string orderID, string goodsID,int count, float price, string currency, string payment)
- {
- CheckInit();
- if (s_useNewSDKManager)
- {
- SDKManagerNew.LogPay(orderID, goodsID, count, price, currency,payment);
- }
- for (int i = 0; i < s_logServiceList.Count; i++)
- {
- try
- {
- s_logServiceList[i].LogPay(orderID, goodsID, count, price, currency, payment);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager LogPay Exception: " + e.ToString());
- }
- }
- }
- public static void LogPaySuccess(string orderID)
- {
- CheckInit();
- if (s_useNewSDKManager)
- {
- SDKManagerNew.LogPaySuccess(orderID);
- }
- for (int i = 0; i < s_logServiceList.Count; i++)
- {
- try
- {
- s_logServiceList[i].LogPaySuccess(orderID);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager LogPaySuccess Exception: " + e.ToString());
- }
- }
- }
- //以下三个配合使用,用于追踪虚拟物品的产出消耗
- public static void LogRewardVirtualCurrency(float count, string reason)
- {
- CheckInit();
- if (s_useNewSDKManager)
- {
- SDKManagerNew.LogRewardVirtualCurrency(count, reason);
- }
- for (int i = 0; i < s_logServiceList.Count; i++)
- {
- try
- {
- s_logServiceList[i].LogRewardVirtualCurrency(count, reason);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager RewardVirtualCurrency Exception: " + e.ToString());
- }
- }
- }
- public static void LogPurchaseVirtualCurrency(string goodsID, int num, float price)
- {
- CheckInit();
- if (s_useNewSDKManager)
- {
- SDKManagerNew.LogPurchaseVirtualCurrency(goodsID, num, price);
- }
- for (int i = 0; i < s_logServiceList.Count; i++)
- {
- try
- {
- s_logServiceList[i].LogPurchaseVirtualCurrency(goodsID, num, price);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager PurchaseVirtualCurrency Exception: " + e.ToString());
- }
- }
- }
- public static void LogUseItem(string goodsID, int num)
- {
- CheckInit();
- if (s_useNewSDKManager)
- {
- SDKManagerNew.LogUseItem(goodsID, num);
- }
- for (int i = 0; i < s_logServiceList.Count; i++)
- {
- try
- {
- s_logServiceList[i].LogUseItem(goodsID, num);
- }
- catch (Exception e)
- {
- Debug.LogError("SDKManager LogUseItem Exception: " + e.ToString());
- }
- }
- }
- #endregion
- #region 其他SDK
- public static void ToClipboard(string content)
- {
- #if UNITY_EDITOR
- GUIUtility.systemCopyBuffer = content;
- #elif UNITY_ANDROID
- SDKManagerNew.ToClipboard(content);
- #elif UNITY_IOS
- ClipboardManager.ToClipboard(content);
- #endif
- }
- public static void DownloadApk(string url = null)
- {
- #if UNITY_ANDROID
- SDKManagerNew.DownloadApk(url);
- #endif
- }
- public static void GetAPKSize(string url = null)
- {
- #if UNITY_ANDROID
- SDKManagerNew.GetAPKSize(url);
- #endif
- }
- /// <summary>
- /// 读取注入配置
- /// </summary>
- public static string GetProperties(string key,string defaultValue = "")
- {
- return GetProperties(SDKInterfaceDefine.FileName_ChannelProperties,key, defaultValue);
- }
- /// <summary>
- /// 读取注入配置
- /// </summary>
- public static string GetProperties(string properties, string key, string defaultValue)
- {
- return SDKManagerNew.GetProperties(properties, key, defaultValue);
- }
- #region 事件监听
- public static void AddOtherCallBackListener(string functionName, OtherCallBack callBack)
- {
- if (s_callBackDict.ContainsKey(functionName))
- {
- s_callBackDict[functionName] += callBack;
- }
- else
- {
- s_callBackDict.Add(functionName, callBack);
- }
- if(s_useNewSDKManager)
- {
- SDKManagerNew.AddOtherCallBackListener(functionName, callBack);
- }
- }
- public static void RemoveOtherCallBackListener(string functionName, OtherCallBack callBack)
- {
- if (s_callBackDict.ContainsKey(functionName))
- {
- s_callBackDict[functionName] -= callBack;
- }
- else
- {
- Debug.LogError("RemoveOtherCallBackListener 不存在的 function Name ->" + functionName + "<-");
- }
- if (s_useNewSDKManager)
- {
- SDKManagerNew.RemoveOtherCallBackListener(functionName, callBack);
- }
- }
- #endregion
- #endregion
- #endregion
- #region 加载SDK设置
- /// <summary>
- /// 读取当前游戏内的SDK配置
- /// 找不到或者解析失败会返回Null
- /// </summary>
- /// <returns></returns>
- public static SchemeData LoadGameSchemeConfig()
- {
- if (ConfigManager.GetIsExistConfig(c_ConfigName))
- {
- Debug.Log("LoadGameSchemeConfig");
- Dictionary<string, SingleField> configData = ConfigManager.GetData(c_ConfigName);
- return JsonUtility.FromJson<SchemeData>(configData[c_KeyName].GetString());
- }
- else
- {
- Debug.Log("LoadGameSchemeConfig null");
- return null;
- }
- }
- public static void AnalyzeSchemeData(
- SchemeData schemeData,
- out List<LoginInterface> loginScheme,
- out List<ADInterface> ADScheme,
- out List<PayInterface> payScheme,
- out List<LogInterface> logScheme,
- out List<OtherSDKInterface> otherScheme
- )
- {
- if (schemeData != null)
- {
- loginScheme = new List<LoginInterface>();
- for (int i = 0; i < schemeData.LoginScheme.Count; i++)
- {
- loginScheme.Add((LoginInterface)AnalysisConfig(schemeData.LoginScheme[i]));
- }
- ADScheme = new List<ADInterface>();
- for (int i = 0; i < schemeData.ADScheme.Count; i++)
- {
- ADScheme.Add((ADInterface)AnalysisConfig(schemeData.ADScheme[i]));
- }
- payScheme = new List<PayInterface>();
- for (int i = 0; i < schemeData.PayScheme.Count; i++)
- {
- payScheme.Add((PayInterface)AnalysisConfig(schemeData.PayScheme[i]));
- }
- logScheme = new List<LogInterface>();
- for (int i = 0; i < schemeData.LogScheme.Count; i++)
- {
- logScheme.Add((LogInterface)AnalysisConfig(schemeData.LogScheme[i]));
- }
- otherScheme = new List<OtherSDKInterface>();
- for (int i = 0; i < schemeData.OtherScheme.Count; i++)
- {
- otherScheme.Add((OtherSDKInterface)AnalysisConfig(schemeData.OtherScheme[i]));
- }
- }
- else
- {
- loginScheme = new List<LoginInterface>();
- ADScheme = new List<ADInterface>();
- payScheme = new List<PayInterface>();
- logScheme = new List<LogInterface>();
- otherScheme = new List<OtherSDKInterface>();
- }
- }
- static SDKInterfaceBase AnalysisConfig(SDKConfigData data)
- {
- if (data == null)
- {
- return new NullSDKInterface();
- }
- else
- {
- return (SDKInterfaceBase)JsonUtility.FromJson(data.SDKContent, Assembly.Load("Assembly-CSharp").GetType(data.SDKName));
- }
- }
- #endregion
- #region 初始化SDK
- static void LoadService(SchemeData data)
- {
- AnalyzeSchemeData(
- data,
- out s_loginServiceList,
- out s_ADServiceList,
- out s_payServiceList,
- out s_logServiceList,
- out s_otherServiceList
- );
- }
- static void InitSDK()
- {
- InitLogin(s_loginServiceList);
- InitSDKList(s_ADServiceList);
- InitPay(s_payServiceList);
- InitSDKList(s_logServiceList);
- InitSDKList(s_otherServiceList);
- //Debug.Log("s_loginServiceList: " + s_loginServiceList.Count);
- }
- #endregion
- #region 功能函数
- static T GetSDKService<T>(List<T> list, string name) where T : SDKInterfaceBase
- {
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].m_SDKName == name)
- {
- return list[i];
- }
- }
- throw new Exception("GetSDKService " + typeof(T).Name + " Exception dont find ->" + name + "<-");
- }
- static bool GetHasSDKService<T>(List<T> list, string name) where T : SDKInterfaceBase
- {
- for (int i = 0; i < list.Count; i++)
- {
- if (list[i].m_SDKName == name)
- {
- return true;
- }
- }
- return false;
- }
- static void InitSDKList<T>(List<T> list) where T : SDKInterfaceBase
- {
- for (int i = 0; i < list.Count; i++)
- {
- try
- {
- list[i].m_SDKName = list[i].GetType().Name;
- list[i].Init();
- }
- catch (Exception e)
- {
- Debug.LogError("Init " + typeof(T).Name + " SDK Exception:\n" + e.ToString());
- }
- }
- }
- #endregion
- #region 自动监听上报
- /// <summary>
- /// 自动上报监听初始化
- /// </summary>
- static void AutoListenerInit()
- {
- PayCallBack += OnPayCallBackListener;
- }
- /// <summary>
- /// 自动上报支付
- /// </summary>
- static void OnPayCallBackListener(OnPayInfo info)
- {
- if (info.isSuccess)
- {
- LogPay(info.orderID,info.goodsId,1,info.price,info.currency, info.storeName.ToString());
- }
- }
- #endregion
- }
- #region 声明
- public delegate void LoginCallBack(OnLoginInfo info);
- public delegate void PayCallBack(OnPayInfo info);
- public delegate void ADCallBack(OnADInfo info);
- public delegate void OtherCallBack(OnOtherInfo info);
- public class SchemeData
- {
- public string SchemeName;
- public bool UseNewSDKManager;
- public List<SDKConfigData> LogScheme = new List<SDKConfigData>();
- public List<SDKConfigData> LoginScheme = new List<SDKConfigData>();
- public List<SDKConfigData> ADScheme = new List<SDKConfigData>();
- public List<SDKConfigData> PayScheme = new List<SDKConfigData>();
- public List<SDKConfigData> OtherScheme = new List<SDKConfigData>();
- }
- [System.Serializable]
- public class SDKConfigData
- {
- public string SDKName;
- public string SDKContent;
- }
- public enum SDKType
- {
- Log,
- Login,
- AD,
- Pay,
- Other,
- }
- #endregion
- }
|