Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 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
0
Question by LightStriker · Aug 11, 2013 at 08:31 PM · iosiphoneipad

Compile Time difference between iPad and iPhone

From: http://docs.unity3d.com/Documentation/Manual/PlatformDependentCompilation.html

I can see there's a tag "UNITY_IPHONE", which let you do in your code

 #if UNITY_PHONE
 #endif

And it will automatically include or exclude code paths that are relevant to the current platform.

However, I can't find a way to do that difference between an iPad and an iPhone. Both have different screen resolution, which means I have to layout my UI differently. The iOS store specifically support different version for iPad vs iPhone, but Unity would not support such differentiation?

Comment
Add comment
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

1 Reply

· Add your reply
  • Sort: 
avatar image
1

Answer by Joyrider · Aug 11, 2013 at 08:36 PM

the UNITY_IPHONE, actually means iOS, not a specific device.

It is for platform (not device) dependant compiling. And both iPad and iPhone actually use the same platform (iOS), and thus have the same inner workings.

As for your UI, use screen resolutions to set it up.

Comment
Add comment · Show 4 · 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
avatar image LightStriker · Aug 11, 2013 at 08:54 PM 0
Share

I know the Screen class. However, doing a layout on iPad vs on iPhone is not the same. The screen ratio isn't even the same. So am I forced to do something like if (ratio == 4/3) { } else if (ratio == 16/9) { }?

avatar image Joyrider · Aug 11, 2013 at 09:02 PM 0
Share

you could yes. We on the other hand, usually think our GUI with anchors and sizefactors, like:

 float sizeFactor = Screen.width/1024; // if your original UI positions/sizes are for the iPad2 for example
 
 GUI.Button(new Rect(Screen.width-(10+btnSize.x)*sizeFactor, Screen.height - (10+btnSize.y)*sizeFactor,btnSize.x*sizeFactor,btnSize.y*sizeFactor),"$$anonymous$$yButton");

So a button would always be at (10,10) from the bottom right of the screen for example if it has 1024 pixels horizontally.

So ins$$anonymous$$d of giving all your buttons a fixed position, they all have a fixed position compared to an anchor point; and thus adapt to the screen.

avatar image LightStriker · Aug 11, 2013 at 09:21 PM 0
Share

I built a library with many methods doing just that, which use position/size from whatever screen borders I want independently of the screen size. I never place anything on screen using "pixels". The problem is not the size itself, but the screen ratio. Something that looks good on a 4/3 may look horrible in a 16/9 giving space between items or overlapping them. Adding empty space on each side of my layout to pad the difference between resolution is not a good solution.

Example of what I use to position UI items;

 /// <summary>
 /// Return a rectangle which position is relative to the screen size.
 /// </summary>
 /// <param name="x">% horizontal</param>
 /// <param name="y">% vertical</param>
 /// <param name="width">% width</param>
 /// <param name="height">% height</param>
 /// <param name="position">The position is relative to which screen sides</param>
 /// <param name="scale">The scale is relative to which screen sides</param>
 public static Rect Relative(float x, float y, float width, float height, Bounds position, Bounds scale)
 {
     Rect result = new Rect(x, y, width, height);

     if (((scale & Bounds.Left) == Bounds.Left) || ((scale & Bounds.Right) == Bounds.Right))
         result.width = Screen.width * width;

     if (((scale & Bounds.Left) == Bounds.Left) || ((scale & Bounds.Right) == Bounds.Right))
         result.height = Screen.height * height;

     if ((position & (Bounds.Right | Bounds.Left)) == (Bounds.Right | Bounds.Left))
         result.x = (Screen.width * x - (result.width / 2));
     else if ((position & Bounds.Left) == Bounds.Left)
         result.x = Screen.width * x;
     else if ((position & Bounds.Right) == Bounds.Right)
         result.x = Screen.width * x - result.width;

     if ((position & (Bounds.Top | Bounds.Bottom)) == (Bounds.Top | Bounds.Bottom))
         result.y = (Screen.height * y - (result.height / 2));
     else if ((position & Bounds.Top) == Bounds.Top)
         result.y = Screen.height * y;
     else if ((position & Bounds.Bottom) == Bounds.Bottom)
         result.y = Screen.height * y - result.height;

     return result;
 }
avatar image Joyrider · Aug 11, 2013 at 09:25 PM 0
Share

Well then I guess your if(ratio){} does the trick. ;) This is anyway possible for iOS. I'm more used to Android, and since there are so many different aspect ratios, we just build our GUI to look good whatever the AR is. Because handling all possible ARs can be quite time consu$$anonymous$$g otherwise.

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

16 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Unity modules for iOS? 1 Answer

iPhone Controller Asset 0 Answers

iOS: Handheld.PlayFullScreenMovie 2 Answers

How to drag a scrollView with TouchPhase.Moved? 0 Answers

How to identify each iOS device? 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