Log in or register to post comments

Vuforia as subview in iOS capturing all touches?

September 27, 2013 - 2:23am #1

I have created a very simple project, and exported it to Xcode. Then I've modified the AppDelegate to use my own storyboard and set _unityView as a subview inside my UI.

It works, camera works, tracking works, but all touches either to the native UI or to the Unity view seem to be ignored.

Has anyone been in the same situation? Any ideas where to look?

Vuforia as subview in iOS capturing all touches?

October 21, 2014 - 2:48pm #13

How would you recommend going about adding a button to close the Camera view and revert back to the root view controller? I am in need of adding simple back functionliaty once I am able to get Vuforia launching within a separate view. Thank you in advance!

Vuforia as subview in iOS capturing all touches?

April 3, 2014 - 2:49am #12

Great to hear :)

N

Vuforia as subview in iOS capturing all touches?

April 2, 2014 - 10:55pm #11

Update:

It works for me now. When I added a navigation controller to storyboard, it works as charm. Thanks.

Vuforia as subview in iOS capturing all touches?

March 26, 2014 - 5:48am #10

Hi Sorry,

I am unable to share the source at present.

Please check again as you must have missed a step or two.  Also worth checking the Unity thread mentioned.

 

N

 

 

Vuforia as subview in iOS capturing all touches?

March 25, 2014 - 12:02am #9

NalinS,

Could you share the source code of your project?

I did as your suggestion, but the program only load storyboard scene, no Unity scene.

Thanks,

ThachNH

Vuforia as subview in iOS capturing all touches?

October 7, 2013 - 3:20am #8

I was setting the Storyboard both on the project settings and loading it by code.

Yes - I've done that before ;)

 

Glad it's working!

 

N

 

Vuforia as subview in iOS capturing all touches?

October 4, 2013 - 6:03am #7

Found it! Doh!

I was setting the Storyboard both on the project settings and loading it by code. This caused it to be loaded twice, so the touches were going to the first one, but the rendering was the second one!

When I implemented your version, it crashed as it was calling viewDidLoad twice, with different ViewControllers addresses. That was it!

So either load storyboards by code or on the plist, but not both. 

Now excuse me while I go bang my head against some big, solid tree. :D

Vuforia as subview in iOS capturing all touches?

October 3, 2013 - 9:38am #6

I had a look at your code, but I cannot tell you why you are not getting any touches.

 

However I was able to build another two samples from scratch (with and without Vuforia) that do receive touches.  The basic approach is outlined on this Unity thread:

http://forum.unity3d.com/threads/191971-Unity-AppController-subclassing/page2

 

Here is what I did:

First,  I built a standard Image Targets App.

Next I copied a storyboard into the XCode project which has a navigation controller that leads on to my own native UI view controller as the root one (the idea is to push a button which pushes a new Unity Vuforia window on top)

Next I subclassed the UnityAppController to create an extension as recommended:

 

#import <UIKit/UIKit.h>

#import "UnityAppController.h"

#import "UI/UnityView.h"

#import "iPhone_View.h"

 

@interface MyAppController : UnityAppController

{

}

 

 

 

- (void)createViewHierarchyImpl;

 

@end

 

@implementation MyAppController

 

- (void)createViewHierarchyImpl

{

    UIStoryboard *storyBoard    = [UIStoryboard storyboardWithName:@"Main" bundle:nil];

    UIViewController *mainVC    = [storyBoard instantiateInitialViewController];

 

    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

    

    self.window.rootViewController = mainVC;

    _rootController             = [self.window rootViewController];

    _rootView                   = _rootController.view;

        

}

@end

 

IMPL_APP_CONTROLLER_SUBCLASS(MyAppController)

 

Then I added the following class for my ViewController with .h and .mm files respectively:

 

#import <UIKit/UIKit.h>

#import "iPhone_View.h"

 

@interface NalinViewController : UIViewController

 

@property (strong, nonatomic) UnityDefaultViewController *unityVC;

 

@end

 

 

 

 

#import "NalinViewController.h"

#import "UnityAppController.h"

 

@interface NalinViewController ()

 

 

@end

 

@implementation NalinViewController

 

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil

{

    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];

    if (self) {

        // Custom initialization

    }

    return self;

}

 

