NovusX

native_camera_API

Jul 18th, 2021 (edited)
259
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. private void TakePicture( int maxSize )
  2. {
  3.     NativeCamera.Permission permission = NativeCamera.TakePicture( ( path ) =>
  4.     {
  5.         Debug.Log( "Image path: " + path );
  6.         if( path != null )
  7.         {
  8.             // Create a Texture2D from the captured image
  9.             Texture2D texture = NativeCamera.LoadImageAtPath( path, maxSize );
  10.             if( texture == null )
  11.             {
  12.                 Debug.Log( "Couldn't load texture from " + path );
  13.                 return;
  14.             }
  15.  
  16.             // Assign texture to a temporary quad and destroy it after 5 seconds
  17.             GameObject quad = GameObject.CreatePrimitive( PrimitiveType.Quad );
  18.             quad.transform.position = Camera.main.transform.position + Camera.main.transform.forward * 2.5f;
  19.             quad.transform.forward = Camera.main.transform.forward;
  20.             quad.transform.localScale = new Vector3( 1f, texture.height / (float) texture.width, 1f );
  21.            
  22.             Material material = quad.GetComponent<Renderer>().material;
  23.             if( !material.shader.isSupported ) // happens when Standard shader is not included in the build
  24.                 material.shader = Shader.Find( "Legacy Shaders/Diffuse" );
  25.  
  26.             material.mainTexture = texture;
  27.                
  28.             Destroy( quad, 5f );
  29.  
  30.             // If a procedural texture is not destroyed manually,
  31.             // it will only be freed after a scene change
  32.             Destroy( texture, 5f );
  33.         }
  34.     }, maxSize );
  35.  
  36.     Debug.Log( "Permission result: " + permission );
  37. }
  38.  
  39. private void RecordVideo()
  40. {
  41.     NativeCamera.Permission permission = NativeCamera.RecordVideo( ( path ) =>
  42.     {
  43.         Debug.Log( "Video path: " + path );
  44.         if( path != null )
  45.         {
  46.             // Play the recorded video
  47.             Handheld.PlayFullScreenMovie( "file://" + path );
  48.         }
  49.     } );
  50.  
  51.     Debug.Log( "Permission result: " + permission );
  52. }
Add Comment
Please, Sign In to add comment