62 lines
1.8 KiB
C#
62 lines
1.8 KiB
C#
![]() |
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;
|
||
|
|
||
|
void Start(){
|
||
|
Init();
|
||
|
}
|
||
|
|
||
|
void Update(){
|
||
|
if(CheckComfirm()){
|
||
|
StartCoroutine(CreatALocalBoard());
|
||
|
}
|
||
|
}
|
||
|
|
||
|
void Init(){
|
||
|
//找到必要的物体和组件
|
||
|
player = FindObjectOfType<MyPlayer>();
|
||
|
sql = FindObjectOfType<PlayerInfo>();
|
||
|
}
|
||
|
|
||
|
private IEnumerator CreatALocalBoard(){
|
||
|
Debug.Log("执行了新建");
|
||
|
//新建一个板子
|
||
|
Board temp = Instantiate(board,player.transform.position + new Vector3(0,0.4f,0),Quaternion.identity).GetComponent<Board>();
|
||
|
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<PlayerInput>().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);
|
||
|
}
|
||
|
}
|