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));
        }
        public static NativeIOSDelegate CreateNativeIOSDelegate(System.Action <System.Collections.Hashtable> methodToCall)
        {
            int rndId = UnityEngine.Random.Range(100000, 999999);
            int iter  = 0;

            while (GameObject.Find("NativeDelegate_" + rndId) != null && iter++ < 100)
            {
                rndId = UnityEngine.Random.Range(100000, 999999);
            }

            if (GameObject.Find("NativeDelegate_" + rndId) != null)
            {
                Debug.LogError("Error there is allready a callback existing");
                return(null);
            }

            GameObject delegRoot = GameObject.Find("NativeDelegates");

            if (delegRoot == null)
            {
                delegRoot = new GameObject("NativeDelegates");
            }


            GameObject goDeleg = new GameObject("NativeDelegate_" + rndId);

            goDeleg.transform.parent = delegRoot.transform;
            NativeIOSDelegate test = goDeleg.AddComponent <NativeIOSDelegate>() as NativeIOSDelegate;

            test.deleg = methodToCall;

            return(test);
        }
Exemple #3
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 });
        }