问:
Unity 3.5 release notes say there is support for the iOS Camera. Where is this documented?
I'm looking for a simple example of how to take a photo and apply it as a texture.
回答:
We were having a similar problem and got this reply from the great folks at Unity:
The cameras are accessed from the WebCamTexture class:-
http://unity3d.com/support/documentation/ScriptReference/WebCamTexture.html
When you create an instance of this class, you supply the name of the camera you want to use. A list of all cameras is available from the devices property. The entries in the list give the camera's name and whether or not it is front-facing. You could use code something like the following:-
function Start () { var devices : WebCamDevice[] = WebCamTexture.devices; var frontCamName: String; var backCamName: String; var frontTex: WebCamTexture; var backTex: WebCamTexture;
for( var i = 0 ; i < devices.length ; i++ ) { if (devices[i].isFrontFacing) { frontCamName = devices[i].name; } else { backCamName = devices[i].name; } } frontTex = new WebCamTexture(frontCamName, width, height, framesPerSec); backTex = new WebCamTexture(backCamName, width, height, framesPerSec);
}
The WebCamTexture also has Play, Pause and Stop functions and GetPixels/SetPixels (like Texture2D) to enable you to analyse the captured image data.
I hope this helps address your question as far as accessing the cameras. -wm