#region unity检测权限
public void ReqLiveAuth(UnityAction action)
{
StopCoReqCamera ();
m_CoReqCamera = StartCoroutine (SyncReqCamera(action));
}
IEnumerator SyncReqCamera(UnityAction action)
{
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam | UserAuthorization.Microphone);
WebCamDevice[] devices = WebCamTexture.devices;
yield return 0;
yield return Application.RequestUserAuthorization (UserAuthorization.Microphone);
string[] mics = Microphone.devices;
yield return 0;
if (!Application.HasUserAuthorization (UserAuthorization.WebCam) || !Application.HasUserAuthorization (UserAuthorization.Microphone)) {
//TODO
} else {
if (action != null) {
action.Invoke ();
}
}
yield break;
}
//停止协程
private void StopCoReqCamera()
{
if (m_CoReqCamera != null) {
StopCoroutine (m_CoReqCamera);
m_CoReqCamera = null;
}
}
#endregion
unity 检测相机麦克风权限
最新推荐文章于 2022-11-15 10:23:24 发布