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 Start(){ Init(); } void Update(){ if(CheckComfirm()){ StartCoroutine(CreatALocalBoard()); } } void Init(){ //找到必要的物体和组件 player = FindObjectOfType(); sql = FindObjectOfType(); } private IEnumerator CreatALocalBoard(){ Debug.Log("执行了新建"); //新建一个板子 Board temp = Instantiate(board,player.transform.position + new Vector3(0,0.4f,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"); //将板子信息传向云端 sql.CreateBoard(SceneManager.GetActiveScene().buildIndex,temp.postion,temp.text); } private bool CheckComfirm(){ //如果按下此帧按下此二键中的一个 return (Gamepad.current!= null && Gamepad.current.buttonSouth.wasPressedThisFrame) || Input.GetKeyDown(KeyCode.Return); } }