!!!Webカメラ (モバイル) モバイル端末のカメラはWebCamTextureクラスにより情報を取得できます。 !!カメラ情報を取得 WebCamDevice [] devices = WebCamTexture.devices; for (int i = 0; i < devices.Length; i++) { string name = devices[i].name; // デバイス名. bool isFrontFacing = devices[i].isFrontFacing; // FrontFaceのカメラかどうか. Debug.Log(name + " isFrontFacing " + isFrontFacing); } WebCamTexture.devicesより対応しているカメラ一覧を取得します。 nameで名称を取得、isFrontFacingがtrueの場合は 端末から見て前側のカメラ撮影が可、となります。 !!カメラ用のテクスチャを作成 カメラ撮影は、指定のテクスチャ「WebCamTexture」で行われ、Materialにこのテクスチャを割り当てることが可能になっています。 動画であっても静止画であってもWebCamTextureを経由。 private WebCamTexture m_webCamTexture = null; void Start() { m_webCamTexture = new WebCamTexture("デバイス名", 320, 240, 10); } WebCamTextureのコンストラクタで、第一引数に WebCamTexture.devicesで取得したデバイス名を指定。 第二引数で撮影を行う幅、第三引数で撮影を行う高さ、第四引数で1秒間に撮影される画像数(fps)を指定します。 後は自動的にカメラからの撮影が行われます。 引数で指定したパラメータがデバイスでサポートされていない場合は、それに近いものが採用されるとのこと。 !!指定のMaterialにカメラで撮影したテクスチャを割り当て private Material m_webCamMat; private WebCamTexture m_webCamTexture = null; void Start() { // リソースとして用意した「webCamTextureMat」という名称のMaterialを保持. m_webCamMat = Resources.Load("materials/webCamTextureMat", typeof(Material)) as Material; // カメラ用のテクスチャ生成. m_webCamTexture = new WebCamTexture("デバイス名", 320, 240, 10); // Materialにカメラ用テクスチャを割り当て. if (m_webCamMat != null) { m_webCamMat.mainTexture = m_webCamTexture; m_webCamTexture.Play(); // 撮影の開始. } } 取得したMaterialのmainTexture にWebCamTexture を割り当て。 その後「m_webCamTexture.Play();」とすることで動画として撮影が開始されます。 !!撮影開始 m_webCamTexture.Play(); WebCamTexture のPlay()関数を呼ぶことで撮影が開始されます。 Pause後の再開もこの関数で行います。 !!撮影の一時中断 m_webCamTexture.Pause(); WebCamTexture のPause()関数を呼ぶことで撮影が一時停止されます。 Play()関数で再開。 ---- {{lastmodified}}