Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.

Topics - raydenuni

Pages: [1]
I would like to set the size of a UISprite to be the size of a grid with its children. It looks like UIStretch can do that, but it's deprecated in place of the anchoring system. One can't anchor a UIWidget to a grid because a grid is not itself a widget. How should I go about populating a grid and then resizing a texture to be the size of the elements in the grid?

NGUI 3 Support / Adding and Removing elements from Scrollview
« on: June 12, 2014, 06:54:57 PM »
NGUI 3.5.9

I have a scrollview with a grid and a bunch of elements. I'm adding and removing them at runtime and running into a weird issue where removing elements causes the grid to be scrolled up outside of the visible clip zone. I can either drag the contents back into view, or I can execute the "Reset Clipping Position" manually in the editor. Here's the code I'm using to remove elements:

  1. void Foo() {
  2.         foreach (Transform child in _grid.transform) {
  3.                 if (childMatchesCondition()) {
  4.                         NGUITools.Destroy(child.gameObject);
  5.                         break;
  6.                 }
  7.         }
  9.         _gridScrollView.ResetPosition();
  10.         _grid.GetComponent<UIGrid>().Reposition();
  11. }

It seems like it's the grid Reposition() that messes it up. If I just do ResetPosition, the list always lines up at the top of the scrollview (but then I get gaps), but if I call Reposition, it will sometimes shift up so one element is above the scrollview clip.

What I expect:
  1.  ___
  2. | @ |
  3. | @ |
  4. | @ |
  5. -----

What I get:
  1.  _@_
  2. | @ |
  3. | @ |
  4. |   |
  5. -----

With some larger scroll views that I have, if I filter it down to only a few elements they will often scroll all the way off the top of the screen and I can't see any of them.

Thoughts anyone? This seems like a pretty standard use case so there must be an easy way to do this properly.

I created an empty scene, made a containing Panel and set it's clip to alpha and then added a button outside the Panel's hierarchy and made it a Draggable Object. This works. Then I made the button's drag effect none (from MomentumAndSpring) and that sort of works. The button has bounds, the bounds seem to depend on the button's current location and not the panel (not sure if that's a bug or I'm doing something wrong). Then I moved the button underneath the panel in the hierarchy and I could no longer drag it. Changing drag effect to MomentumAndSpring makes it work again, but the combination of None and being under the clipping panel in the hierarchy breaks the drag.

I have a sprite I would like to fit in a section of the screen. Let's say the middle 3/5 at the bottom. I built the following to do so:

- Container - UIWidget with a Unified anchor of (custom 0.2, custom 0.8, bottom 0, top 0)
-- Sprite - UIStretch with FitInternalKeepingRatio and then appropriate InitialSize values for my sprite

In the editor, this will properly scale up the image, maintaining aspect ratio, to fit in the bottom of the screen. But in-game, it is pushed off screen I believe.

Potential bug somewhere in how UIStretch and Anchors interact?


Alternatively, how to implement FitInternalKeepingRatio using the new 3.0.7 anchors? This post seems to be asking the same question:

If there's a better way to do this, I'm all ears.

Pages: [1]