Forest_Client/Forest/Assets/Scripts/Gameplay/Login/LoginStatusFaceBook.cs

77 lines
2.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using cfg.BI;
using PhxhSDK;
using Framework.BI;
using Framework.Event;
using Event = cfg.BI.Event;
using Constants = Framework.Constants.Constants;
namespace Gameplay.Login
{
public class LoginStatusFaceBook : LoginStatus
{
public override LoginStatusID ID
{
get { return LoginStatusID.Facebook; }
}
public override void Login()
{
DebugUtil.LogWarning("Facebook登录");
var sdkHelper = SDKManager.Instance.GetSdkHelper(SDKManager.SdkName.FireBase);
var loginService = sdkHelper as ILoginService;
loginService?.SetCurLoginParty(ThirdLoginSDK.Facebook);
loginService?.Login(OnLoginSuccess, OnLoginFail);
}
public override void Logout()
{
var sdkHelper = SDKManager.Instance.GetSdkHelper(SDKManager.SdkName.FireBase);
var loginService = sdkHelper as ILoginService;
loginService?.SetCurLoginParty(ThirdLoginSDK.Facebook);
loginService?.Logout();
}
public override string GetProfileName()
{
var sdkHelper = SDKManager.Instance.GetSdkHelper(SDKManager.SdkName.FireBase);
var loginService = sdkHelper as ILoginService;
loginService?.SetCurLoginParty(ThirdLoginSDK.Facebook);
string profileName = loginService?.GetProfileName();
DebugUtil.LogWarning("Facebook Get UserName: {0}", profileName);
return string.IsNullOrEmpty(profileName) ? Constants.EmptyUser : profileName;
}
private void OnLoginSuccess(string userID, string facebookUserID, string idToken)
{
LoginManager.Instance.IsLogin = true;
LoginManager.Instance.ShowLogin = true;
//第三方ID设置为Firebase验证后的唯一id 并存至本地
AppInfoManager.Instance.ThirdLoginSuccess(userID, LoginStatusID.Facebook);
BIManager.Instance.ThirdID = userID;
BIManager.Instance.TrackEvent(Event.login_success);
BIManager.Instance.TrackEventOnce(EventFirst.fte_login_success);
//从服务器获取数据
GetDataFromSever();
EventManager.Instance.Send(EventManager.EventName.LoginSuccess);
DebugUtil.LogWarning("FaceBook登录成功userID: {0}", userID);
}
private void GetDataFromSever()
{
AppInfoManager.Instance.CurLoginState = AppInfoManager.NetConfigID.ThirdID;
AppNetConfig.State = NetRequestStatus.Start;
}
private void OnLoginFail(int code, string msg)
{
LoginManager.Instance.IsLogin = false;
BIManager.Instance.TrackEvent(Event.login_fail, msg);
DebugUtil.LogError("FaceBook Login Fail: {0}", msg);
EventManager.Instance.Send(EventManager.EventName.LoginFail);
}
}
}