您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
70 行
1.7 KiB
70 行
1.7 KiB
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.InputSystem;
|
|
using TMPro;
|
|
|
|
public class UIPlayerDisplayBehaviour : MonoBehaviour
|
|
{
|
|
|
|
[Header("Input")]
|
|
public PlayerInput playerInput;
|
|
|
|
[Header("Device Display")]
|
|
public DeviceDisplayConfigurator deviceDisplayConfigurator;
|
|
|
|
[Header("UI")]
|
|
public TextMeshProUGUI playerDisplayText;
|
|
|
|
private int currentPlayerID;
|
|
private string currentPlayerDevice;
|
|
private Color currentDeviceColor;
|
|
|
|
void Start()
|
|
{
|
|
GetPlayerInputID();
|
|
GetPlayerDeviceDisplayName();
|
|
GetPlayerDeviceDisplayColor();
|
|
SetDeviceDisplayText();
|
|
}
|
|
|
|
void GetPlayerInputID()
|
|
{
|
|
currentPlayerID = playerInput.playerIndex;
|
|
}
|
|
|
|
void GetPlayerDeviceDisplayName()
|
|
{
|
|
currentPlayerDevice = deviceDisplayConfigurator.GetDeviceDisplayName(playerInput.devices[0].ToString());
|
|
}
|
|
|
|
void GetPlayerDeviceDisplayColor()
|
|
{
|
|
currentDeviceColor = deviceDisplayConfigurator.GetDeviceDisplayColor(playerInput.devices[0].ToString());
|
|
}
|
|
|
|
void SetDeviceDisplayText()
|
|
{
|
|
playerDisplayText.SetText("Player: " + (currentPlayerID + 1) + "\n" + currentPlayerDevice);
|
|
playerDisplayText.color = currentDeviceColor;
|
|
}
|
|
|
|
void SetDisconnectedDisplayText()
|
|
{
|
|
playerDisplayText.SetText("Player: " + (currentPlayerID + 1) + "\n" + "Device Disconnected!");
|
|
playerDisplayText.color = new Color(1,1,1,1);
|
|
}
|
|
|
|
//Device Callbacks from the new Input System ----
|
|
|
|
private void OnDeviceLost()
|
|
{
|
|
SetDisconnectedDisplayText();
|
|
}
|
|
|
|
private void OnDeviceRegained()
|
|
{
|
|
SetDeviceDisplayText();
|
|
}
|
|
|
|
}
|