public void SetPhotoResolution(int width, int height) { if (NatCam.IsPlaying) { Ext.Warn("Cannot set photo resolution when preview is running"); return; } #if UNITY_IOS if (NatCam.Interface == NatCamInterface.NativeInterface) { Native.SetPhotoResolution(this, width, height); } else { Ext.Warn("Cannot set photo resolution on fallback interface"); } #elif UNITY_ANDROID if (NatCam.Interface == NatCamInterface.NativeInterface) { Native.A.Call("SetPhotoResolution", (int)this, width, height); } else { Ext.Warn("Cannot set photo resolution on fallback interface"); } #else Ext.Warn("Cannot set photo resolution on fallback interface"); #endif }
public void SetResolution(int width, int height) { if (NatCam.IsPlaying) { Ext.Warn("Cannot set resolution when preview is running"); return; } #if UNITY_IOS if (NatCam.Interface == NatCamInterface.NativeInterface) { Native.SetResolution(this, width, height); } else { requestedResolution = new Vector2(width, height); } #elif UNITY_ANDROID if (NatCam.Interface == NatCamInterface.NativeInterface) { Native.A.Call("SetResolution", (int)this, width, height); } else { requestedResolution = new Vector2(width, height); } #else requestedResolution = new Vector2(width, height); #endif }
public void SetFramerate(float framerate) { if (NatCam.IsPlaying) { Ext.Warn("Cannot set frame rate when preview is running"); return; } #if UNITY_IOS if (NatCam.Interface == NatCamInterface.NativeInterface) { Native.SetFramerate(this, framerate); } else { requestedFramerate = framerate; } #elif UNITY_ANDROID if (NatCam.Interface == NatCamInterface.NativeInterface) { Native.A.Call("SetFramerate", (int)this, framerate); } else { requestedFramerate = framerate; } #else requestedFramerate = framerate; #endif }
public void SetFocus(Vector2 viewportPoint) { //Check that this camera is active if (NatCam.ActiveCamera.index != index) { Ext.Warn("This camera is not the NatCam ActiveCamera. SetFocus might fail"); } #if UNITY_IOS if (NatCam.Interface == NatCamInterface.NativeInterface) { Native.SetFocus(this, viewportPoint.x, viewportPoint.y); } else { Ext.Warn("SetFocus is not supported on the fallback interface"); } #elif UNITY_ANDROID if (NatCam.Interface == NatCamInterface.NativeInterface) { Native.A.Call("SetFocus", (int)this, viewportPoint.x, viewportPoint.y); } else { Ext.Warn("SetFocus is not supported on the fallback interface"); } #else Ext.Warn("SetFocus is not supported on the fallback interface"); #endif }
public static void Pause() { switch (Interface) { case NatCamInterface.NativeInterface: Native.Pause(); break; case NatCamInterface.FallbackInterface: Fallback.Pause(); break; } }
public static void SaveToPhotos(Texture2D photo, SaveMode saveMode = SaveMode.SaveToPhotoGallery) //DEPLOY { if (Interface == NatCamInterface.FallbackInterface) { Ext.Warn("Cannot save photo on fallback interface"); return; } if (saveMode == SaveMode.DoNotSave) { Ext.Warn("Don't ask me to save a photo then say I shouldn't :/"); //Sassy return; } Native.SaveToPhotos(photo, (int)saveMode); }
public static void Release() { DeviceCamera.Reset(); switch (Interface) { case NatCamInterface.NativeInterface: Native.Release(); break; case NatCamInterface.FallbackInterface: Fallback.Release(); break; } }
public static void Play(DeviceCamera camera = null) { switch (Interface) { case NatCamInterface.NativeInterface: if (camera != null) { Native.mActiveCamera = camera; } Native.Play(); break; case NatCamInterface.FallbackInterface: if (camera != null) { Fallback.mActiveCamera = camera; } Fallback.Play(); break; } }
public static void CapturePhoto(params PhotoCallback[] callbacks) { if (!IsPlaying) { Ext.Warn("Cannot capture photo when session is not running"); return; } if (callbacks.Length == 0 && OnPhotoCapture == null) { Ext.Warn("Cannot capture photo because there is no callback subscribed"); return; } else if (callbacks.Length > 0) { for (int i = 0; i < callbacks.Length; i++) { PhotoCallback callback = callbacks[i]; PhotoCallback captureWrapper = null; captureWrapper = (Texture2D photo) => { if (callback != null) { callback(photo); } OnPhotoCapture -= captureWrapper; }; OnPhotoCapture += captureWrapper; } } if (Interface == NatCamInterface.NativeInterface) { Native.CapturePhoto(); } else { Fallback.CapturePhoto(); } }
public static void Initialize(NatCamInterface NatCamInterface = NatCamInterface.NativeInterface, PreviewType PreviewType = PreviewType.NonReadable, Switch MetadataDetection = Switch.Off) { Interface = NatCamInterface; if (Interface == NatCamInterface.NativeInterface && !IsSupportedDevice) { Ext.Warn("Running on an unsupported platform or a device without cameras. Falling back to Fallback"); Interface = NatCamInterface.FallbackInterface; } switch (Interface) { case NatCamInterface.NativeInterface: Native.Initialize(PreviewType, MetadataDetection == Switch.On); Native.RegisterEvents(PropagateStart, PropagateUpdate, PropagatePhoto, PropagateBarcode, PropagateFace, SetApplicationFocus); break; case NatCamInterface.FallbackInterface: Fallback.Initialize(MetadataDetection == Switch.On); Fallback.RegisterEvents(PropagateStart, PropagateUpdate, PropagatePhoto, PropagateBarcode, PropagateFace, SetApplicationFocus); break; default: goto case NatCamInterface.FallbackInterface; } }