Here's a bug report of NGUI's ScrollView Component.
If a scroll view is anchored, and if the anchoring makes the baseClipRegion of it changed, the contents in the scroll view will be wrongly positioned.
And here's my solution:
Since the bug happens in the case of baseClipRegion changing, it seems ok to fix it by calling the method "ResetPosition" which is to fix the position of the contents when baseClipRegion is changed.
So the following is the key code:
UIPanel.cs
public Vector4 baseClipRegion
{
get
{
return mClipRange;
}
set
{
if (Mathf.Abs(mClipRange.x - value.x) > 0.001f ||
Mathf.Abs(mClipRange.y - value.y) > 0.001f ||
Mathf.Abs(mClipRange.z - value.z) > 0.001f ||
Mathf.Abs(mClipRange.w - value.w) > 0.001f)
{
mResized = true;
mCullTime = (mCullTime == 0f) ? 0.001f : RealTime.time + 0.15f;
------------------------------------------ before ------------------------------------------
mClipRange = value;
------------------------------------------ after -------------------------------------------
if (mClipRange != value)
{
mClipRange = value;
var scrollViewComponent = this.GetComponent<UIScrollView>();
if (scrollViewComponent != null)
{
scrollViewComponent.ResetPosition();
}
}
---------------------------------------------------------------------------------------------
mMatrixFrame = -1;
#if UNITY_EDITOR
if (!Application.isPlaying) UpdateDrawCalls();
#endif
}
}
}
Hopes this bug can be fixed at next version of NGUI, and so I don't have to member to change the code myself.
Looking forward to your replying.