2026.1.30 unitysdk
This commit is contained in:
parent
95acd87be4
commit
2d5dc1ef64
8
Assets/AddressableAssetsData/Android.meta
Normal file
8
Assets/AddressableAssetsData/Android.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b30e7166417b860469dd2f109845967a
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Binary file not shown.
@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 613a106049ce9f34c94bc2b238cff4a6
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -65,7 +65,7 @@ public partial class SDKMgr : MonoBehaviour
|
||||
{
|
||||
if (sdk == null)
|
||||
{
|
||||
#if UNITY_EDITOR || NULLSDK
|
||||
#if NULLSDK
|
||||
//listener = new NULLSDKCBListener();
|
||||
sdk = new NULLSDKAndroid();
|
||||
//sdk.Init(listener, "");
|
||||
@ -79,8 +79,9 @@ public partial class SDKMgr : MonoBehaviour
|
||||
// sdk = new NTSDKAndroid();
|
||||
// sdk.Init(listener, "SDKUni");
|
||||
|
||||
#elif (UNITY_ANDROID || UNITY_IOS)
|
||||
#elif (UNITY_EDITOR || UNITY_ANDROID || UNITY_IOS)
|
||||
sdk = new UnitySDK();
|
||||
Debug.Log("tzy_测试");
|
||||
#else
|
||||
|
||||
var types = Assembly.GetExecutingAssembly().GetTypes();
|
||||
@ -113,7 +114,7 @@ public partial class SDKMgr : MonoBehaviour
|
||||
}
|
||||
|
||||
if (sdk == null)
|
||||
return;
|
||||
return;
|
||||
|
||||
if (sdk.GetInited())
|
||||
{
|
||||
@ -180,10 +181,12 @@ public partial class SDKMgr : MonoBehaviour
|
||||
|
||||
public void EnterGame()
|
||||
{
|
||||
Debug.Log("tzy_1EnterGame");
|
||||
SyncInfoToFairGuard();
|
||||
SyncInfoToBugly();
|
||||
if (sdk == null) return;
|
||||
sdk.EnterGame();
|
||||
Debug.Log("tzy_2EnterGame");
|
||||
}
|
||||
|
||||
public void CreateRole()
|
||||
|
||||
@ -1,5 +1,23 @@
|
||||
public class UnitySDK: SDKBase
|
||||
using Unity.Services.Core;
|
||||
using Unity.Services.Authentication.PlayerAccounts;
|
||||
using Unity.Services.Authentication;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
using System;
|
||||
using TMPro;
|
||||
|
||||
|
||||
public enum UnitySDK_Type
|
||||
{
|
||||
none, Anonymous, Google, FaceBook, un
|
||||
}
|
||||
|
||||
|
||||
|
||||
public class UnitySDK : SDKBase
|
||||
{
|
||||
UnitySDK_Type type = UnitySDK_Type.none;
|
||||
|
||||
public UnitySDKCBListener mListener;
|
||||
|
||||
public UnitySDK()
|
||||
@ -7,21 +25,43 @@
|
||||
mListener = SDKMgr.Instance.gameObject.AddComponent<UnitySDKCBListener>();
|
||||
SDKName = "Unity";
|
||||
}
|
||||
|
||||
#region 继承父类
|
||||
public override void Init()
|
||||
{
|
||||
base.Init();
|
||||
mListener.InitSuccessCB(null);
|
||||
|
||||
UnityServices.Instance.Initialized += () =>
|
||||
{
|
||||
Debug.Log("初始化");
|
||||
mListener.InitSuccessCB(null);
|
||||
ChooseSDK();
|
||||
|
||||
};
|
||||
UnityServices.InitializeAsync();
|
||||
|
||||
}
|
||||
|
||||
public override void Login()
|
||||
{
|
||||
mListener.LoginSucessCB(null);
|
||||
switch (type)
|
||||
{
|
||||
case UnitySDK_Type.Anonymous:
|
||||
UGS_Anonymous_Start_SignIn_Asnyc();
|
||||
break;
|
||||
case UnitySDK_Type.Google:
|
||||
case UnitySDK_Type.FaceBook:
|
||||
UGS_UPA_Start_SignIn_Asnyc();
|
||||
break;
|
||||
case UnitySDK_Type.un:
|
||||
UGS_un_Start_SignIn_Asnyc(UGS_un_username, UGS_un_password);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
public override void Logout()
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
UGS_SignOut();
|
||||
}
|
||||
|
||||
public override void SwitchAccount()
|
||||
@ -37,17 +77,14 @@
|
||||
|
||||
public override void CreateRole()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void EnterGame()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void UpdateRoleLv()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public override void ExitGame()
|
||||
@ -67,11 +104,296 @@
|
||||
|
||||
public override void CallInitSuccessCB()
|
||||
{
|
||||
|
||||
Login();
|
||||
}
|
||||
|
||||
public override void CallLoginSuccessCB()
|
||||
{
|
||||
|
||||
}
|
||||
#endregion 继承父类
|
||||
|
||||
|
||||
void ChooseSDK()
|
||||
{
|
||||
Transform loginpad = GameObject.Find("UIRoot").transform.Find("UILanuch").Find("Root").Find("Login");
|
||||
|
||||
Button btn_anonymous = loginpad.Find("Btn_Login_Anonymous").GetComponent<Button>();
|
||||
Button btn_google = loginpad.Find("Btn_Login_Google").GetComponent<Button>();
|
||||
Button btn_facebook = loginpad.Find("Btn_Login_FaceBook").GetComponent<Button>();
|
||||
Button btn_un = loginpad.Find("Btn_Login_un").GetComponent<Button>();
|
||||
|
||||
btn_anonymous.onClick.RemoveAllListeners();
|
||||
btn_google.onClick.RemoveAllListeners();
|
||||
btn_facebook.onClick.RemoveAllListeners();
|
||||
btn_un.onClick.RemoveAllListeners();
|
||||
|
||||
btn_anonymous.onClick.AddListener(() => SetType(UnitySDK_Type.Anonymous));
|
||||
btn_google.onClick.AddListener(() => SetType(UnitySDK_Type.Google));
|
||||
btn_facebook.onClick.AddListener(() => SetType(UnitySDK_Type.FaceBook));
|
||||
btn_un.onClick.AddListener(() => SetType(UnitySDK_Type.un));
|
||||
|
||||
loginpad.gameObject.SetActive(true);
|
||||
|
||||
void SetType(UnitySDK_Type type)
|
||||
{
|
||||
this.type = type;
|
||||
if (type != UnitySDK_Type.un) loginpad.gameObject.SetActive(false);
|
||||
if (type == UnitySDK_Type.un)
|
||||
{
|
||||
UGS_un_InputInfo();
|
||||
}
|
||||
SetSignIn();
|
||||
}
|
||||
}
|
||||
|
||||
void SetSignIn()
|
||||
{
|
||||
//设置Signin 挂载
|
||||
//mListener.InitSuccessCB(null);
|
||||
Debug.Log($"tzy_{Time.realtimeSinceStartup}");
|
||||
switch (type)
|
||||
{
|
||||
|
||||
case UnitySDK_Type.Anonymous:
|
||||
AuthenticationService.Instance.SignedIn += () =>
|
||||
{
|
||||
base.SetLogined(true);
|
||||
Debug.Log($"tzy___LoginSucessCB");
|
||||
Debug.Log($"tzy_{Time.realtimeSinceStartup}");
|
||||
mListener.LoginSucessCB(UGS_Anonymous_SetInfo());
|
||||
};
|
||||
break;
|
||||
case UnitySDK_Type.Google:
|
||||
case UnitySDK_Type.FaceBook:
|
||||
PlayerAccountService.Instance.SignedIn += UGS_UPA_SignIn_Unity_Asnyc;
|
||||
break;
|
||||
case UnitySDK_Type.un:
|
||||
AuthenticationService.Instance.SignedIn += () =>
|
||||
{
|
||||
base.SetLogined(true);
|
||||
mListener.LoginSucessCB(UGS_un_SetInfo());
|
||||
};
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void UGS_SignOut()
|
||||
{
|
||||
AuthenticationService.Instance.SignOut();
|
||||
base.SetInited(false);
|
||||
base.SetLogined(false);
|
||||
//UGS_UpdateUI();
|
||||
}
|
||||
|
||||
#region UGS Unity Player Account
|
||||
|
||||
async void UGS_UPA_Start_SignIn_Asnyc()
|
||||
{
|
||||
if (PlayerAccountService.Instance.IsSignedIn)
|
||||
{
|
||||
base.SetInited(true);
|
||||
UGS_UPA_SignIn_Unity_Asnyc();
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
await PlayerAccountService.Instance.StartSignInAsync();
|
||||
}
|
||||
catch (RequestFailedException ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
async void UGS_UPA_SignIn_Unity_Asnyc()
|
||||
{
|
||||
try
|
||||
{
|
||||
await AuthenticationService.Instance.SignInWithUnityAsync(PlayerAccountService.Instance.AccessToken);
|
||||
//成功后
|
||||
base.SetLogined(true);
|
||||
|
||||
mListener.LoginSucessCB(UGS_UPA_SetInfo());
|
||||
}
|
||||
catch (RequestFailedException ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
UserInfo UGS_UPA_SetInfo()
|
||||
{
|
||||
UserInfo userInfo;
|
||||
var player = PlayerAccountService.Instance;
|
||||
if (player.IsSignedIn)
|
||||
{
|
||||
Debug.Log("tzy_send userinfo");
|
||||
userInfo = new UserInfo()
|
||||
{
|
||||
uid = player.IdToken,
|
||||
token = player.AccessToken,
|
||||
userName = "?"
|
||||
};
|
||||
return userInfo;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
||||
#endregion UGS Unity Player Account
|
||||
|
||||
#region UGS Anonymous
|
||||
|
||||
async void UGS_Anonymous_Start_SignIn_Asnyc()
|
||||
{
|
||||
try
|
||||
{
|
||||
base.SetInited(true);
|
||||
await AuthenticationService.Instance.SignInAnonymouslyAsync();
|
||||
|
||||
}
|
||||
catch (RequestFailedException ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
UserInfo UGS_Anonymous_SetInfo()
|
||||
{
|
||||
UserInfo userInfo;
|
||||
//var player = PlayerAccountService.Instance;
|
||||
var auth = AuthenticationService.Instance;
|
||||
Debug.Log("tzy_send userinfo1");
|
||||
if (auth.IsSignedIn)
|
||||
{
|
||||
Debug.Log("tzy_send userinfo2");
|
||||
userInfo = new UserInfo()
|
||||
{
|
||||
uid = auth.PlayerId,
|
||||
token = auth.AccessToken,
|
||||
userName = "?"
|
||||
};
|
||||
return userInfo;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
||||
#endregion UGS Anonymous
|
||||
|
||||
|
||||
#region UGS un
|
||||
|
||||
string UGS_un_username, UGS_un_password;
|
||||
|
||||
void UGS_un_InputInfo()
|
||||
{
|
||||
Transform loginpad = GameObject.Find("UIRoot").transform.Find("UILanuch").Find("Root").Find("Login");
|
||||
Transform unpad = loginpad.Find("Rect_un");
|
||||
Button btn_cancel = unpad.Find("Btn_Group").Find("Btn_Cancel").GetComponent<Button>();
|
||||
Button btn_confirm = unpad.Find("Btn_Group").Find("Btn_Confirm").GetComponent<Button>();
|
||||
TMP_InputField input1 = unpad.Find("Content").Find("Input1").GetComponent<TMP_InputField>();
|
||||
TMP_InputField input2 = unpad.Find("Content").Find("Input2").GetComponent<TMP_InputField>();
|
||||
|
||||
input1.text = ""; input2.text = "";
|
||||
btn_cancel.onClick.RemoveAllListeners(); btn_confirm.onClick.RemoveAllListeners();
|
||||
|
||||
|
||||
|
||||
btn_cancel.onClick.AddListener(() =>
|
||||
{
|
||||
unpad.gameObject.SetActive(false);
|
||||
});
|
||||
btn_confirm.onClick.AddListener(() =>
|
||||
{
|
||||
string username = input1.text;
|
||||
string password = input2.text;
|
||||
UGS_un_SignUp_Async(username, password);
|
||||
});
|
||||
|
||||
unpad.gameObject.SetActive(true);
|
||||
|
||||
|
||||
}
|
||||
|
||||
async void UGS_un_SignUp_Async(string username, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
await AuthenticationService.Instance.SignUpWithUsernamePasswordAsync(username, password);
|
||||
Debug.Log("SignUp is successful.");
|
||||
//UGS_un_SignIn_Async(username, password);
|
||||
}
|
||||
catch (AuthenticationException ex)
|
||||
{
|
||||
Debug.Log(ex);
|
||||
UGS_un_SignIn_Async(username, password);
|
||||
}
|
||||
}
|
||||
|
||||
async void UGS_un_SignIn_Async(string username, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
await AuthenticationService.Instance.SignInWithUsernamePasswordAsync(username, password);
|
||||
Debug.Log("SignIn is successful.");
|
||||
base.SetLogined(true);
|
||||
Transform loginpad = GameObject.Find("UIRoot").transform.Find("UILanuch").Find("Root").Find("Login");
|
||||
loginpad.gameObject.SetActive(false);
|
||||
}
|
||||
catch (AuthenticationException ex)
|
||||
{
|
||||
Debug.Log(ex);
|
||||
}
|
||||
}
|
||||
|
||||
async void UGS_un_Start_SignIn_Asnyc(string username, string password)
|
||||
{
|
||||
try
|
||||
{
|
||||
base.SetInited(true);
|
||||
await AuthenticationService.Instance.SignInWithUsernamePasswordAsync(username, password);
|
||||
|
||||
}
|
||||
catch (RequestFailedException ex)
|
||||
{
|
||||
Debug.LogException(ex);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
UserInfo UGS_un_SetInfo()
|
||||
{
|
||||
UserInfo userInfo;
|
||||
//var player = PlayerAccountService.Instance;
|
||||
var auth = AuthenticationService.Instance;
|
||||
if (auth.IsSignedIn)
|
||||
{
|
||||
Debug.Log("tzy_send userinfo");
|
||||
userInfo = new UserInfo()
|
||||
{
|
||||
uid = auth.PlayerId,
|
||||
token = auth.AccessToken,
|
||||
userName = "?"
|
||||
};
|
||||
return userInfo;
|
||||
}
|
||||
else return null;
|
||||
}
|
||||
|
||||
|
||||
#endregion UGS un
|
||||
|
||||
}
|
||||
@ -27,9 +27,12 @@ public class UnitySDKCBListener:MonoBehaviour
|
||||
|
||||
public void LoginSucessCB(object arg)
|
||||
{
|
||||
if (arg == null) return;
|
||||
SDKMgr.Instance.SetLogined(true);
|
||||
//EventMgr.DispatchEvent<bool, UserInfo>(new CoreEvent<bool, UserInfo>(ECoreEventType.EID_SDK_LOGIN_RESULT_NEW, true, null));
|
||||
//SDKEventUtil.SendMessage(SDKCBEnum.LOGIN_SUCCESS_CB, null);
|
||||
|
||||
|
||||
SDKEventUtil.SendMessage(SDKCBEnum.LOGIN_SUCCESS_CB, arg);
|
||||
}
|
||||
|
||||
public void LogoutSuccessCB(object arg)
|
||||
|
||||
19
Assets/Resources/UnityPlayerAccountSettings.asset
Normal file
19
Assets/Resources/UnityPlayerAccountSettings.asset
Normal file
@ -0,0 +1,19 @@
|
||||
%YAML 1.1
|
||||
%TAG !u! tag:unity3d.com,2011:
|
||||
--- !u!114 &11400000
|
||||
MonoBehaviour:
|
||||
m_ObjectHideFlags: 0
|
||||
m_CorrespondingSourceObject: {fileID: 0}
|
||||
m_PrefabInstance: {fileID: 0}
|
||||
m_PrefabAsset: {fileID: 0}
|
||||
m_GameObject: {fileID: 0}
|
||||
m_Enabled: 1
|
||||
m_EditorHideFlags: 0
|
||||
m_Script: {fileID: 11500000, guid: b58a3bc647e70774b8c7225eb3b51e7e, type: 3}
|
||||
m_Name: UnityPlayerAccountSettings
|
||||
m_EditorClassIdentifier:
|
||||
clientId: 8b6bcc9f-bfab-477c-9c41-8495a6e8ac1f
|
||||
scopeMask: 7
|
||||
useCustomDeepLinkUri: 0
|
||||
customScheme:
|
||||
customHost:
|
||||
8
Assets/Resources/UnityPlayerAccountSettings.asset.meta
Normal file
8
Assets/Resources/UnityPlayerAccountSettings.asset.meta
Normal file
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 730ac908f9286de44bf8cc0b883ceb05
|
||||
NativeFormatImporter:
|
||||
externalObjects: {}
|
||||
mainObjectFileID: 11400000
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@ -284,6 +284,7 @@ public class GameMgr : SingletonMono<GameMgr>
|
||||
|
||||
private void OnLanuchLoadCompleted(bool success)
|
||||
{
|
||||
/*
|
||||
// wx94eecfb4cfafcde5
|
||||
var v1 = Convert.FromBase64String("d3g5NGVlY2ZiNGNmYWZjZGU1");
|
||||
// f00967e57166397a9ec8908b3626fdca
|
||||
@ -301,6 +302,9 @@ public class GameMgr : SingletonMono<GameMgr>
|
||||
EnterLuaLogin(false);
|
||||
}));
|
||||
|
||||
*/
|
||||
EnterLuaLogin(false);
|
||||
|
||||
}
|
||||
|
||||
public static string GetLocalIPAddress()
|
||||
@ -1177,6 +1181,8 @@ public class GameMgr : SingletonMono<GameMgr>
|
||||
if (mSdkInitedLuaCB != null)
|
||||
{
|
||||
mSdkInitedLuaCB.Call(this, true, SDKMgr.Instance.GetSDKName());
|
||||
Debug.Log("tzy_sdk init success"+SDKMgr.Instance.GetSDKName());
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user