public static void OpenPhotoAlbum(System.Action <Texture2D, bool, string> callback) { UIImagePicker.Open(ImagePickerType.UIImagePickerControllerSourceTypeSavedPhotosAlbum, (bool succeeded, bool cancelled, string path) => { Debug.Log("Native Camera Saved image at path : " + path); bool ok = succeeded; var www = new WWW(path); if (ok && !cancelled) { WWWUtil.Wait(www, (WWW w, bool www_ok) => { string msg = (www_ok ? "" : "error loading file"); if (www_ok && w.texture == null) { www_ok = false; msg = "texture is null"; } callback(w.texture, www_ok, msg); }); } else { string msg = cancelled ? "cancelled" : ""; callback(null, false, msg); } Texture2D tex; }); }
public static void OpenPhotoAlbum(System.Action <Texture2D, bool, string> callback, bool rotateImageOnImport, ImagePickerType galleryType = ImagePickerType.UIImagePickerControllerSourceTypeSavedPhotosAlbum) { UIImagePicker.Open(galleryType, rotateImageOnImport, (bool succeeded, bool cancelled, string path) => { Debug.Log("Native Camera Saved image at path : " + path); bool ok = succeeded; var www = new WWW(path); if (ok && !cancelled) { Tastybits.NativeGallery.NativeGalleryController.LastPickedImagePath = path; WWWUtil.Wait(www, (WWW w, bool www_ok) => { string msg = (www_ok ? "" : "error loading file"); if (www_ok && w.texture == null) { www_ok = false; msg = "texture is null"; } callback(w.texture, www_ok, msg); }); } else { Tastybits.NativeGallery.NativeGalleryController.LastPickedImagePath = ""; string msg = cancelled ? "cancelled" : ""; callback(null, false, msg); } }); }
/** * Loads the asset from the assetlibrary. */ static void LoadAssetFromAssetLibrary(string assetUrl, System.Action <Texture2D> callback) { // Load using Native Method. if (LoadImageMethod == NativeGalleryController.LoadImageMethods.NativeLoading) { var bytes = LoadPngBytesFromPath(assetUrl, GetMaxTextureSize()); var tx = new Texture2D(2, 2); tx.LoadImage(bytes); callback(tx); } else // Load using WWW. { string path = assetUrl; var www = new WWW(path); Tastybits.NativeGallery.NativeGalleryController.LastPickedImagePath = path; WWWUtil.Wait(www, (WWW w, bool www_ok) => { //string msg = ( www_ok ? "" : "error loading file" ); if (www_ok && w.texture == null) { www_ok = false; //msg = "texture is null"; } callback(w.texture); }); } }
public static void OpenGallery(System.Action <Texture2D> callback) { if (Application.platform != RuntimePlatform.Android) { Debug.LogError("Cannot do this on a non Android platform"); } string callbackId = NativeIOSDelegate.CreateNativeIOSDelegate((System.Collections.Hashtable args) => { Debug.Log("NativeCallback returned"); bool succeeded = System.Convert.ToBoolean(args["succeeded"]); bool cancelled = System.Convert.ToBoolean(args["cancelled"]); string path = System.Convert.ToString(args["path"]); Debug.Log("AndroidGallery returned with succeeded = " + succeeded + " cancelled = " + cancelled + " path = " + path); var www = new WWW(path); if (succeeded && !cancelled) { WWWUtil.Wait(www, (WWW w, bool www_ok) => { string msg = (www_ok ? "" : "error loading file"); if (www_ok && w.texture == null) { www_ok = false; msg = "texture is null"; } callback(w.texture); }); } else { string msg = cancelled ? "cancelled" : ""; callback(null); } }).name; AndroidCls.CallStatic("OpenGallery", new object[] { callbackId }); }