Author Topic: Stuck with NGUI widget position VS. Unity World positions  (Read 7563 times)

SatMangieri

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 9
    • View Profile
Stuck with NGUI widget position VS. Unity World positions
« on: October 15, 2014, 02:39:49 PM »
Hi Guys,
My problem is the following. I am creating a matrix of sprites (Unity Sprites) and positioning this matrix in the bottom of my scene Just like this picture
http://postimg.org/image/mqxf7vkcp/b7ae49c6/

So the thing is i need to get the position of the Unity gameobject, which is the matrix container. I.e. It is at (-3.5,0.5,0)(This is his world position) and "convert" that value to assign it to the widget NGUI element. So i can instantiate the NGUI elements just above the matrix. The matrix can change his height. That is why i need to do it in this way.

I've tried already changing the unity gameobject position to a screen position, but nothing works. I'm sure I'm getting wrong the concept here.
I need an explanation about how to convert that world's position of the unity gameobject and pass it to the NGUI widget.
I saw one post where The Wise Moonk talks about "...If your UIRoot is pixel-perfect, then your sprites will work with pixel coordinates..." (here is the post: http://www.tasharen.com/forum/index.php?topic=7042.0)
But honestly i cannot get it so someone give me some light and it will be highly appreciated.
I will still looking for the answer though.
Thanks,

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Stuck with NGUI widget position VS. Unity World positions
« Reply #1 on: October 16, 2014, 06:38:32 AM »
NGUI was written with ortho size 1 for the UI camera. If you use something else, the results may not always work as you'd expect.

I don't recommend you work with world position in any case. Why not stick to local positions? If you know something is 800 pixels, then in local space it will be 800 units in the UI.

Why do you need an ortho camera size 5 anyway?

SatMangieri

  • Newbie
  • *
  • Thank You
  • -Given: 3
  • -Receive: 1
  • Posts: 9
    • View Profile
Re: Stuck with NGUI widget position VS. Unity World positions
« Reply #2 on: October 16, 2014, 07:03:00 AM »
Hi  @ArenMook
Thanks for answer. I got the solution to NGUI and Unity positions another member gave me the answer.
In fact I'm still new to Unity, maybe I'm doing many things wrong. I'm using the main camera with size of 5; really don't know why :S. In fact i had to code (resizing the camera) to make fit the matrix of sprites so always will be at the bottom and filling the width of screen.

And how do i stick into local positions with the unity game objects?
I should leave the main camera to size of 1 as the NGUI.
Then you told me that the relationship between pixels will be equal to UI units. So if i have the matrix with a height of 400 pixels.
and the Screen resolution has 800 pixels height. It means i can calculate the Y value;
But still don't know how. Could you explain more please?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Stuck with NGUI widget position VS. Unity World positions
« Reply #3 on: October 16, 2014, 07:08:45 AM »
transform.localPosition = xyz;

Main camera can be any size, it doesn't matter as it's not your UI camera. Your UI camera should remain size of 1 though.

When you create new UI, by default it will use the flexible mode (pixel-perfect), meaning its units will match your pixels -- and 100 pixels means seeing "100" in the transform inspector.