I am developing a level selection menu that's essentially a long, scrollable list of items using UIDraggablePanel and UIGrid. I'm trying to find a way to initialize the scroll position so that the last played level is visible. However, calling SetDragAmount() on the UIDraggablePanel seems to do weird things: it moves the entire panel as well as the contents.
To test this, open
NGUI/Examples/Scenes/Example 7 - Scroll View (Panel).unity, then add the following script to the
Click Me button (and disable the UIButton Tween component):
TestDragPanel.csusing UnityEngine;
using System.Collections;
public class TestDragPanel : MonoBehaviour {
void Start() {
UIEventListener.Get(this.gameObject).onClick += onButtonClick;
}
void onButtonClick(GameObject button) {
GameObject gob = GameObject.Find("UIPanel (Clipped View)");
UIDraggablePanel draggablePanel = gob.GetComponent<UIDraggablePanel>();
draggablePanel.SetDragAmount(0.25f, 0f, true);
}
}
I would assume that the code would move the scroll position to 25%. And that seems to happen, since in the second picture the scrollbar has moved to the right - but so has the panel itself. See the attachments for screenshots before and after calling the method.
I'm using NGUI 2.3.4 and Unity 4.0.1f2.
Edit: Marked as solved, and clarified subject to match with the solution.