236 lines
6.8 KiB
C#
236 lines
6.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Runtime.InteropServices;
|
|
using Touka;
|
|
using UnityEngine;
|
|
|
|
public class TKGiOSLoginManager : MonoBehaviour
|
|
{
|
|
#if UNITY_IOS
|
|
// login result callback
|
|
[DllImport("__Internal")]
|
|
public static extern void TKG_LoginResultCallback(
|
|
IntPtr loginResult
|
|
);
|
|
|
|
// login out callback
|
|
[DllImport("__Internal")]
|
|
public static extern void TKG_LogoutCallback(
|
|
IntPtr loginOut
|
|
);
|
|
|
|
// delete account callback
|
|
[DllImport("__Internal")]
|
|
public static extern void TKG_DeleteAccountCallback(
|
|
IntPtr deleteAccount
|
|
);
|
|
|
|
// login out
|
|
[DllImport("__Internal")]
|
|
private static extern void TKG_Logout();
|
|
|
|
// availablechannel
|
|
[DllImport("__Internal")]
|
|
private static extern string TKG_AvailableLoginChannelList();
|
|
|
|
// login
|
|
[DllImport("__Internal")]
|
|
private static extern void TKG_Login(LoginType type);
|
|
|
|
// delete account
|
|
[DllImport("__Internal")]
|
|
private static extern void TKG_DeleteAccount();
|
|
|
|
|
|
// bind account
|
|
[DllImport("__Internal")]
|
|
private static extern void TKG_BindAccount(LoginType loginType,BindType bindType,string thirdUid);
|
|
|
|
// bind account callback
|
|
[DllImport("__Internal")]
|
|
public static extern void TKG_BindAccountCallback(
|
|
IntPtr bindAccount
|
|
);
|
|
|
|
// auto login
|
|
[DllImport("__Internal")]
|
|
private static extern bool TKG_IsCanAutoLogin();
|
|
|
|
[DllImport("__Internal")]
|
|
private static extern void TKG_AutoLogin();
|
|
#endif
|
|
|
|
|
|
public bool IsCanAutoLogin()
|
|
{
|
|
#if UNITY_IOS
|
|
return TKG_IsCanAutoLogin();
|
|
#else
|
|
return false;
|
|
#endif
|
|
}
|
|
|
|
public void AutoLogin()
|
|
{
|
|
#if UNITY_IOS
|
|
// login callback
|
|
loginResultDelegate loginResultHandler = new loginResultDelegate(loginResultHandle);
|
|
IntPtr result = Marshal.GetFunctionPointerForDelegate(loginResultHandler);
|
|
TKG_LoginResultCallback(result);
|
|
TKG_AutoLogin();
|
|
#endif
|
|
}
|
|
|
|
public void DeleteAccount()
|
|
{
|
|
|
|
#if UNITY_IOS
|
|
// delete account callback
|
|
deleteAccountDelegate deleteAccountHandler = new deleteAccountDelegate(deleteAccountHandle);
|
|
IntPtr result = Marshal.GetFunctionPointerForDelegate(deleteAccountHandler);
|
|
TKG_DeleteAccountCallback(result);
|
|
|
|
TKG_DeleteAccount();
|
|
#endif
|
|
}
|
|
|
|
|
|
public void Login(LoginType _type)
|
|
{
|
|
#if UNITY_IOS
|
|
// login callback
|
|
loginResultDelegate loginResultHandler = new loginResultDelegate(loginResultHandle) ;
|
|
IntPtr result = Marshal.GetFunctionPointerForDelegate(loginResultHandler);
|
|
TKG_LoginResultCallback(result);
|
|
|
|
TKG_Login(_type);
|
|
#endif
|
|
|
|
}
|
|
|
|
public void Logout()
|
|
{
|
|
#if UNITY_IOS
|
|
// logout callback
|
|
logoutDelegate logoutHandler = new logoutDelegate(logoutHandle);
|
|
IntPtr result = Marshal.GetFunctionPointerForDelegate(logoutHandler);
|
|
TKG_LogoutCallback(result);
|
|
|
|
TKG_Logout();
|
|
#endif
|
|
}
|
|
|
|
public List<LoginType> AvailableLoginChannelList()
|
|
{
|
|
|
|
#if UNITY_EDITOR
|
|
string temp = "0,4";
|
|
#elif UNITY_IOS
|
|
string temp = TKG_AvailableLoginChannelList();
|
|
|
|
|
|
string[] arr = temp.Split(',');
|
|
List<LoginType> list = new List<LoginType>();
|
|
for (int i = 0; i < arr.Length; i++)
|
|
{
|
|
list.Add((LoginType)Enum.Parse(typeof(LoginType), arr[i]));
|
|
}
|
|
return list;
|
|
#endif
|
|
return null;
|
|
}
|
|
|
|
public void BindAccount(LoginType loginType, BindType bindType, string thirdUid)
|
|
{
|
|
#if UNITY_IOS
|
|
// logout callback
|
|
bindAccountDelegate bindHandler = new bindAccountDelegate(bindAccountHandle);
|
|
IntPtr result = Marshal.GetFunctionPointerForDelegate(bindHandler);
|
|
TKG_BindAccountCallback(result);
|
|
TKG_BindAccount(loginType,bindType,thirdUid);
|
|
#endif
|
|
}
|
|
|
|
#if UNITY_IOS
|
|
// bind account callback
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
public delegate void bindAccountDelegate(BindAccountStatus status, LoginType type, string msg, string userId, string token, string email, string nickName, string iconUrl,string thirdUids);
|
|
[AOT.MonoPInvokeCallback(typeof(bindAccountDelegate))]
|
|
static void bindAccountHandle(BindAccountStatus status, LoginType type, string msg, string userId, string token, string email, string nickName, string iconUrl, string thirdUids)
|
|
{
|
|
|
|
if (TKGSDKCallback.mBindAccountCallback != null)
|
|
{
|
|
string[] Strs = thirdUids.Split(',');
|
|
TKGSDKCallback.mBindAccountCallback.Invoke(status, type, msg, userId, token, email, nickName, iconUrl, Strs);
|
|
TKGSDKCallback.mBindAccountCallback = null;
|
|
}
|
|
}
|
|
|
|
|
|
// delete account callback
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
public delegate void deleteAccountDelegate(DeleteStatus status,string userId);
|
|
[AOT.MonoPInvokeCallback(typeof(deleteAccountDelegate))]
|
|
static void deleteAccountHandle(DeleteStatus status, string userId)
|
|
{
|
|
|
|
if (TKGSDKCallback.mDeleteAccountCallback != null)
|
|
{
|
|
TKGSDKCallback.mDeleteAccountCallback.Invoke(status, userId);
|
|
TKGSDKCallback.mDeleteAccountCallback = null;
|
|
}
|
|
}
|
|
|
|
// login out callback
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
public delegate void logoutDelegate();
|
|
[AOT.MonoPInvokeCallback(typeof(logoutDelegate))]
|
|
static void logoutHandle()
|
|
{
|
|
|
|
if (TKGSDKCallback.mLogoutCallback != null)
|
|
{
|
|
TKGSDKCallback.mLogoutCallback.Invoke();
|
|
TKGSDKCallback.mLogoutCallback = null;
|
|
}
|
|
}
|
|
|
|
// login callback
|
|
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
|
|
public delegate void loginResultDelegate(LoginStatus status, LoginType type, string msg, string userId, string token, string email, string nickName, string iconUrl);
|
|
[AOT.MonoPInvokeCallback(typeof(loginResultDelegate))]
|
|
static void loginResultHandle(LoginStatus status, LoginType type, string msg, string userId, string token, string email, string nickName, string iconUrl)
|
|
{
|
|
|
|
if (TKGSDKCallback.mLoginCallback != null)
|
|
{
|
|
TKGSDKCallback.mLoginCallback.Invoke(status,type,msg,userId,token,email,nickName,iconUrl);
|
|
TKGSDKCallback.mLoginCallback = null;
|
|
}
|
|
}
|
|
|
|
#endif
|
|
|
|
private static TKGiOSLoginManager s_instance;
|
|
|
|
public static TKGiOSLoginManager Instance
|
|
{
|
|
get
|
|
{
|
|
if (s_instance == null)
|
|
{
|
|
GameObject TGGameObject = new GameObject
|
|
{
|
|
name = "TKGLoginObject"
|
|
};
|
|
s_instance = TGGameObject.AddComponent<TKGiOSLoginManager>();
|
|
DontDestroyOnLoad(TGGameObject);
|
|
}
|
|
return s_instance;
|
|
}
|
|
}
|
|
}
|