예제 #1
0
 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;
     });
 }
예제 #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;
         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);
         }
     });
 }
예제 #3
0
 public static void Wait(WWW www, System.Action <WWW, bool> _callback)
 {
     if (instance == null)
     {
         GameObject go = GameObject.Find("Job");
         if (go == null)
         {
             go = new GameObject("Job");
         }
         WWWUtil comp = go.GetComponent <WWWUtil> () as WWWUtil;
         if (comp == null)
         {
             comp = go.AddComponent <WWWUtil>() as WWWUtil;
         }
         instance = comp;
     }
     if (instance.running)
     {
         _callback(null, false);
         return;
     }
     if (www == null)
     {
         Debug.LogError("Error WWW is null");
     }
     instance.running  = true;
     instance.target   = www;
     instance.callback = _callback;
     instance.StartCoroutine(instance.tmp());
 }
예제 #4
0
 /**
  * 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);
         });
     }
 }
예제 #5
0
        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 });
        }
예제 #6
0
 public WWWUtil() : base()
 {
     instance = null;
 }