Unityについて質問があります。これが以前に答えられていないことを願っています。カメラ (HD カムなど) をコンピューターに接続したいのですが、ビデオ フィードを Unity シーン内に表示する必要があります。カメラが見ているものをリアルタイムで表示する仮想テレビ画面のようなものだと考えてください。これどうやってするの?Google は正しい方向を示してくれませんでしたが、クエリを正しく取得できないだけかもしれません ;)
私が何をしようとしているのか理解していただければ幸いです。
Unityについて質問があります。これが以前に答えられていないことを願っています。カメラ (HD カムなど) をコンピューターに接続したいのですが、ビデオ フィードを Unity シーン内に表示する必要があります。カメラが見ているものをリアルタイムで表示する仮想テレビ画面のようなものだと考えてください。これどうやってするの?Google は正しい方向を示してくれませんでしたが、クエリを正しく取得できないだけかもしれません ;)
私が何をしようとしているのか理解していただければ幸いです。
それが役立つ場合は、上記の受け入れられた回答に基づいて、C# スクリプトとして記述された回答を投稿しています (受け入れられた回答は JavaScript でした)。このスクリプトを、レンダラーがアタッチされているゲームオブジェクトにアタッチするだけで機能します。
public class DisplayWebCam : MonoBehaviour
{
void Start ()
{
WebCamDevice[] devices = WebCamTexture.devices;
// for debugging purposes, prints available devices to the console
for(int i = 0; i < devices.Length; i++)
{
print("Webcam available: " + devices[i].name);
}
Renderer rend = this.GetComponentInChildren<Renderer>();
// assuming the first available WebCam is desired
WebCamTexture tex = new WebCamTexture(devices[0].name);
rend.material.mainTexture = tex;
tex.Play();
}
}
@LeeStemKoski の例から作業して、未加工の画像を使用して Web カメラのテクスチャを再生する例を作成し、Web カメラを UI に追加できるようにしました。
public class DisplayWebCam : MonoBehaviour
{
[SerializeField]
private UnityEngine.UI.RawImage _rawImage;
void Start()
{
WebCamDevice[] devices = WebCamTexture.devices;
// for debugging purposes, prints available devices to the console
for (int i = 0; i < devices.Length; i++)
{
print("Webcam available: " + devices[i].name);
}
//Renderer rend = this.GetComponentInChildren<Renderer>();
// assuming the first available WebCam is desired
WebCamTexture tex = new WebCamTexture(devices[0].name);
//rend.material.mainTexture = tex;
this._rawImage.texture = tex;
tex.Play();
}
}
** 編集 **
これは非常に自明ですが、念のため: このスクリプトを の 1 つに添付するGameObject
と、その に「Raw Image」フォーム フィールドが表示されgui information panel
ます。フォーム フィールドにGameObject
ドラッグ アンド ドロップできますUI RawImage GameObject
。