- (void)viewDidLoad

{

    [super viewDidLoad];

// Do any additional setup after loading the view.

    

    _unityVC = [[UnityDefaultViewController alloc] init];    

    

    UnityAppController* appController = (UnityAppController*)[UIApplication sharedApplication].delegate;

    _unityVC.view = (UIView*)appController.unityView;

}

 

- (IBAction)goButton:(id)sender {

    

    // need to set this so subsequent view controllers know the size

    [self.navigationController pushViewController:_unityVC animated:YES];

 

 

}

 

 

- (void)didReceiveMemoryWarning

{

    [super didReceiveMemoryWarning];

    // Dispose of any resources that can be recreated.

}

 

- (void)dealloc {

    [super dealloc];

}

- (void)viewDidUnload {

    [super viewDidUnload];

}

@end

 

 

Finally I added the following at line 59 in UnityAppController 

 

@property (strong, nonatomic) UIWindow *window;

 

...because iOS needs this in order to pickup the storyboard.

 

Then build and run, and hopefully it all works as expected.

Give it a try and let me know how you get on.

 

N

 

 

 

 

 

Vuforia as subview in iOS capturing all touches?

September 30, 2013 - 6:50am #5

Would you like me to upload the project somewhere for you to check?

Yes, that would be great.

If you can upload two Unity projects one with and one without Vuforia that would be ideal.  Presumably this will have the xcode project inside as well?

 

cheers,

N

Vuforia as subview in iOS capturing all touches?

September 29, 2013 - 4:50am #4

As for the exact setup:

  1. Export Unity+Vuforia project. One image marker with a light and a sphere. All default settings.
  2. On XCode:
    1. Replace AppControllerClassName in main.mm to point to a AppController subclass (call it CustomAppController). A the "UIWindow *window" property.
    2. CustomAppController overrides - (void) createViewHierarchyImpl. Loads a storyboard, instantiates the initial ViewController and sets _rootController and _rootView (see below).
    3. The storyboard MainViewController starts, on viewWillAppear adds the AppController's unityView as a subview of the container UIView. 

The view presents right, unity content shows, vuforia works and shows the camera, etc. The problem is that while "pure unity content" does not interfere with the rest of the UI, vuforia does.

Would you like me to upload the project somewhere for you to check?

- (void)createViewHierarchyImpl {
    NSString *storyBoardName;
    if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad)
    {
        storyBoardName = @"MainStoryboard";
        // The device is an iPad running iPhone 3.2 or later.
    }
    else
    {
        storyBoardName = @"MainStoryboard~iphone";
        // The device is an iPhone or iPod touch.
    }
    UIStoryboard *storyBoard    = [UIStoryboard storyboardWithName:storyBoardName bundle:nil];
    UIViewController *mainVC    = [storyBoard instantiateInitialViewController];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = mainVC;
    
    _rootController             = [self.window rootViewController];
    _rootView                   = _rootController.view;
}

 

Vuforia as subview in iOS capturing all touches?

September 28, 2013 - 2:35am #3

Ok, I'm using XCode 5, Unity 4.2.1, vuforia 2.6.7. A simple unity, non-vuforia project (just a cube), doesn't interfere with touches on the rest of the UIKit UI (a simple UIButton). Both on iOS6 (iPhone 4) and iOS7 (iPad).

A simple vuforia project (one marker, a sphere), on both platforms, makes the UIKit buttons (over or apart of the GLView) unresponsive.

It's like the vuforia part is either hogging the main UI thread or capturing all events (probably more the former as buttons outside the glview don't respond either).

We've done several vuforia+iOS projects with UIKit controls, and that's the first time we've had problems. We are not doin anything intensive (UIKit animations or the like).

Vuforia as subview in iOS capturing all touches?

September 27, 2013 - 10:08am #2

Well, this is cutting edge, so I am not surprised that you are seeing problems.

I am more surprised you managed to get any input out of Unity within the generated project :O

How did you set things up?

 

The place this is being discussed is over at the Unity forums:

http://forum.unity3d.com/threads/191971-Unity-AppController-subclassing/page2

 

I have tried a sample project with and without Vuforia, but so far neither is registering any touches at all when inside a storyboard based app.

 

N

Log in or register to post comments