Skip to content

Instantly share code, notes, and snippets.

@momo-the-monster
Created March 24, 2017 20:13
Show Gist options
  • Save momo-the-monster/7286b118d393be0172e1aaa77135e676 to your computer and use it in GitHub Desktop.
Save momo-the-monster/7286b118d393be0172e1aaa77135e676 to your computer and use it in GitHub Desktop.
public static WebCamTexture PrepareWebCamTexture (ref WebCamDevice device, bool frontFace, int width, int height)
{
WebCamTexture texture = null;
// Checks how many and which cameras are available on the device
for (int cameraIndex = 0; cameraIndex < WebCamTexture.devices.Length; cameraIndex++) {
if (WebCamTexture.devices [cameraIndex].isFrontFacing == frontFace) {
Debug.Log (cameraIndex + " name " + WebCamTexture.devices [cameraIndex].name
+ " isFrontFacing " + WebCamTexture.devices [cameraIndex].isFrontFacing);
device = WebCamTexture.devices [cameraIndex];
texture = new WebCamTexture (device.name, width, height);
break;
}
}
// fallback
if (texture == null) {
device = WebCamTexture.devices[0];
texture = new WebCamTexture (device.name, width, height);
}
Debug.Log ("width " + texture.width + " height " + texture.height + " fps " + texture.requestedFPS);
return texture;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment