@ParseMachine

Как получить доступ к камере устройства в браузере, приложение WebGL Unity?

Пробую создать простое приложение на Unity. В нем хочу реализовать доступ к камере устройства. Реализовал решение, оно работает отлично на билдах для конкретных платформ. Например: андроид, винда. Там доступ к камере получается без проблем. Пермишн запрашивается, но как только я собираю WebGL и деплою, там в консоли показывает, что просто 0 камер доступно. Хотя на устройстве они есть. Код приложил внизу, строка "Debug.LogError($"DEVICES AMOUNT {WebCamTexture.devices.Length}");" - выводит 0 в браузере и нормальное кол-во на устройстве. Помогите решить, пожалуйста, гуглил уже, пробовал варианты, но не выходит

using System.Collections;
using UnityEngine;
using UnityEngine.UI;

namespace MultiWebcam
{
    public sealed class CameraController : MonoBehaviour
    {
        [SerializeField] private RawImage _display;

        private WebCamDevice[] devices;
        private WebCamTexture _texture;
        private int _currentCameraIndex = 0;

        private void Awake()
        {
            StartCoroutine(Start());
        }

        private IEnumerator Start()
        {
            yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
            if (Application.HasUserAuthorization(UserAuthorization.WebCam))
            {
                Debug.Log("webcam found");
                devices = WebCamTexture.devices;
                for (int cameraIndex = 0; cameraIndex < devices.Length; ++cameraIndex)
                {
                    Debug.Log("devices[cameraIndex].name: ");
                    Debug.Log(devices[cameraIndex].name);
                    Debug.Log("devices[cameraIndex].isFrontFacing");
                    Debug.Log(devices[cameraIndex].isFrontFacing);
                }
            }
            else
            {
                Debug.Log("no webcams found");
            }
        }

        public void SwapCamera()
        {
            if (WebCamTexture.devices.Length > 0)
            {
                _currentCameraIndex++;
                _currentCameraIndex %= WebCamTexture.devices.Length;

                if (_texture != null)
                {
                    StopCamera();
                    StartCamera();
                }
            }
        }

        public void StartCamera()
        {
            Debug.LogError($"USER PERMISSION {Application.HasUserAuthorization(UserAuthorization.WebCam)}");
            Debug.LogError($"DEVICES AMOUNT {WebCamTexture.devices.Length}");

            if (WebCamTexture.devices.Length > 0)
            {
                WebCamDevice device = WebCamTexture.devices[_currentCameraIndex];
                _texture = new WebCamTexture(device.name);
                _display.texture = _texture;

                _texture.Play();
                Debug.LogError($"START PLAYING!");
            }
        }

        public void StopCamera()
        {
            if (_texture != null)
            {
                _texture.Stop();
                _display.texture = null;
                _texture = null;
            }
        }
    }
}
  • Вопрос задан
  • 115 просмотров
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы