Skip to content

Instantly share code, notes, and snippets.

@AtelierOfUnity
Created January 21, 2015 01:36
Show Gist options
  • Save AtelierOfUnity/13679f400ab7781c924a to your computer and use it in GitHub Desktop.
Save AtelierOfUnity/13679f400ab7781c924a to your computer and use it in GitHub Desktop.
WebCamTexture+ScreenShotで擬似カメラ(GUITexture版)
using UnityEngine;
using System.Collections;
public class WebCam_2DTex : MonoBehaviour {
public int camWidth_px = 1280;
public int camHeight_px = 720;
Vector2 pivotPoint;
int pivot_x;
int pivot_y;
WebCamTexture webcamTexture;
void Start () {
pivot_x = Screen.width / 2;
pivot_y = Screen.height / 2;
pivotPoint = new Vector2 (pivot_x, pivot_y);
var devices = WebCamTexture.devices;
if (devices.Length > 0){
webcamTexture = new WebCamTexture(camWidth_px,camHeight_px);
webcamTexture.Play();
}else{
Debug.Log("Webカメラが検出できませんでした");
return;
}
}
void OnGUI(){
//iPhone,Androidの場合はGuiTextureの向きを縦にする
if(Application.platform == RuntimePlatform.IPhonePlayer||Application.platform == RuntimePlatform.Android){
GUIUtility.RotateAroundPivot(90, pivotPoint);
}
GUI.DrawTexture(new Rect(pivot_x - (camWidth_px/2), pivot_y - (camHeight_px/2), camWidth_px,camHeight_px), webcamTexture);
}
//Sceneを変更する場合にカメラを止める
public void EndCam(){
webcamTexture.Stop ();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment