UnityのWebGLビルドした際のCameraテスト
WebGLビルドの場合は、正しいカメラ解像度が取得できないようです。すべての3840x2160 60FPSの設定になるようです。
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using System.Linq;
using TMPro;
namespace SyskenTLib.SimpleFunction1.Camera
{
public class SimpleCamera : MonoBehaviour
{
[SerializeField]
private TMP_Dropdown _cameraListDropDown;
[SerializeField] private RawImage _cameraRawImage;
[SerializeField] private AspectRatioFitter _aspectRatioFitter;
[SerializeField] private TextMeshProUGUI _logText;
private WebCamTexture _currentCameraTexture;
// Start is called before the first frame update
void Start()
{
WebCamDevice[] cameraDevices = WebCamTexture.devices;
List dropdownValueList = new List();
cameraDevices.ToList().ForEach(cameraDevice =>
{
TMP_Dropdown.OptionData optionData = new TMP_Dropdown.OptionData();
optionData.text = cameraDevice.name;
dropdownValueList.Add(optionData);
});
_cameraListDropDown.options = dropdownValueList;
_cameraListDropDown.onValueChanged.AddListener(OnSelectDropdown);
}
private void OnSelectDropdown(int selectIndex)
{
if (_currentCameraTexture)
{
_currentCameraTexture.Stop();
}
WebCamDevice cameraDevice = WebCamTexture.devices[selectIndex];
_currentCameraTexture = new WebCamTexture(cameraDevice.name,3840,2160,60);
_currentCameraTexture.Play();
}
private void Update()
{
if (_currentCameraTexture)
{
_cameraRawImage.texture = _currentCameraTexture;
_aspectRatioFitter.aspectRatio = 1.0f*_currentCameraTexture.width / _currentCameraTexture.height;
if (_logText)
{
_logText.text = ""+_currentCameraTexture.deviceName
+" w:" + _currentCameraTexture.width
+ " h:" + _currentCameraTexture.height
+ " fps:" + _currentCameraTexture.requestedFPS;
}
}
}
}
}