From 5ae8a9a51df414ff372d64556d8ddbf8c0f58474 Mon Sep 17 00:00:00 2001 From: Le Duc Anh Date: Tue, 3 Feb 2026 14:57:23 +0700 Subject: [PATCH] combine SDK with login UI --- Assets/PerfectWorld/Prefab/UIManager.prefab | 6 +-- .../PerfectWorld/Scripts/Common/Singleton.cs | 2 + .../Scripts/Network/UnityGameSession.cs | 4 ++ .../Scripts/Tech3CSDK/Tech3CSDKWrapper.cs | 21 ++++----- .../Scripts/UI/Action/CDlgSkillSubAction.cs | 2 - .../Scripts/UI/Inventory/CECSCItem.cs | 10 ----- .../Scripts/UI/Login/LoginScreenUI.cs | 44 ++++++++++++------- ProjectSettings/EditorBuildSettings.asset | 3 ++ ProjectSettings/ProjectSettings.asset | 4 +- 9 files changed, 54 insertions(+), 42 deletions(-) diff --git a/Assets/PerfectWorld/Prefab/UIManager.prefab b/Assets/PerfectWorld/Prefab/UIManager.prefab index da3ce713de..1f62ad0fcf 100644 --- a/Assets/PerfectWorld/Prefab/UIManager.prefab +++ b/Assets/PerfectWorld/Prefab/UIManager.prefab @@ -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 diff --git a/Assets/PerfectWorld/Scripts/Common/Singleton.cs b/Assets/PerfectWorld/Scripts/Common/Singleton.cs index 8a84813091..460a57c271 100644 --- a/Assets/PerfectWorld/Scripts/Common/Singleton.cs +++ b/Assets/PerfectWorld/Scripts/Common/Singleton.cs @@ -16,6 +16,8 @@ namespace BrewMonster { if (_instance.IsValueCreated) throw new InvalidOperationException($"Singleton<{typeof(T).Name}> already created!"); + + Initialize(); } protected virtual void Initialize() diff --git a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs index 8bd18a435c..be910eaca7 100644 --- a/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs +++ b/Assets/PerfectWorld/Scripts/Network/UnityGameSession.cs @@ -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) diff --git a/Assets/PerfectWorld/Scripts/Tech3CSDK/Tech3CSDKWrapper.cs b/Assets/PerfectWorld/Scripts/Tech3CSDK/Tech3CSDKWrapper.cs index 7b931f18ed..348554316c 100644 --- a/Assets/PerfectWorld/Scripts/Tech3CSDK/Tech3CSDKWrapper.cs +++ b/Assets/PerfectWorld/Scripts/Tech3CSDK/Tech3CSDKWrapper.cs @@ -13,8 +13,8 @@ namespace BrewMonster.Scripts public class Tech3CSDKWrapper : Singleton { - 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; diff --git a/Assets/PerfectWorld/Scripts/UI/Action/CDlgSkillSubAction.cs b/Assets/PerfectWorld/Scripts/UI/Action/CDlgSkillSubAction.cs index 7553bf9e76..1d518858fa 100644 --- a/Assets/PerfectWorld/Scripts/UI/Action/CDlgSkillSubAction.cs +++ b/Assets/PerfectWorld/Scripts/UI/Action/CDlgSkillSubAction.cs @@ -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 { diff --git a/Assets/PerfectWorld/Scripts/UI/Inventory/CECSCItem.cs b/Assets/PerfectWorld/Scripts/UI/Inventory/CECSCItem.cs index 8ab2bba4c8..8101130b87 100644 --- a/Assets/PerfectWorld/Scripts/UI/Inventory/CECSCItem.cs +++ b/Assets/PerfectWorld/Scripts/UI/Inventory/CECSCItem.cs @@ -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 diff --git a/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs b/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs index 9557fc7075..ee6024729e 100644 --- a/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs +++ b/Assets/PerfectWorld/Scripts/UI/Login/LoginScreenUI.cs @@ -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) diff --git a/ProjectSettings/EditorBuildSettings.asset b/ProjectSettings/EditorBuildSettings.asset index d8eb995fa9..fcbac00c16 100644 --- a/ProjectSettings/EditorBuildSettings.asset +++ b/ProjectSettings/EditorBuildSettings.asset @@ -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 diff --git a/ProjectSettings/ProjectSettings.asset b/ProjectSettings/ProjectSettings.asset index 2758853a70..7cb5db3a15 100644 --- a/ProjectSettings/ProjectSettings.asset +++ b/ProjectSettings/ProjectSettings.asset @@ -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