combine SDK with login UI

This commit is contained in:
Le Duc Anh
2026-02-03 14:57:23 +07:00
parent d234076311
commit 5ae8a9a51d
9 changed files with 54 additions and 42 deletions
+3 -3
View File
@@ -2317,9 +2317,9 @@ RectTransform:
m_Children: []
m_Father: {fileID: 3233441867675090637}
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5}
m_AnchoredPosition: {x: 485, y: 371.6}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 49, y: -229.8}
m_SizeDelta: {x: 85, y: 92}
m_Pivot: {x: 0.5, y: 0.5}
--- !u!222 &7710645045682326551
@@ -16,6 +16,8 @@ namespace BrewMonster
{
if (_instance.IsValueCreated)
throw new InvalidOperationException($"Singleton<{typeof(T).Name}> already created!");
Initialize();
}
protected virtual void Initialize()
@@ -17,6 +17,7 @@ using BrewMonster.Scripts.Task;
using BrewMonster.UI;
using UnityEngine;
using UnityEngine.SceneManagement;
using BrewMonster.Scripts;
namespace BrewMonster.Network
{
@@ -220,6 +221,9 @@ namespace BrewMonster.Network
// When LoginScene is already loaded additively, Start() won't re-run.
// Force the login UI to refresh to the correct entry state immediately.
ApplyLoginEntryToUI(entryTarget);
// now we have to logout from Tech3C SDK
Tech3CSDKWrapper.Instance.Logout();
}
private static void ApplyLoginEntryToUI(LogoutFlowState.LoginEntryTarget entryTarget)
@@ -13,8 +13,8 @@ namespace BrewMonster.Scripts
public class Tech3CSDKWrapper : Singleton<Tech3CSDKWrapper>
{
public string clientId = "";
public string clientSecret = "";
public string clientId = "tghh";
public string clientSecret = "1nBnWnUJadlqzlcd7x7uibXZwW9Bxx9h";
private AuthCallback authCallback;
private LogoutCallback logoutCallback;
@@ -56,7 +56,7 @@ namespace BrewMonster.Scripts
BMLogger.Log("[SDK] Client ID and/or Client Secret not set. Please configure in Inspector.");
}
BMLogger.Log("[SDK] Tech3C SDK Simple Demo Started");
BMLogger.Log("[SDK] Tech3C SDK Started");
isInitialized = true;
}
@@ -152,19 +152,19 @@ namespace BrewMonster.Scripts
{
if (!isInitialized)
{
BMLogger.LogError("[SDK] SDK is not initialized, please call Initialize() first");
BMLogger.LogError("[SDK] [Login] SDK is not initialized, please call Initialize() first");
return false;
}
if (isProcessing)
{
BMLogger.LogError("[SDK] SDK is already processing a request, please wait for the current request to complete");
BMLogger.LogError("[SDK] [Login] SDK is already processing a request, please wait for the current request to complete");
return false;
}
if (onLoginCallback == null)
{
BMLogger.LogError("[SDK] Login callback is not set, please set it using SetLoginCallback");
BMLogger.LogError("[SDK] [Login] Login callback is not set, please set it using SetLoginCallback");
return false;
}
@@ -178,24 +178,25 @@ namespace BrewMonster.Scripts
{
if (!isInitialized)
{
BMLogger.LogError("[SDK] SDK is not initialized, please call Initialize() first");
BMLogger.LogError("[SDK] [Logout] SDK is not initialized, please call Initialize() first");
return false;
}
if (isProcessing)
{
BMLogger.LogError("[SDK] SDK is already processing a request, please wait for the current request to complete");
BMLogger.LogError("[SDK] [Logout] SDK is already processing a request, please wait for the current request to complete");
return false;
}
if (onLogOutCallback == null)
{
BMLogger.LogError("[SDK] Logout callback is not set, please set it using SetLogoutCallback");
BMLogger.LogError("[SDK] [Logout] Logout callback is not set, please set it using SetLogoutCallback");
return false;
}
isProcessing = true;
//TODO: Check again after 3C resolve the callback issue.
// isProcessing = true;
Tech3CSDK.Instance.Logout(logoutCallback);
return true;
@@ -4,8 +4,6 @@ using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
using static UnityEditor.AddressableAssets.Build.Layout.BuildLayout;
namespace BrewMonster
{
@@ -1,15 +1,5 @@
using BrewMonster.Network;
using BrewMonster.Scripts.Skills;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.VisualScripting;
using static BrewMonster.SkillArrayWrapper;
using UnityEngine;
using BrewMonster.Scripts.Managers;
using UnityEditorInternal.Profiling.Memory.Experimental;
using BrewMonster.Scripts;
namespace BrewMonster
@@ -42,6 +42,18 @@ namespace BrewMonster.UI
_ = Tech3CSDKWrapper.Instance;
}
void OnEnable()
{
Tech3CSDKWrapper.Instance.SetLoginCallback(OnLoginCallback);
Tech3CSDKWrapper.Instance.SetLogoutCallback(OnLogoutCallback);
}
private void OnDisable()
{
Tech3CSDKWrapper.Instance.RemoveLoginCallback();
Tech3CSDKWrapper.Instance.RemoveLogoutCallback();
}
void Start()
{
AudioManager.Instance.PlayBGM(loginBGM, 1.5f);
@@ -62,10 +74,7 @@ namespace BrewMonster.UI
if (_selectCharacterScreen != null)
_selectCharacterScreen.gameObject.SetActive(false);
Tech3CSDKWrapper.Instance.SetLoginCallback(OnLoginCallback);
Tech3CSDKWrapper.Instance.SetLogoutCallback(OnLogoutCallback);
ApplyLoginEntry(BrewMonster.Network.LogoutFlowState.ConsumeNextLoginEntry());
ApplyLoginEntry(LogoutFlowState.ConsumeNextLoginEntry());
}
// Update is called once per frame
@@ -94,12 +103,6 @@ namespace BrewMonster.UI
}
private void OnDisable()
{
Tech3CSDKWrapper.Instance.RemoveLoginCallback();
Tech3CSDKWrapper.Instance.RemoveLogoutCallback();
}
public async void OnLoginButtonClicked()
{
if (_loginInProgress)
@@ -111,14 +114,25 @@ namespace BrewMonster.UI
_loginInProgress = true;
if (_loginButton != null) _loginButton.interactable = false;
// Use Tech3C SDK login UI.
bool started = Tech3CSDKWrapper.Instance.Login();
if (!started)
// If username or password is empty, use Tech3C SDK login UI.
if (string.IsNullOrEmpty(_usernameInputField.text) || string.IsNullOrEmpty(_passwordInputField.text))
{
// Fallback: manual username/password login (useful in dev if SDK not configured).
BMLogger.LogWarning("[LoginScreenUI] Tech3CSDKWrapper.Login() failed, fallback to manual login.");
// Use Tech3C SDK login UI.
bool started = Tech3CSDKWrapper.Instance.Login();
if (!started)
{
// Fallback: manual username/password login (useful in dev if SDK not configured).
BMLogger.LogWarning("[LoginScreenUI] Tech3CSDKWrapper.Login() failed, fallback to manual login.");
await BeginGameLoginAsync(_usernameInputField.text, _passwordInputField.text);
}
}
else
{
// otherwise use manual username/password login.
BMLogger.LogError("[LoginScreenUI] Username/password empty.");
await BeginGameLoginAsync(_usernameInputField.text, _passwordInputField.text);
}
}
private async Task BeginGameLoginAsync(string username, string password)
@@ -23,6 +23,9 @@ EditorBuildSettings:
- enabled: 0
path: Assets/Scenes/MonsterRender.unity
guid: fdaaa6dd81a1845a9826745163a927ef
- enabled: 0
path: Assets/Scenes/SampleScene.unity
guid: 9fc0d4010bbf28b4594072e72b8655ab
m_configObjects:
com.unity.addressableassets: {fileID: 11400000, guid: 224e456928aaa4603b0c4a9ec48ee013, type: 2}
m_UseUCBPForAssetBundles: 0
+2 -2
View File
@@ -256,9 +256,9 @@ PlayerSettings:
clonedFromGUID: 00000000000000000000000000000000
templatePackageId:
templateDefaultScene:
useCustomMainManifest: 0
useCustomMainManifest: 1
useCustomLauncherManifest: 0
useCustomMainGradleTemplate: 0
useCustomMainGradleTemplate: 1
useCustomLauncherGradleManifest: 0
useCustomBaseGradleTemplate: 0
useCustomGradlePropertiesTemplate: 0