This is one of those weird things that I've always wanted to get rid of in NGUI.
I have a sliced sprite of 150x100 dimensions. Yet if I click on its right-most edge, I get an x value of around 125, and not 150! (See attachment)
var screen = NGUITools.FindCameraForLayer(fromSlot.gameObject.layer).WorldToScreenPoint(Slot.background.cachedTransform.position);
float x = (Input.mousePosition.x - screen.x);
float y = (screen.y - Input.mousePosition.y);
Debug.Log("x: " + x + "y: " + y);
I need this to figure our how many slots I'm clicking away from the top-left slot. After I get the difference, I divide by the slot's template size (50) to get the right number:
// continuation from previous code...
float colDif = x / Owner.SlotSize;
float rowDif = y / Owner.SlotSize;
Debug.Log("col: " + Mathf.FloorToInt(colDif) + " rowDif: " + Mathf.FloorToInt(rowDif) + " sSize: " + Owner.SlotSize);
AddingOffset
= new Index2D
((int)rowDif,
(int)colDif
);
This will only work well, if I get a correct x and y. But since they're a bit lesser than the original values (~125 and not 150 for the width, and ~80 and not 100 for the height), my calculations all will go wrong.
Can somebody tell me why this is happening, and how to go about doing it the right way?
Thanks a lot!