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