using System.Collections.Generic; using BrewMonster.Network; using CSNetwork.Protocols; using CSNetwork.Protocols.RPCData; using TMPro; using UnityEngine; using UnityEngine.UI; namespace BrewMonster.UI { /// /// Login Flow: /// 1. Enter username and password /// 2. Click login button /// 3. Login success, get the list of characters /// 4. Open the select character screen /// public class LoginScreenUI : MonoBehaviour { [SerializeField] private TMP_InputField _usernameInputField; [SerializeField] private TMP_InputField _passwordInputField; [SerializeField] private Button _loginButton; [SerializeField] private SelecScreenCharacter _selectCharacterScreen; private List _roleInfos; void Start() { _loginButton.onClick.AddListener(OnLoginButtonClicked); } // Update is called once per frame void Update() { if (_roleInfos != null) { _selectCharacterScreen.InitScreen(_roleInfos, OnClickSelectCharacter); _roleInfos = null; } } public async void OnLoginButtonClicked() { Logger.Log("OnLoginButtonClicked"); string username = _usernameInputField.text; string password = _passwordInputField.text; UnityGameSession.SetConnectionInfo("103.182.22.52", 29000); await UnityGameSession.Login(username, password, OnLoginComplete); } /// /// Callback when the login is complete. /// Then get the list of characters /// private void OnLoginComplete(bool result) { if (!result) { Logger.LogError("Login failed"); return; } UnityGameSession.GetRoleListAsync(OnGetRoleListComplete); } /// /// Callback when the list of characters is retrieved. /// Then move to the select character screen /// private void OnGetRoleListComplete(List roleInfos) { Logger.Log($"OnGetRoleListComplete {roleInfos.Count}"); _roleInfos = roleInfos; } private void OnClickSelectCharacter(RoleInfo roleInfo) { Logger.Log($"OnClickSelectCharacter {roleInfo.name}"); UnityGameSession.SelectRoleAsync(roleInfo, OnSelectRoleComplete); } private void OnSelectRoleComplete(RoleInfo roleInfo) { Logger.Log($"OnSelectRoleComplete {roleInfo.name} - {roleInfo.roleid}"); // now we have to enter the world UnityGameSession.SendProtocol( new enterworld() { Roleid = roleInfo.roleid, Provider_link_id = 0, L_timeout = 0, Localsid = 0, Locktime = 0, Settime = 0, Timeout = 0 } ); } #if UNITY_EDITOR private void OnValidate() { if (_usernameInputField == null) { // find childrend with name "username" _usernameInputField = transform.Find("username").GetComponent(); } if (_passwordInputField == null) { // find childrend with name "password" _passwordInputField = transform.Find("password").GetComponent(); } if (_loginButton == null) { // find childrend with name "LoginBtn" _loginButton = transform.Find("LoginBtn").GetComponent