using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using DG.Tweening;
using Sirenix.OdinInspector;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Opening : MonoBehaviour
{
///
/// 文本输入框组件
///
private InputField inputField;
private PlayerInfo sql;
void Start(){
Init();
}
private void Init(){
//找到必要的游戏物体和组件
inputField = FindObjectOfType();
sql = FindObjectOfType();
}
void Update(){
//检查是否触发确认输入事件
if(CheckComfirm())
StartCoroutine(GetTextAndFindUser());
}
///
/// 获取输入框内容,并检查是否有该用户
///
private IEnumerator GetTextAndFindUser(){
string inputUserName = inputField.text;
if(sql.hasName(inputUserName)){
//若已存在,拉取其信息
sql.uName = inputUserName;
sql.GetSqlData();
}
else{
//否则创建一个用户,再拉取其信息
sql.CreateUser(inputUserName);
sql.uName = inputUserName;
sql.GetSqlData();
}
//给玩家以数据库的数据
MyPlayer.progress = (MyPlayer.Progress)sql.rate;
//完成后进村
FindObjectOfType().OnCall(Blcak.Type.水平);
yield return new WaitForSeconds(1f);
SceneManager.LoadScene("cun");
}
private bool CheckComfirm(){
//如果按下此帧按下此二键中的一个
return (Gamepad.current!= null &&
Gamepad.current.buttonSouth.wasPressedThisFrame) ||
Input.GetKeyDown(KeyCode.Return);
}
}