【发布时间】:2017-04-04 16:16:25
【问题描述】:
我正在使用以下脚本来启用/禁用 WebGL 上的网络摄像头。
它在编辑器上工作正常,但在浏览器上,网络摄像头灯在禁用 WebcamTexture 后保持亮起。
它发生在 Chrome 和 Firefox 上。
有什么想法吗?
谢谢。
WebCamTexture _webcamTexture;
public void Enable()
{
#if UNITY_EDITOR || DEVELOPMENT_BUILD
Debug.Log("Enable");
#endif
_enabled = true;
}
public void Disable()
{
#if UNITY_EDITOR || DEVELOPMENT_BUILD
Debug.Log("Disable");
#endif
_enabled = false;
}
#region MONOBEHAVIOUR
void Update()
{
if(_enabled)
{
if(_webcamTexture == null)
{
while(!Application.RequestUserAuthorization(UserAuthorization.WebCam).isDone)
{
return;
}
if (Application.HasUserAuthorization(UserAuthorization.WebCam))
{
#if UNITY_EDITOR || DEVELOPMENT_BUILD
Debug.Log("Webcam authorized");
#endif
_webcamTexture = new WebCamTexture (WebCamTexture.devices[0].name);
_webcamTexture.Play ();
}
else
{
#if UNITY_EDITOR || DEVELOPMENT_BUILD
Debug.Log("Webcam NOT authorized");
#endif
}
}
else if (_webcamTexture.isPlaying)
{
if(!_ready)
{
if (_webcamTexture.width < 100)
{
return;
}
_ready = true;
}
if(_webcamTexture.didUpdateThisFrame)
{
_aspectRatioFitter.aspectRatio = (float)_webcamTexture.width / (float)_webcamTexture.height;
_imageRectTransform.localEulerAngles = new Vector3 (0, 0, -_webcamTexture.videoRotationAngle);
_image.texture = _webcamTexture;
}
}
}
else
{
if(_webcamTexture != null)
{
_webcamTexture.Stop ();
_webcamTexture = null;
_image.texture = null;
}
}
}
#endregion
【问题讨论】:
标签: c# unity3d camera webcam unity-webgl