using UnityEngine.UI;
using UnityEngine;
public class OpenCamera : MonoBehaviour
{
/// <summary>顯示在此圖片上</summary>
RawImage rimgShow = null;
/// <summary>//接收攝影機返回的圖片數據</summary>
WebCamTexture myCam;
IEnumerator open_Camera()
{
//授權開啟鏡頭
yield return Application.RequestUserAuthorization(UserAuthorization.WebCam);
if(Application.HasUserAuthorization(UserAuthorization.WebCam))
{
//設置攝影機要攝影的區域
//(攝影機名稱, 攝影機要拍到的寬度, 攝影機要拍到的高度, 攝影機的FPS)
myCam = new WebCamTexture(WebCamTexture.devices[0].name, Screen.width, Screen.height, 60);
rimgShow.texture = myCam;
myCam.Play();//開啟攝影機
}
}
// Use this for initialization
void Start()
{
rimgShow = gameObject.GetComponent<RawImage>();
StartCoroutine(open_Camera());//開啟攝影機鏡頭
}
/// <summary>開啟攝影機</summary>
public void openCamera()
{
rimgShow.gameObject.SetActive(true);
myCam.Play();//開啟攝影機
}
/// <summary>消滅</summary>
void OnDisable()
{
//當程式關閉時會自動呼叫此方法關閉攝影機
myCam.Stop();
}
}
沒有留言:
張貼留言