powerfun-unity/Assets/Scripts/Scenes/LoginController.cs

81 lines
2.2 KiB
C#
Raw Normal View History

2021-03-26 16:36:31 +08:00
using Assets.Scripts;
using DG.Tweening;
2021-03-25 16:55:36 +08:00
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection;
using System.Text;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
2021-03-25 17:53:48 +08:00
public class LoginController : MonoBehaviour
2021-03-25 16:55:36 +08:00
{
[SerializeField] InputField phone;
[SerializeField] InputField pwd;
[SerializeField] Button login;
[SerializeField] RawImage loading;
// Start is called before the first frame update
void Start()
{
2021-03-26 16:36:31 +08:00
transform.Find("RawImage").DOMove(new Vector3(0.5f,0.5f,0),1);
2021-03-25 16:55:36 +08:00
if (login != null)
{
login.onClick.AddListener(Submit);
}
if (loading != null)
{
loading.texture.wrapMode = TextureWrapMode.Repeat;
}
}
async void Submit()
{
if (phone == null || pwd == null)
{
Utils.showToast(gameObject, "未绑定", 1);
return;
}
//if (string.IsNullOrEmpty(phone.text) || string.IsNullOrEmpty(pwd.text))
//{
// Utils.showToast(gameObject, "请输入信息", 1);
// return;
//}
//var res = await Global.userApi.Login(phone.text, pwd.text, "");
//测试用
2021-03-25 17:53:48 +08:00
var res = await ConfigHelper.userApi.Login("15651831367", "123456", "");
2021-03-25 16:55:36 +08:00
//var res = await NoAuthApi.Login(phone.text, pwd.text);
if (res.result)
{
2021-03-25 17:53:48 +08:00
ConfigHelper.CurrentUser = res.data;
2021-03-25 16:55:36 +08:00
SceneManager.LoadScene("2-Main");
}
else
{
}
}
// Update is called once per frame
void Update()
{
2021-03-26 16:36:31 +08:00
Debug.Log($"{phone.isFocused}, ${pwd != null}, ${Input.GetKeyDown(KeyCode.Tab)}");
2021-03-25 16:55:36 +08:00
if (phone.isFocused && pwd != null && Input.GetKeyDown(KeyCode.Tab))
{
pwd.ActivateInputField();
}
//if (Input.GetKeyDown(KeyCode.Return) && )
//{
//}
//if (Input.GetKeyDown(KeyCode.Return)) {
// Debug.Log("回车键");
// if (pwd.isFocused)
// {
// this.Submit();
// }
//}
}
}