Exemple #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));
        }
Exemple #2
0
        public static void OpenGallery(System.Action <Texture2D> callback, bool rotateImportedImage = true)
        {
            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);

                if (succeeded && !cancelled)
                {
                    LoadAssetFromAssetLibrary(path, ( Texture2D tex ) => {
                        callback(tex);
                    });
                }
                else
                {
                    Tastybits.NativeGallery.NativeGalleryController.LastPickedImagePath = "";
                    //string msg = cancelled ? "cancelled" : "";
                    callback(null);
                }
            }).name;

            AndroidCls.CallStatic("OpenGallery", new object[] { callbackId, rotateImportedImage });
        }
        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 });
        }