Unity.Platform.IPhone.IPhoneMedia.ShowCameraView C# (CSharp) Method

ShowCameraView() private method

private ShowCameraView ( ) : void
return void
		private void ShowCameraView ()
		{
			UIApplication.SharedApplication.InvokeOnMainThread (delegate {

			if(UIImagePickerController.IsSourceTypeAvailable(UIImagePickerControllerSourceType.Camera)) {

				UIImagePickerController imagePickerController = new UIImagePickerController();
				imagePickerController.SourceType = UIImagePickerControllerSourceType.Camera;
				
				if(cameraOptions != null) {
					if(cameraOptions.UseFrontCamera) {
						SystemLogger.Log(SystemLogger.Module.PLATFORM, "Setting front camera...");
						imagePickerController.CameraDevice = UIImagePickerControllerCameraDevice.Front;
					}

					if(cameraOptions.UseCustomCameraOverlay) {
						SystemLogger.Log(SystemLogger.Module.PLATFORM, "Using custom overlay...");
						
						UIScreen screen = UIScreen.MainScreen;
						SystemLogger.Log(SystemLogger.Module.PLATFORM, "device bounds width " + screen.Bounds.Width);
						SystemLogger.Log(SystemLogger.Module.PLATFORM, "device bounds height " + screen.Bounds.Height);
						CameraOverlayView overlay = new CameraOverlayView(imagePickerController, cameraOptions, 
								new CGRect(0, 0, screen.Bounds.Width, screen.Bounds.Height));

						// Hide the controls
						imagePickerController.ShowsCameraControls = false; // hide native camera controls
						imagePickerController.NavigationBarHidden = true;  // hide navigation bar
						imagePickerController.ToolbarHidden = true;  // hide toolbar (bottom)

						// Make camera view full screen:
						imagePickerController.WantsFullScreenLayout = true;

							nfloat cameraViewHeight = screen.Bounds.Width * CameraOverlayView.CAMERA_ASPECT_RATIO; 
						nfloat cameraVerticalOffset = (screen.Bounds.Height - cameraViewHeight) / 2f; // moves the preview exactly in the middle of the screen
						SystemLogger.Log(SystemLogger.Module.PLATFORM, "camera view height " + cameraViewHeight);
						SystemLogger.Log(SystemLogger.Module.PLATFORM, "camera vertical offset " + cameraVerticalOffset);

						CGAffineTransform translate = CGAffineTransform.Translate( imagePickerController.CameraViewTransform, 0.0f, cameraVerticalOffset); 
						imagePickerController.CameraViewTransform = translate;

						CGAffineTransform scale = CGAffineTransform.Scale(imagePickerController.CameraViewTransform, CameraOverlayView.CAMERA_ASPECT_RATIO, CameraOverlayView.CAMERA_ASPECT_RATIO);
						imagePickerController.CameraViewTransform = scale;

						// Insert the overlay in the picker controller
						imagePickerController.CameraOverlayView = overlay;
					}
				}
				
				imagePickerController.FinishedPickingMedia += HandleCameraFinishedPickingMedia;
				imagePickerController.Canceled += HandleImagePickerControllerCanceled;
				
				IPhoneServiceLocator.CurrentDelegate.MainUIViewController ().PresentModalViewController (imagePickerController, true);
				IPhoneServiceLocator.CurrentDelegate.SetMainUIViewControllerAsTopController(false);
			} else {
				INotification notificationService = (INotification)IPhoneServiceLocator.GetInstance ().GetService ("notify");
				if (notificationService != null) {
					notificationService.StartNotifyAlert ("Media Alert", "Camera is not available on this device.", "OK");
				}
			}
			});
		}