69 lines
1.8 KiB
C#
69 lines
1.8 KiB
C#
![]() |
using System.Collections;
|
||
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using UnityEngine.UI;
|
||
|
using UnityEngine.InputSystem;
|
||
|
|
||
|
/// <summary>
|
||
|
/// 板子组件
|
||
|
/// </summary>
|
||
|
public class Board : Interactive
|
||
|
{
|
||
|
/// <summary>
|
||
|
/// 留言板内容
|
||
|
/// </summary>
|
||
|
public string text;
|
||
|
/// <summary>
|
||
|
/// 留言板主人的uid
|
||
|
/// </summary>
|
||
|
public int uid;
|
||
|
/// <summary>
|
||
|
/// 留言板位置
|
||
|
/// </summary>
|
||
|
public Vector2 postion;
|
||
|
private GameObject UI;
|
||
|
private Text textUI;
|
||
|
private Text UIDUI;
|
||
|
private MyPlayer player;
|
||
|
|
||
|
Board(Vector2 postion, int uid, string text){
|
||
|
this.postion = postion;
|
||
|
this.uid = uid;
|
||
|
this.text = text;
|
||
|
}
|
||
|
|
||
|
void Start(){
|
||
|
Init();
|
||
|
}
|
||
|
void Update(){
|
||
|
if(CheckComfirm()){
|
||
|
UI.SetActive(false);
|
||
|
player.GetComponent<PlayerInput>().SwitchCurrentActionMap("Normal");
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private void Init(){
|
||
|
UI = GameObject.Find("留言板相关").transform.GetChild(1).gameObject;
|
||
|
textUI = UI.GetComponent<RectTransform>().GetChild(0).GetChild(0).GetComponent<Text>();
|
||
|
UIDUI = UI.GetComponent<RectTransform>().GetChild(0).GetChild(1).GetComponent<Text>();
|
||
|
player = FindObjectOfType<MyPlayer>();
|
||
|
}
|
||
|
|
||
|
/// <summary>
|
||
|
/// 当玩家与留言板互动
|
||
|
/// </summary>
|
||
|
public override void OnCall(){
|
||
|
UI.SetActive(true);
|
||
|
textUI.text = text;
|
||
|
UIDUI.text = "UID:"+uid;
|
||
|
player.GetComponent<PlayerInput>().SwitchCurrentActionMap("NullMap");
|
||
|
}
|
||
|
|
||
|
private bool CheckComfirm(){
|
||
|
//如果按下此帧按下此二键中的一个
|
||
|
return (Gamepad.current!= null &&
|
||
|
Gamepad.current.buttonEast.wasPressedThisFrame) ||
|
||
|
Input.GetKeyDown(KeyCode.K);
|
||
|
}
|
||
|
}
|