using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
///
/// 创建一个留言板的时候由UI调用
///
public class CreatABoard : MonoBehaviour
{
///
/// 游戏内板子的预制体
///
public GameObject board;
private MyPlayer player;
private PlayerInfo sql;
public InputField inputField;
void Awake(){
Init();
}
void Start(){
}
void Update(){
if(CheckComfirm()){
StartCoroutine(CreatALocalBoard());
}
}
public void Creat(){
//player.GetComponent().SwitchCurrentActionMap("NullMap");
//Time.timeScale = 0;
}
void Init(){
//找到必要的物体和组件
player = FindObjectOfType();
sql = FindObjectOfType();
}
private IEnumerator CreatALocalBoard(){
//新建一个板子
Board temp = Instantiate(board,player.transform.position + new Vector3(0,0.3f,0),Quaternion.identity).GetComponent();
yield return new WaitForEndOfFrame();
//初始化板子
temp.uid = sql.uid;
temp.text = inputField.text;
temp.postion = temp.transform.position;
//关闭UI
gameObject.SetActive(false);
inputField.text = null;
//恢复玩家操作地图
//player.GetComponent().SwitchCurrentActionMap("Normal");
player.inControl = true;
player.GetComponent().constraints = RigidbodyConstraints2D.FreezeRotation;
//将板子信息传向云端
sql.CreateBoard(SceneManager.GetActiveScene().buildIndex,temp.postion,temp.text);
}
private bool CheckComfirm(){
//如果按下此帧按下此二键中的一个
return (Gamepad.current!= null &&
Gamepad.current.buttonSouth.wasPressedThisFrame) ||
Input.GetKeyDown(KeyCode.Return);
}
}