此示例项目是为了演示 Unity 输入系统的各种工具和功能。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

72 行
2.1 KiB

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
public class PlayerVisualsBehaviour : MonoBehaviour
{
//Player ID
private int playerID;
private PlayerInput playerInput;
[Header("Device Display Settings")]
public DeviceDisplayConfigurator deviceDisplaySettings;
[Header("Sub Behaviours")]
public PlayerUIDisplayBehaviour playerUIDisplayBehaviour;
[Header("Player Material")]
public SkinnedMeshRenderer playerSkinnedMeshRenderer;
private int clothingTintShaderID;
public void SetupBehaviour(int newPlayerID, PlayerInput newPlayerInput)
{
playerID = newPlayerID;
playerInput = newPlayerInput;
SetupShaderIDs();
UpdatePlayerVisuals();
}
void SetupShaderIDs()
{
clothingTintShaderID = Shader.PropertyToID("_Clothing_Tint");
}
public void UpdatePlayerVisuals()
{
UpdateUIDisplay();
UpdateCharacterShader();
}
void UpdateUIDisplay()
{
playerUIDisplayBehaviour.UpdatePlayerIDDisplayText(playerID);
string deviceName = deviceDisplaySettings.GetDeviceName(playerInput);
playerUIDisplayBehaviour.UpdatePlayerDeviceNameDisplayText(deviceName);
Color deviceColor = deviceDisplaySettings.GetDeviceColor(playerInput);
playerUIDisplayBehaviour.UpdatePlayerIconDisplayColor(deviceColor);
}
void UpdateCharacterShader()
{
Color deviceColor = deviceDisplaySettings.GetDeviceColor(playerInput);
playerSkinnedMeshRenderer.material.SetColor(clothingTintShaderID, deviceColor);
}
public void SetDisconnectedDeviceVisuals()
{
string disconnectedName = deviceDisplaySettings.GetDisconnectedName();
playerUIDisplayBehaviour.UpdatePlayerDeviceNameDisplayText(disconnectedName);
Color disconnectedColor = deviceDisplaySettings.GetDisconnectedColor();
playerUIDisplayBehaviour.UpdatePlayerIconDisplayColor(disconnectedColor);
playerSkinnedMeshRenderer.material.SetColor(clothingTintShaderID, disconnectedColor);
}
}