104 lines
2.5 KiB
C#
104 lines
2.5 KiB
C#
using System;
|
|
using Gameplay.Net;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
|
|
|
|
public class UILoginController : UIWindow
|
|
{
|
|
private TMPro.TMP_InputField _Input;
|
|
private TMP_Dropdown dropdown;
|
|
|
|
public override void OnInit()
|
|
{
|
|
|
|
}
|
|
|
|
private void Awake()
|
|
{
|
|
|
|
dropdown = GameObject.Find("Dropdown_LogIn").GetComponent<TMP_Dropdown>();
|
|
dropdown.onValueChanged.AddListener(onValueChanged);
|
|
|
|
UpadteDropdownSeverName();
|
|
|
|
_Input = FindObj("InputField_LogIn").GetComponent<TMPro.TMP_InputField>();
|
|
string account = PlayerPrefs.GetString("LoginAccount", "");
|
|
_Input.text = account;
|
|
BindButton("Login/Login", OnButtonLogin);
|
|
|
|
}
|
|
|
|
|
|
public void onValueChanged(int value)
|
|
{
|
|
AppConfig.Instance.Select(value);
|
|
|
|
PlayerPrefs.SetInt("ServerIndex", value);
|
|
|
|
return;
|
|
}
|
|
|
|
private void UpadteDropdownSeverName()
|
|
{
|
|
dropdown.options.Clear();
|
|
var serverInfo = AppConfig.Instance.GetServerInfo();
|
|
if (serverInfo.Count <= 0)
|
|
{
|
|
return;
|
|
}
|
|
|
|
foreach (var item in serverInfo)
|
|
{
|
|
dropdown.options.Add(new TMP_Dropdown.OptionData() { text = item.name });
|
|
}
|
|
var index = PlayerPrefs.GetInt("ServerIndex", 0);
|
|
|
|
if(index >= 0 && index <= serverInfo.Count)
|
|
{
|
|
dropdown.captionText.text = serverInfo[index].name;
|
|
dropdown.value = index;
|
|
}
|
|
else
|
|
{
|
|
dropdown.captionText.text = serverInfo[0].name;
|
|
dropdown.value = 0;
|
|
}
|
|
|
|
AppConfig.Instance.Select(index);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Select(int nIndex)
|
|
{
|
|
var serverInfo = AppConfig.Instance.GetServerInfo();
|
|
var getCurrent = AppConfig.Instance.GetCurrent();
|
|
if (nIndex >= serverInfo.Count)
|
|
{
|
|
getCurrent = serverInfo[0];
|
|
DebugUtil.LogError("AppConfig Select nIndex:{0} >= m_ServerInfos.Count:{1}, set default as 0", nIndex, serverInfo.Count);
|
|
return;
|
|
}
|
|
getCurrent = serverInfo[nIndex];
|
|
|
|
}
|
|
|
|
private async void OnButtonLogin()
|
|
{
|
|
PlayerPrefs.SetString("LoginAccount", _Input.text);
|
|
Gameplay.Net.Actor.Instance.StartLogin(NLDPB.LoginType.Phxh, _Input.text);
|
|
}
|
|
|
|
public override void OnRelease()
|
|
{
|
|
// EventManager.Instance.Unregister(EventManager.EventName.NetLoginServerInfo, OnNameSend);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
|
|
}
|
|
}
|