Image Picker version 2.0 – Android Ultimate Plugin (1.7.4) for Unity3d

Today we added a new Feature on Android Ultimate Plugin for Unity3d and that is you can now get 2 or more images at the same time, well at first we thought that adding this feature is so easy but no it’s not that easy we need to create a Custom Gallery Activity for this because the simple Activity intent for getting more images on Android is not working i don’t know why that’s why we resort on doing this Custom Activity and this new feature required an Open Source Library and this is  Android Universal Image Loader created by Nostra13, we need this to for Caching of images and to load it faster on our Activity and to prevent crashed because of out of memory but  this is not 100% cure, out of memory can still happen specially on low spec devices so beware

Before anything else i want you to download the Universal Image Loader from this open source link https://github.com/nostra13/Android-Universal-Image-Loader/blob/master/downloads/universal-image-loader-1.9.5.jar

Or from this link if that link is down or gone

https://drive.google.com/file/d/0Bw14w3QBZaGxVWszZGZnMEdISlE/view?usp=sharing

and i want you to put this jar file (universal-image-loader-1.9.5.jar) on directory of your unity3d project “Assets/Plugins/Android/aup/libs”

And that’s it everything is set

Please check this sample usage on how to use it and it’s so easy right?

private ImagePickerPlugin imagePickerPlugin;
imagePickerPlugin = ImagePickerPlugin.GetInstance();

private Dispatcher dispatcher;
// needed to run the callback on the main thread
dispatcher = Dispatcher.GetInstance();

imagePickerPlugin.SetDebug(0);
// init image picker instance
imagePickerPlugin.Init();

// listen on events
imagePickerPlugin.OnGetImagesComplete += onGetImagesComplete;
imagePickerPlugin.OnGetImageCancel += onGetImageCancel;
imagePickerPlugin.OnGetImageFail += onGetImageFail;

// opens up a custom gallery for you to select images
imagePickerPlugin.GetImages();

private void onGetImagesComplete(string rawImagePath)
{
     dispatcher.InvokeAction(
        () =>
          {
             // do something here
             imagePaths = rawImagePath.Split(',');
  
             // load the texture
             rawImage1.texture = AUP.Utils.LoadTexture(imagePaths[0]);

             rawImage2.texture = AUP.Utils.LoadTexture(imagePaths[1]);
          }
      );
}

private void onGetImageCancel()
{  
    dispatcher.InvokeAction(
        () =>
          {
            // do something here
          }
    );
}

private void onGetImageFail()
{  
   dispatcher.InvokeAction(
        () =>
          {
             // do something here
          }
    );
}

 

Please Note that we need the Dispatcher if we want to do something after the callback to make sure that this codes will run on the Main Thread if not you will definitely encounter some errors or issues

And there you have it so easy right? , i hope this information helps you

For more questions or comments or suggestions just email us at gigadrillgames@gmail.com

See you! Thanks for Visiting and Reading 🙂

 

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.