スマホのカメラで撮影した画像を保存する、というアプリをunityで作ろうと思ってます。
とりあえず、以下のサイトのコードを参考にして実行してみました。(アンドロイド版のみ)
https://www.urablog.xyz/entry/2017/07/06/225444
https://gist.github.com/GOROman/2abc0a2c8b94a36935bf
自分が使用しているUnityはVer 2018.2.10fです
発生している問題・エラーメッセージ
エラーは特に出ていませんでした。
該当のソースコード
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using System.IO; public class WebCam : MonoBehaviour { [SerializeField] private int m_width = 1920; [SerializeField] private int m_height = 1080; [SerializeField] private RawImage m_displayUI = null; private WebCamTexture m_webCamTexture = null; public GameObject StartCamera; private IEnumerator Start() { if(WebCamTexture.devices.Length == 0) { Debug.LogFormat("カメラのデバイスが無いようだ。"); yield break; } else { Debug.LogFormat("カメラを確認しました。"); // yield break; } yield return Application.RequestUserAuthorization(UserAuthorization.WebCam ); if( !Application.HasUserAuthorization( UserAuthorization.WebCam )) { Debug.LogFormat("カメラを使う許可がされていません"); yield break; } else { Debug.LogFormat("カメラを使う許可がされました。"); } WebCamDevice userCameraDevice = WebCamTexture.devices[0]; m_webCamTexture = new WebCamTexture(userCameraDevice.name, m_width, m_height); m_webCamTexture.Play(); } private void Update() { } public void OnPlay() { if (m_webCamTexture == null) { return; } if (m_webCamTexture.isPlaying) { return; } m_webCamTexture.Play(); StartCamera.SetActive(true); } public void OnStop() { if (m_webCamTexture == null) { return; } if (!m_webCamTexture.isPlaying) { return; } m_webCamTexture.Stop(); StartCamera.SetActive(false); } } // class TestCamera
試したこと
Playボタンを押すとPCのカメラの横の光?みたいなのはm_webCamTexture.Play();を連動してついたり消えたりします。
カメラの検出や許可したときのメッセージもコンソールに出力されているのでできていると思います。
さっぱりわからないので何かしら教えていただけると幸いです。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2018/12/23 15:21
2018/12/24 00:11
2018/12/24 16:19
2018/12/25 04:14