George Fedoseev

Embedded Gallery v1.0

Unity Asset for accessing native gallery of iOS and Android devices without leaving Unity UI

OS Requirements:

 

Quick Start

From anywhere call static method EGPicker.OpenPicker(). Callback will be called with EGPickedItem. Use picked item to load Texture2D:

 

EGPicker

Main class to work with gallery picker. Contains methods to open picker and load textures.

EGPicker.OpenPicker()

Opens gallery picker on a separate canvas.

ParameterDescription
OnPickedItem (Action)Picked item callback. Can be called multiple times if multipleMode enabled.
pickerSkin (string)Picker sking to use. Default: "Standard"
OnCancel (Action)Picker dismiss callback. Default: null.
resetPicker (bool)If true then picker is recreated when loaded. Otherwise it's preserved from previous use. Default: false.
multipleMode (bool)If false, picker closes on first item selection. If true can select multiple items. Default: false.
cameraPicker (bool)If true adds camera viewfinder for capturing images. Default: false
capturedImagesAlbumName (string)Album name where to put images captured with camera. Default: null (if null then overriden later to Application.productName)
showAlbumSelector (bool)If true shows scrollable album selector strip on top of the picker. Default: true

Example Usage

EGPicker.LoadImageAsync()

Loads Texture2D asynchronously given item picked from picker.

ParameterDescription
driver (MonoBehaviour)MonoBehaviour to use for texture loadings coroutine.
pickedItem (EGPickedItem)Item to load.
maxResolution (int)Limit max resolution. 0 - no limit. Default: 0.

Example Usage

EGDataSource

Interface to native galleries and camera on Android and iOS + Editor Mockup

 

EGDataSource.GetAlbumsAsync()

Gets albums from native photo gallery on iOS or Android.

 

EGDataSource.GetThumbnailsAsync()

Gets thumbnails and image data (width, height) from native gallery in paginated manner. Prepares and returns paths to thumbnail images on native side.

ParameterDescription
page (int)Page to get
perPage (int)Items per page
albumId (string)Filter by album id. If empty string - no filtering (default).
approximateSize (int)Approximate thumbnails size to prepare.

EGDataSource.GetImageTextureAsync()

Returns Texture2D for specified native image id.

ParameterDescription
imageId (string)Id of image to return
driver (MonoBehaviour)MonoBehaviour that will be used for texture-loading coroutine
maxResolution (int)Limit resolution of the image. 0 - no limit (can be overriden later to SystemInfo.maxTextureSize if bigger).

 

EGDataSource.SaveImageAsync()

Saves texture to native gallery under specified album.

public static Task SaveImageAsync (Texture2D texture, string albumName)
ParameterDescription
texture (Texture2D)Texture2D to save
albumName (string)Album name where to put image

 

EGDataSource.CheckGalleryPermission()

Returns permission state for gallery access.

public static EGPermission CheckGalleryPermission ()

 

EGDataSource.RequestGalleryPermission()

Triggers native request for gallery permission.

public static EGPermission RequestGalleryPermission ()

 

EGDataSource.CheckCameraPermission()

Returns permission state for device camera access.

public static EGPermission CheckCameraPermission ()

 

EGDataSource.RequestCameraPermission()

Trigger native request for device camera access.

public static EGPermission RequestCameraPermission ()

 

EGDataSource.CanOpenSettings()

Determines if its possible to open settings for changing gallery permission.

public static bool CanOpenSettings ()

 

EGDataSource.OpenSettings()

Opens native Settings on the app's section to change permission.

public static void OpenSettings ()

EGConst

In this class you can customize constants such as text that appears to ask user for gallery access.