请求在 iOS 上使用网络摄像头或麦克风,以及在 WebGL 上仅使用网络摄像头的授权。
Application.RequestUserAuthorization
用于请求麦克风和摄像头的权限。应用程序会向用户显示一个对话框,并等待操作完成,然后才能使用这些功能。
注意: 使用 Application.HasUserAuthorization 查询操作的结果。
using UnityEngine; using UnityEngine.iOS; using System.Collections;
// Show WebCams and Microphones on an iPhone/iPad. // Make sure NSCameraUsageDescription and NSMicrophoneUsageDescription // are in the Info.plist.
public class ExampleClass : MonoBehaviour { IEnumerator Start() { FindWebCams();
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam); if (Application.HasUserAuthorization(UserAuthorization.WebCam)) { Debug.Log("webcam found"); } else { Debug.Log("webcam not found"); }
FindMicrophones();
yield return Application.RequestUserAuthorization(UserAuthorization.Microphone); if (Application.HasUserAuthorization(UserAuthorization.Microphone)) { Debug.Log("Microphone found"); } else { Debug.Log("Microphone not found"); } }
void FindWebCams() { foreach (var device in WebCamTexture.devices) { Debug.Log("Name: " + device.name); } }
void FindMicrophones() { foreach (var device in Microphone.devices) { Debug.Log("Name: " + device); } } }