/// <summary> /// 打开相册 选择多张照片 /// </summary> public static void OpenPhotos(Action <Texture2D[]> callBack) { NativeGallery.Permission permission = NativeGallery.GetImagesFromGallery((string[] path) => { if (path == null || path.Length == 0) { return; } Texture2D[] texs = new Texture2D[path.Length]; for (int i = 0; i < path.Length; i++) { try { if (!string.IsNullOrEmpty(path[i])) { texs[i] = NativeGallery.LoadImageAtPath(path[i]); } } catch (Exception ex) { Debug.LogWarning("第" + i + "张图片处理失败 : " + ex.Message + "\n" + path[i]); } } if (callBack != null) { callBack(texs); } }); if (permission != NativeGallery.Permission.Granted) { ShowToast("当前没有相册访问权限,请在设置中打开"); //打开应用程序设置 if (NativeGallery.CanOpenSettings()) { NativeGallery.OpenSettings(); } } }
// Image Handler public void AddImage() // Open Gallery and add image { if (NativeGallery.CanSelectMultipleFilesFromGallery()) { NativeGallery.MediaPickMultipleCallback multi_callback = new NativeGallery.MediaPickMultipleCallback(LoadImages); NativeGallery.GetImagesFromGallery(multi_callback); return; } NativeGallery.MediaPickCallback callback = new NativeGallery.MediaPickCallback(LoadImage); NativeGallery.GetImageFromGallery(callback); }
public void AddPicturesFromGalleryOnClick() { if (NativeGallery.IsMediaPickerBusy()) { return; } if (NativeGallery.CanSelectMultipleFilesFromGallery()) { NativeGallery.GetImagesFromGallery((paths) => HandlePictureAddition(paths), "Select pictures", "image/*"); } else { NativeGallery.GetImageFromGallery((path) => HandlePictureAddition(new[] { path }), "Select picture", "image/*"); } }
/// <summary> /// Launches the mobile devices native gallery so the user can pick 1 or more images. /// The file paths of these images are then saved and later loaded onto the GameBackground gameobject. /// Also sets the Dropdown menu to 'Custom' if successfully picked. /// </summary> public void PickImagePaths() { NativeGallery.Permission permission = NativeGallery.GetImagesFromGallery((paths) => { Debug.Log("Image path: " + paths); if (paths != null) { SetCustomPaths(paths); PlayerPrefsX.SetStringArray(ID + "_CustomPaths", paths); ChangeBackground(BackgroundFolders.Length); SetBackground(BackgroundFolders.Length); } }, "Select a PNG image", "image/png"); Variables.BackgroundsChanged = true; CheckPlayable(); }
private void LoadImagesFromGallery() { NativeGallery.Permission permission; if (NativeGallery.CanSelectMultipleFilesFromGallery()) { permission = NativeGallery.GetImagesFromGallery((paths) => { if (paths != null) { foreach (string path in paths) { Texture2D loadedTexture = LoadTextureFromGallery(path); LoadedTextures.Add(loadedTexture); } } if (LoadedTextures[0]) { gameController.LoadingOfImagesDone(); } }, title: "Select multiple images", mime: "image/*"); } else { permission = NativeGallery.GetImageFromGallery((path) => { if (path != null) { Texture2D loadedTexture = LoadTextureFromGallery(path); LoadedTextures.Add(loadedTexture); } if (LoadedTextures[0]) { gameController.LoadingOfImagesDone(); } }, title: "Select single image", mime: "image/*"); } }
/// <summary> /// 打开相册 选择多张照片 /// </summary> public static void OpenPhotos(Action <string[]> callBack) { NativeGallery.Permission permission = NativeGallery.GetImagesFromGallery((string[] path) => { if (path == null || path.Length == 0) { return; } if (callBack != null) { callBack(path); } }); if (permission != NativeGallery.Permission.Granted) { ShowToast("当前没有相册访问权限,请在设置中打开"); //打开应用程序设置 if (NativeGallery.CanOpenSettings()) { NativeGallery.OpenSettings(); } } }