Skip to content

Instantly share code, notes, and snippets.

@dddnuts
Created April 30, 2016 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dddnuts/86e7bd5bf23dc3507e10bc16e7cf6f05 to your computer and use it in GitHub Desktop.
Save dddnuts/86e7bd5bf23dc3507e10bc16e7cf6f05 to your computer and use it in GitHub Desktop.
An Unity iOS plugin to pick images from the album.
//
// DDDImagePickerPlugin.mm
// Unity-iPhone
//
// Created by dddnuts on 4/29/16.
//
//
#import <Foundation/Foundation.h>
#import <QBImagePicker/QBImagePicker.h>
@interface DDDImagePickerDelegate : NSObject<QBImagePickerControllerDelegate>
+(instancetype)sharedInstance;
@end
@implementation DDDImagePickerDelegate
+(instancetype)sharedInstance
{
static DDDImagePickerDelegate *instance;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
instance = [DDDImagePickerDelegate new];
});
return instance;
}
-(void)qb_imagePickerControllerDidCancel:(QBImagePickerController *)imagePickerController
{
UIViewController *unityViewController = UnityGetGLViewController();
[unityViewController dismissViewControllerAnimated:YES completion:nil];
// TODO: Send message to Unity.
}
-(void)qb_imagePickerController:(QBImagePickerController *)imagePickerController didFinishPickingAssets:(NSArray *)assets
{
UIViewController *unityViewController = UnityGetGLViewController();
[unityViewController dismissViewControllerAnimated:YES completion:nil];
// TODO: Send message with selected images to Unity.
}
@end
extern "C" {
void DDDImagePicker_Open() {
QBImagePickerController *picker = [QBImagePickerController new];
picker.allowsMultipleSelection = YES;
picker.maximumNumberOfSelection = 2;
picker.showsNumberOfSelectedAssets = YES;
picker.delegate = [DDDImagePickerDelegate sharedInstance];
UIViewController *unityViewController = UnityGetGLViewController();
[unityViewController presentViewController:picker animated:YES completion:nil];
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment