Author Topic: Is it required to use OrthographicSize equal to 1 for UI camera?  (Read 4655 times)

user123

  • Guest
I'm using 2D UI with UIRoot.ScalingStyle set to FixedSize with ManualHeight equal to 640. This causes UIRoot's transform to be scaled. It is very uncomfortable for me to use scaled UI root. For example, when instantiating UI prefabs I forced to set its scale to ONE in script after attaching to UIRoot.

To make UIRoot scale equal to ONE I've set ManualHeight to 2. And then, to keep my virtual screen height equal to 640, I've set OrthographicSize for UI camera to 320 (half required here). In this case almost all are fine: all controls on its places, anchors works too.

So, here is the question. Is it required to use OrthographicSize equal to 1 for UI camera?

P.S. If it is allowed, then there is a bug in UIStretch, which works incorrectly (at least with Both style) if OrthographicSize for camera is not 1.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Is it required to use OrthographicSize equal to 1 for UI camera?
« Reply #1 on: May 17, 2013, 05:43:58 AM »
Required? No. Is NGUI designed to work in 2 / Screen.height by default? Yes.

Not sure why having UIRoot scaled is an issue for you. You should be instantiating things underneath it, and working in pixels anyway. NGUITools.AddChild your panels with content -- this already resets the scale to 1.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Is it required to use OrthographicSize equal to 1 for UI camera?
« Reply #2 on: May 17, 2013, 06:58:02 AM »
You're doing it wrong. You are taking a fundamental part of NGUI and struggle against it.

UIRoot scales its coordinate system to make the virtual pixel in all its children, so localposition can be pixel sizes in a nice way. The scale of UI Elements should be pixel size, but when instantiating prefabs, the root of that prefab should be scaled 1,1,1, so that the children of those conform to the virtual pixel system.

It seems to me that your solving the problem backwards, by changing the virtual pixels to conform instead.

user123

  • Guest
Re: Is it required to use OrthographicSize equal to 1 for UI camera?
« Reply #3 on: May 17, 2013, 12:02:11 PM »
Well, I did not change any sizes or scales in existing UI (when FixedSize was 640) to make it look exactly the same with FixedSize set to 2 and Camera.OrthographicSize set to 320. And I still can set all sizes in pixels.

In my case UI scaling is done by camera's projection matrix, not actual transform. This seems to me... say... more natural in terms of Unity. I understand that NGUI builds own coordinate system, but is it really required, if you can get the same result (and forget about scaling) with proper camera settings easily?

I also understand that it is done as it is done. So, just make a note. :)

Thanks.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Is it required to use OrthographicSize equal to 1 for UI camera?
« Reply #4 on: May 18, 2013, 03:23:10 AM »
I suggest you just learn how things work and go with them instead of trying to re-engineer some key things like this one. It'll just make your life easier. NGUI was designed in a certain way, so you're just asking for extra hassle here.