Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
2
Question by Tetrad · May 12, 2010 at 10:17 PM · rotationiphoneipadorientation

Making unity play nice with iPad and multiple interface orientations

I'm trying to take advantage of some Cocoa/iPhone OS features inside my Unity application on the iPad.

The current problem I'm running in to is that what cocoa thinks is going on and what the unity application thinks is going on with respect to the orientation of the device don't seem to be in sync. I would try to use a UIPopoverController for something, and the orientation of that would just follow the orientation of the device, whereas the game portion would stay fixed.

I managed to fix that by adding in this function in AppController.mm

- (void)application:(UIApplication *)application didChangeStatusBarOrientation:(UIInterfaceOrientation)oldStatusBarOrientation
{
    iphone::SetScreenOrientation((iphone::ScreenOrientation)[application statusBarOrientation]);
}

It's not perfect, but it's mostly functional. For my purposes having the game run in both landscape and portrait isn't a big deal, but I would imagine that most people would probably want to put in some kind of limitation in the app to prevent orientation switches to portrait types.

The next problem I ran in to is that the coordinate system for Unity GUI and a UIPopoverController don't seem to be the same on any orientation other than portrait.

For example, I have a GUI button that opens a UIPopoverController to do something. So code that looks like this:

void OnGUI()
{
    if( GUI.Button( new Rect( 5, 384, 100, 40 ), "Select Photo" ) )
    {
        SelectPhoto();
    }
}

(Where SelectPhoto eventually calls a function in native code that pushes a UIPopoverController with a photo picker.)

On the cocoa side, I have this code:

- (void)OpenImagePicker { UIImagePickerController* picker = [[[UIImagePickerController alloc] init] autorelease]; picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; picker.delegate = self; picker.allowsEditing = YES;

 self.popOver = [[[UIPopoverController alloc] initWithContentViewController:picker] autorelease];
 popOver.delegate = self;
 [popOver presentPopoverFromRect:CGRectMake( 5, 384, 100, 40 ) inView:view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

}

This only points to the button correctly in portrait. If I press the button in any other orientation it's pointing to some weird position. I'm assuming I'm going to need to change the rect that it's presenting from depending on the current interface orientation, but I'm somewhat stumped as to how to figure it out.

Also, weirdly enough, if I press the button in portrait and rotate to any given orientation, the popover points correctly to the button. It's only if I press it while I'm in a different orientation that it fails to work.

Question 1: How do I get cocoa-appropriate positions from unity screen positions?

Answered: I fiddled around with it for a bit and managed to make a function that seems to solve my problems:

- (CGRect)GetMuxedRect:(CGRect)portraitRect // this is the rect that we're using in Unity GUI
{
    switch( [[UIApplication sharedApplication] statusBarOrientation] )
    {
    case UIInterfaceOrientationPortrait:
        return portraitRect;
    case UIInterfaceOrientationPortraitUpsideDown:
        return CGRectMake( 768 - portraitRect.origin.x - portraitRect.size.width, 1024 - portraitRect.origin.y - portraitRect.size.height, portraitRect.size.width, portraitRect.size.height );
    case UIInterfaceOrientationLandscapeLeft:
        return CGRectMake( portraitRect.origin.y, 1024 - portraitRect.origin.x - portraitRect.size.width, portraitRect.size.height, portraitRect.size.width );
    case UIInterfaceOrientationLandscapeRight:
        return CGRectMake( portraitRect.origin.y - portraitRect.size.height, portraitRect.origin.x, portraitRect.size.height, portraitRect.size.width );
    default:
        return portraitRect;
    }
}

Question 2: What do I need to do with Unity cameras to make the horizontal FOV in landscape modes match the vertical FOV in portraits modes

Comment
Add comment · Show 3
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Jean-Fabre · Mar 10, 2011 at 12:38 PM 0
Share

Sigh, Too bad no one answers you, this is pertinant and running into similar issues.

avatar image TedB · Feb 23, 2012 at 05:16 PM 0
Share

I have created a related question: http://answers.unity3d.com/questions/220063/how-to-display-a-uipopover-on-ipad.html

avatar image TedB · Mar 30, 2012 at 05:22 PM 0
Share

Jesse, in your question you say "For example, I have a GUI button that opens a UIPopoverController to do something." You also said "(Where SelectPhoto eventually calls a function in native code that pushes a UIPopoverController with a photo picker.)"

Would you be willing to share how you did this? This gets to the heart of the answer for the related question I mentioned above.

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by thomasw · Aug 16, 2011 at 01:06 AM

This was a limitation with previous versions of Unity. With Unity 3.4 this issue is addressed:

http://unity3d.com/unity/whats-new/unity-3.4

http://answers.unity3d.com/questions/46492/ios-smooth-auto-rotation-of-orientation.html

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

2 People are following this question.

avatar image avatar image

Related Questions

How to set the video-playback orientation (iPhoneUtils.PlayMovie) 2 Answers

Screen orientation based on device for unified app 0 Answers

Unity iPhone/iPad autorotation 2 Answers

rotated GUI behaving differently on iphone and ipad 1 Answer

Does Unity iOS support GetPixels? 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges