Author Topic: UIGrid Coverflow Style.  (Read 4016 times)

catlard

  • Newbie
  • *
  • Thank You
  • -Given: 7
  • -Receive: 0
  • Posts: 24
    • View Profile
UIGrid Coverflow Style.
« on: May 12, 2014, 09:05:06 PM »
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:

http://imgur.com/3zjduax

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?

  1. public void AdjustPosition(Transform childBeingAdjusted, GameObject middle, int middleInt) {
  2.  
  3.                 //first determine the depth of the items, so the middle one is always on top.
  4.                 int childNdx = int.Parse (childBeingAdjusted.name.Split ('_') [0]);
  5.                 int intDiff = childNdx - middleInt;
  6.                 float offset = _distanceToStartStacking;
  7.                 if(childBeingAdjusted == middle.transform) {
  8.                         childBeingAdjusted.GetComponent<UIWidget>().depth = 0;
  9.                 } else {
  10.                         childBeingAdjusted.GetComponent<UIWidget>().depth = Mathf.Abs (intDiff) * -1;
  11.                 }
  12.  
  13.                 //now, get information about how far off the center of the screen the objects are.
  14.                 ScreenEdgeDetector.instance.UpdateScreenEdgesPersp(Mathf.Abs(middle.transform.position.z - _camera.transform.position.z));
  15.                 float screenEdge = ScreenEdgeDetector.instance._topLeft.x;
  16.                 float lengthOfHalfScreen = Mathf.Abs(_camera.transform.position.x - screenEdge);
  17.                 float percentOffCenter = (childBeingAdjusted.transform.position.x - _camera.transform.position.x)/lengthOfHalfScreen;
  18.  
  19.                 //now, adjust the x and z positions.
  20.                 Vector3 pos = childBeingAdjusted.position;
  21.                 pos.z = _zOffsetCurve.Evaluate(Mathf.Abs(percentOffCenter)) * _moveBackMult;
  22.         //when I comment out this line, the z positioning works fine. but when I put it in, everything breaks. 
  23. pos.x = _xOffsetCurve.Evaluate(percentOffCenter) * _moveSidewaysMult;
  24.                 childBeingAdjusted.transform.position = pos;
  25.         }

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: UIGrid Coverflow Style.
« Reply #1 on: May 13, 2014, 09:17:04 AM »
Don't use a grid for this. Create your own class. Grid uses fixed size positioning, while your positioning should be changing. Therefore -- custom component. You can trim 85% of the code in the process.