Hello, I'm working on a file manager where you have files and folders inside a background.
Every folder has contents which are stored in a List<FolderContents> - A content could be a File or Folder. Each content has an index, that way I can position the content like this:
public void PositionContent(FolderContent content, int atIndex)
{
// since I'm placing the contents in a 1 dimensional list, I have to get the 2 dimensional index of the content to position it
// nContentsToFit is how many contents fits inside the current folder in terms of rows / cols (ex 4x4) (related to the dimensions of the folder's background)
// an example of the offset: the 6th content has an index of 5 (in 1d), now in a 4x4 folder its 2d index is (1,1) (2nd row, 2nd col)
// Index2D is just a struct holding two integers, much like a V2 but for ints instead of floats
var offset
= new Index2D
(atIndex
/ nContentsToFit
.col, atIndex
% nContentsToFit
.j);
// ContentWidth is the width of the folder/file's background -- which is the problem
float x = offset.col * ContentWidth + offset.col * spaceBetweenContents;
float y = offset.row * ContentHeight + offset.row * spaceBetweenContents;
var trans = content.cachedTransform;
trans.position = topLeft.position; // an empty gameObject to start positioning the contents from
var screenpos = guiCamera.WorldToScreenPoint(trans.position);
screenpos.x += x;
screenpos.y -= y;
trans.position = guiCamera.ScreenToWorldPoint(screenpos);
}
Now, at first, when everything was working OK, "ContentWidth" and "ContentHeight" were the same as the scale of the background, but then for some reason I had some trouble and moved my panel under another UI, which is when I noticed a very TERRIBLE positioning of files/folders. I knew the reason is the new UI, I tried finding the dif between them, they were the same
( - I think now the values of the scale are actual screen pixels.
(Please see attachment to see the dif between after and before)
FYI, I have more than one camera and 2 UI.
I'm not developing for any mobile, only PC.
PLEASE for the love of anything you love, just let me understand how NGUI coords work!
0- what happened with me, why did everything got so messed up?
1- what is NGUI virtual pixels?
2- what is the relation between NGUI virtual pixels and screen coord?
3- how does scaling work in NGUI?
4- what does pixel perfect mean?? (please don't tell me "Pixel-perfect means making the pixels perfect" or something similar, cuz I've heard that a lot and it doesn't help clear anything)
5- what is UIRoot.pixelSizeAdjustment?? ("A helper function that figures out the pixel size adjustment for the specified object" - similar explanation to Pixel-perfect, pixel-perfect means the pixels are perfect, aughhhh)
6- when is it that the scaling values are the same as in onscreen pixels?
7- what is the relation between the scale values of an object and its width/height?
Sorry I know it's a lot but please I want to understand how all those things are tied together.... PLZZZZZ ME NEEDZ EXZBLAIN! <Shrek cat look>
I Have looked and searched a lot in the forums, the more I do the more I get confused
( - a lot of what I got are half-missing the info I want.
Let this be a full reference to this subject for those who have the same 'suffering', because there are a lot...
Thank you SO MUCH in advance! "ANYTHING" - would be VERY MUCH appreciated!
And PLZZZZZZZZZZZ Aren, make us a better documentation *___*
EDIT: Problem solved using localPosition in the right place. I've also found out about UITable which does the organizing for me automatically, like UIGrid but for 2D context instead