0

I have a curious problem with rendering the actual content in NGUI widgets when the underlying panel is moved. For some reason, the content itself doesn't update to correct position even if the bounds are. First image is how it should be and second is how it is sometimes after moving the underlying panel from right to left. You can see from the widget rectangles that they are in correct place but the contents (text or sprite) is misplaced.

I have tried updating, refreshing anchors etc. but none seem to be working. Any ideas? It seems to be a rendering problem. We are using Unity 4.6 and NGUI 3.7.4 currently.

OK Not OK

Mayoneez
  • 441
  • 5
  • 19
  • is a draggable panel? – joreldraw May 08 '15 at 06:49
  • Yes it is. It is a UIScrollView where those elements are. – Mayoneez May 08 '15 at 07:09
  • And it is a vertically scrolling scroll view so the content should never move horizontally. – Mayoneez May 08 '15 at 07:37
  • The fast way is that you change this label pivot to Left, and apply anchor to the panel container – joreldraw May 08 '15 at 07:53
  • In other words, make this structure: 1-UIpanel (draggable) 1.1-Uipanel (not draggable and anchor reference) 1.1.1Your other items(labels, sprites,etc) – joreldraw May 08 '15 at 08:01
  • Ended up fixing this with a hack :-( Once the screen transition has completed, I wait for 0.01 seconds and modify the UIScrollView component's y position slightly. This triggers some redraw and the components are drawn at correct positions: `Vector3 pos = videoScrollView.gameObject.transform.localPosition;` `pos.y += 0.1f;` `videoScrollView.gameObject.transform.localPosition = pos;` – Mayoneez May 08 '15 at 10:57
  • Did you try using .SetDirty() on the NGUI gameObjects that move? – Dover8 Jul 02 '15 at 13:51

2 Answers2

0

I suppose NGUI don't work well with (parent) gameobject being inactive. Especially if you try to UIScrollView.ResetPosition, scaling or re-positioning.

so I have an extension that look like this

public static void ResetPositionHack(this UIScrollView scrollView, float animLength = 1f ) {
    scrollView.ResetPosition();
    scrollView.currentMomentum = Vector3.zero;
    KeepMakingDirty.Begin( scrollView, animLength );
}

The method KeepMakingDirty.Begin will attach a MonoBehavior to the object (also make sure no double attachment).
SetDirty() will be called in it's Update() for a specified period of time.
Then the script self-destructs.

Hiro
  • 81
  • 2
  • 7
0

This is a NGUI's bug. It is related to UIPanel.UpdateTransformMatrix(), and has been fixed at NGUI3.9.3 or NGUI 3.9.4.

The code blow works fine in my project:

void UpdateTransformMatrix ()
{
    int fc = Time.frameCount;
    if (cachedTransform.hasChanged)
    {
        mTrans.hasChanged = false;
        mMatrixFrame = -1;
    }

    if (mMatrixFrame != fc)
    {
        mMatrixFrame = fc;
        worldToLocal = mTrans.worldToLocalMatrix;

        Vector2 size = GetViewSize() * 0.5f;

        float x = mClipOffset.x + mClipRange.x;
        float y = mClipOffset.y + mClipRange.y;

        mMin.x = x - size.x;
        mMin.y = y - size.y;
        mMax.x = x + size.x;
        mMax.y = y + size.y;
    }
}
Triumph
  • 3
  • 1