Created
June 21, 2013 02:21
-
-
Save tsubaki/5828407 to your computer and use it in GitHub Desktop.
webcamのデモ。適当なcubeにアタッチして使う。カメラの初期化に時間がかかるため、SettingFOVは数フレーム待つか毎フレーム呼ぶ必要がある。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using UnityEngine; | |
using System.Collections; | |
public class WebCamTextureFOV : MonoBehaviour | |
{ | |
private WebCamTexture webcam = null; | |
private bool isPlaying = false; | |
public bool cameraPositionAuotSetting = true; | |
void Start () | |
{ | |
if (cameraPositionAuotSetting) { | |
transform.position = Vector3.zero; | |
Camera.mainCamera.transform.position = Vector3.zero + Vector3.back * 10; | |
} | |
} | |
void OnGUI () | |
{ | |
if (!isPlaying) { | |
if (GUILayout.Button ("camera on", GUILayout.Height (100))) { | |
CameraOn (); | |
isPlaying = true; | |
} | |
} else { | |
if (GUILayout.Button ("set FOV", GUILayout.Height (100))) { | |
SettingFOV (); | |
} | |
} | |
} | |
void CameraOn () | |
{ | |
webcam = new WebCamTexture (WebCamTexture.devices [0].name, 10000, 10000, 15); | |
renderer.material.mainTexture = webcam; | |
webcam.Play (); | |
} | |
void SettingFOV () | |
{ | |
transform.localScale = new Vector3 (webcam.width, webcam.height, 1); | |
Camera.mainCamera.orthographicSize = webcam.height / 2; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment