Version: Unity 6.0 (6000.0)
言語 : 日本語
ウェブキャンバスサイズの設定
ウェブネットワーク

ウェブブラウザーによるデバイス機能へのアクセス

Unity ウェブプラットフォームは WebCam へのアクセスをサポートしています。ウェブアプリケーションがデバイス上のウェブカメラにアクセスできるようにするには、ブラウザーでカメラへのアクセスをユーザーにリクエストする必要があります。カメラにアクセスする権限がないと、ブラウザーは不完全または不正確な情報を返します。

注意現在、ウェブプラットフォームは WebCam デバイスのみをサポートしています。

ブラウザーでウェブカメラへのアクセス権限をリクエストするには、Application.RequestUserAuthorization APIを使用します。

using UnityEngine;
using UnityEngine.iOS;
using System.Collections;

// Get WebCam information from the browser
public class ExampleClass : MonoBehaviour
{
    private WebCamDevice[] devices;
    
    // Use this for initialization
    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");
        }
    }
}

注意Unity は、MediaDevices.getUserMedia() API を使用して、デバイスにアクセスするためのユーザー権限をリクエストすることを推奨しています。この機能は、セキュアコンテキスト (HTTPS) でのみ使用できます。

ウェブキャンバスサイズの設定
ウェブネットワーク