I'm trying to make my UILabel's pixel perfect however I'm running into problems with positioning the gameobject to a rounded number under a UITable.
My problem is 1) the UITable itself keeps repositioning after and 2) the table elements keep repositioning to a non-pixel perfect position. In my code below I go through all the children gameobjects to make sure they are set to the proper positioning.
uiTable.repositionNow = true;
//get all children and set to pixel perfect position.
Transform[] allChildrenInContainer = GetComponentsInChildren<Transform>();
foreach (Transform child in allChildrenInContainer) {
child
.localPosition = new Vector3
(Mathf
.RoundToInt(child
.localPosition.x),
Mathf.RoundToInt(child.localPosition.y)+0.5f,
Mathf.RoundToInt(child.localPosition.z));
//NGUITools.MakePixelPerfect(child); same problem as above when trying this.
}
Any suggestions?
*EDIT* Solved it myself, hopefully this helps someone else. The solution is to call the "onRepositoin" invoker and it will invoke the method you create when the table is reposition. In my case, I created RepositionPixelPerfect() to be invoked once repositionNow does occur. This method is then invoked after and in my case I wrote this method to set each element to pixel perfect positioning.
Solution:void YourMethodForAddingTableElements()
{
uiTable.onReposition += RepositionPixelPerfect; //onReposition wil invoke RepositionPixelPerfect method when UITable is repositioned.
uiTable.repositionNow = true;
}
void RepositionPixelPerfect()
{
Transform[] allChildrenInContainer = GetComponentsInChildren<Transform>();
foreach (Transform child in allChildrenInContainer) {
NGUITools.MakePixelPerfect(child);
}
}