Created
January 19, 2015 23:41
-
-
Save AtelierOfUnity/210b2d83596319b7d5b5 to your computer and use it in GitHub Desktop.
WebCamTexture+ScreenShotで擬似カメラ
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; | |
using UnityEngine.UI; | |
using System.IO; | |
public class ScreenShot : MonoBehaviour { | |
public void Shot(){ | |
string format = "yyyy-MM-dd-HH-mm-ss"; | |
string fileName = System.DateTime.Now.ToString (format)+".png"; | |
//スクリーンショット撮影(保存先はApplication.persistentDataPath直下) | |
Application.CaptureScreenshot(fileName); | |
string filePath = ""; | |
// select platform | |
switch (Application.platform) { | |
case RuntimePlatform.IPhonePlayer: | |
filePath = Application.persistentDataPath + "/"+fileName; | |
break; | |
case RuntimePlatform.Android: | |
filePath = Application.persistentDataPath + "/"+fileName; | |
break; | |
default: | |
filePath = fileName; | |
break; | |
} | |
//ファイルの保存を待つ処理 | |
StartCoroutine (ImageCheck(filePath)); | |
} | |
IEnumerator ImageCheck(string _filePath){ | |
while (File.Exists (_filePath) == false) { | |
yield return new WaitForSeconds(0.2f); // | |
} | |
Debug.Log("OK");; | |
} | |
} |
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 WebCam : MonoBehaviour { | |
public GameObject Quad; | |
public int camWidth_px = 1280; | |
public int camHeight_px = 720; | |
WebCamTexture webcamTexture; | |
void Start () { | |
var devices = WebCamTexture.devices; | |
if (devices.Length > 0) | |
{ | |
var euler = transform.localRotation.eulerAngles; | |
webcamTexture = new WebCamTexture(camWidth_px,camHeight_px); | |
//iPhone,Androidの場合はカメラの向きを縦にする | |
if(Application.platform == RuntimePlatform.IPhonePlayer||Application.platform == RuntimePlatform.Android){ | |
transform.localRotation = Quaternion.Euler( euler.x, euler.y, euler.z - 90 ); | |
} | |
renderer.material.mainTexture = webcamTexture; | |
webcamTexture.Play(); | |
}else | |
{ | |
Debug.Log("Webカメラが検出できませんでした"); | |
return; | |
} | |
} | |
//Sceneを変更する場合にカメラを止める | |
public void EndCam(){ | |
webcamTexture.Stop (); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment