using FrameWork.SDKManager; using System; using System.Collections.Generic; using System.Linq; using System.Text; using UnityEngine; /// /// 管理平台账号绑定 /// public class AccountMergeController { /// /// 当要绑定的平台已存在回调 /// public static CallBack OnMergeAccountExist; /// /// 最终绑定的结果回调 /// public static CallBack OnConfirmMergeExistAccountCallback; /// /// 返回当前账户已经绑定的平台(包含当前登录平台) /// public static CallBack> OnRequsetAreadyBindPlatformCallBack; private static List areadyBindPlatform = new List(); [RuntimeInitializeOnLoadMethod] private static void Init() { GlobalEvent.AddTypeEvent(OnAccountMergeInfo); GlobalEvent.AddTypeEvent(OnConfirmMergeExistAccount); GlobalEvent.AddTypeEvent(OnRequsetAreadyBindPlatform); LoginGameController.OnUserLogin += OnUserLogin; } private static void OnUserLogin(UserLogin2Client t) { RequsetAreadyBindPlatform(); } #region 消息接收 private static void OnRequsetAreadyBindPlatform(RequsetAreadyBindPlatform2Client e, object[] args) { areadyBindPlatform = e.areadyBindPlatforms; if (OnRequsetAreadyBindPlatformCallBack != null) { OnRequsetAreadyBindPlatformCallBack(e.areadyBindPlatforms); } } private static void OnConfirmMergeExistAccount(ConfirmMergeExistAccount2Client e, object[] args) { if(e.code==0) { if (areadyBindPlatform.Contains(e.loginType)) Debug.LogError("已包含绑定平台:" + e.loginType); else areadyBindPlatform.Add(e.loginType); } else { Debug.LogError("绑定出错"); } if (OnConfirmMergeExistAccountCallback != null) { OnConfirmMergeExistAccountCallback(e); } } private static void OnAccountMergeInfo(AccountMergeInfo2Client e, object[] args) { if (!e.alreadyExistAccount) return; Debug.Log("要绑定的账户已存在:" + e.mergeAccount.userID); if (OnMergeAccountExist != null) { OnMergeAccountExist(e); } } #endregion /// /// 请求哪些是已绑定的平台信息 /// private static void RequsetAreadyBindPlatform() { RequsetAreadyBindPlatform2Server msg = new RequsetAreadyBindPlatform2Server(); JsonMessageProcessingController.SendMessage(msg); } /// /// 返回当前账户已经绑定的平台(包含当前登录平台) /// /// public static List GetAreadyBindPlatform() { return areadyBindPlatform; } /// /// 判断是否能使用商店(规则是当前是游客登录,并且未绑定其他登录方式) /// /// 当前登录方式 /// public static bool CheckCanUseStore(LoginPlatform loginType) { if (areadyBindPlatform.Contains(loginType) && areadyBindPlatform.Count == 1 && loginType == LoginPlatform.Tourist) return false; return true; } /// /// 当要绑定的账户已存在,确认合并 /// public static void ConfirmMerge(bool useCurrentAccount) { ConfirmMergeExistAccount2Server msg = new ConfirmMergeExistAccount2Server(); msg.useCurrentAccount = useCurrentAccount; JsonMessageProcessingController.SendMessage(msg); } public static bool isWaiting = false; /// /// 请求绑定账户 /// /// /// /// public static void MergeLoginPlatform(LoginPlatform loginPlatform, string accountID = "", string pw = "") { if (isWaiting) { Debug.LogError("AccountMergeController => 等待sdk返回登录信息"); return; } isWaiting = true; SDKManager.LoginCallBack += SDKLoginCallBack; string tag = ""; if (loginPlatform == LoginPlatform.AccountLogin) { accountID = accountID.Trim(); pw = pw.Trim(); string pwMd5 = HDJ.Framework.Utils.MD5Utils.GetObjectMD5(pw); tag = accountID + "|" + pwMd5; } SDKManager.LoginByPlatform(loginPlatform, tag); } private static void SDKLoginCallBack(OnLoginInfo info) { isWaiting = false; SDKManager.LoginCallBack -= SDKLoginCallBack; if (info.isSuccess) { AccountMergeInfo2Server msg = AccountMergeInfo2Server.GetMessage(info.loginPlatform, info.accountId, info.password); JsonMessageProcessingController.SendMessage(msg); } else { //sdk登录失败 if (OnConfirmMergeExistAccountCallback != null) { ConfirmMergeExistAccount2Client msg = new ConfirmMergeExistAccount2Client(); msg.code = -1; msg.loginType = info.loginPlatform; OnConfirmMergeExistAccountCallback(msg); } } } }