- Home /
NGUI UIGrid Customization.
Hey, So:
I'm attempting to create a coverflow-style UI Grid. Things are going well, but I'm having trouble adjusting the x positions of the things in the grid so there is more space in the center for the item that's being focused on. Right now, the items to the left and the right crowd around the middle item, as so:
I'm doing this by using the UIGrid class as a base class, and overriding the Reposition function. Basically, after it's done repositioning, I nudge the rotations and z positions of the objects to get the desired effect. However, whenever I attempt to modify the x position of the item, I get nastiness -- the photos either get stuck in the middle, or they move way off screen. Here's the function, called AdjustPosition, that I'm using to create this effect. Is there something in UIGrid that would prevent me from moving items around after Reposition() is called?
public void AdjustPosition(Transform childBeingAdjusted, GameObject middle, int middleInt) {
//first determine the depth of the items, so the middle one is always on top.
int childNdx = int.Parse (childBeingAdjusted.name.Split ('_') [0]);
int intDiff = childNdx - middleInt;
float offset = _distanceToStartStacking;
if(childBeingAdjusted == middle.transform) {
childBeingAdjusted.GetComponent<UIWidget>().depth = 0;
} else {
childBeingAdjusted.GetComponent<UIWidget>().depth = Mathf.Abs (intDiff) * -1;
}
//now, get information about how far off the center of the screen the objects are.
ScreenEdgeDetector.instance.UpdateScreenEdgesPersp(Mathf.Abs(middle.transform.position.z - _camera.transform.position.z));
float screenEdge = ScreenEdgeDetector.instance._topLeft.x;
float lengthOfHalfScreen = Mathf.Abs(_camera.transform.position.x - screenEdge);
float percentOffCenter = (childBeingAdjusted.transform.position.x - _camera.transform.position.x)/lengthOfHalfScreen;
//now, adjust the x and z positions.
Vector3 pos = childBeingAdjusted.position;
pos.z = _zOffsetCurve.Evaluate(Mathf.Abs(percentOffCenter)) * _moveBackMult;
//when I comment out this line, the z positioning works fine. but when I put it in, everything breaks.
pos.x = _xOffsetCurve.Evaluate(percentOffCenter) * _moveSidewaysMult;
childBeingAdjusted.transform.position = pos;
}
Your answer
Follow this Question
Related Questions
Use Unity UI For 2D Games Or Custom Objects Instead? 2 Answers
Specific UI interaction process 0 Answers
How to see NGUI in SceneView 1 Answer
Unity Button Without an Image? 2 Answers
Is NGUI suitable for Mobile Games ? 2 Answers