示例#1
0
        private static string Open(ImagePickerType type, bool transformOnImport, System.Action <bool, bool, string> deleg)

        {
            if (Application.platform != RuntimePlatform.IPhonePlayer)
            {
                Debug.LogError("Error not running on iOS");

                deleg(false, false, "");

                return("");
            }

            Debug.Log("Opening UIImagePicker with type:" + type);

            return(_ImagePickerOpen((int)type, true, transformOnImport, NativeIOSDelegate.CreateNativeIOSDelegate((System.Collections.Hashtable args) => {
                bool succeeded = System.Convert.ToBoolean(args["succeeded"]);

                bool cancelled = System.Convert.ToBoolean(args["cancelled"]);

                string path = System.Convert.ToString(args["path"]);

                Debug.Log("UIImagePicker returned with succeeded = " + succeeded + " cancelled = " + cancelled + " path = " + path);

                deleg(succeeded, cancelled, path);
            }).name));
        }
示例#2
0
        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;

                path = path.Replace("file:/", "file:///");

                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);
                }
            });
        }