Currently while dragging a panel, the drag does not start until the drag threshold is reached. This is fine, however results in a "jump" when the drag starts.
If you observe standard iOS behavior, there is no jump. Anyway here is the code to fix it so dragging panels have no jumpiness. Note that the drag threshold is still preserved as it should be.
In UIDraggablePanel.cs add the following lines:
Vector2 _startOffset;
bool _startOffsetSet = false;
Then in the Drag function, after UICamera.currentTouch.clickNotification = UICamera.ClickNotification.BasedOnDelta; Add the following:
if(!_startOffsetSet)
{
_startOffset = UICamera.currentTouch.totalDelta;
_startOffsetSet = true;
}
Then also in the Drag function, update this line and move it below the code you just added (just added - _startOffset to it)
Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.currentTouch.pos - _startOffset);
Then in the OnPress function in the "else" block, add the following:
Overall looks like this:
public void Press (bool pressed)
{
if (enabled && NGUITools.GetActive(gameObject))
{
if (!pressed && mDragID == UICamera.currentTouchID) mDragID = -10;
mCalculatedBounds = false;
mShouldMove = shouldMove;
if (!mShouldMove) return;
mPressed = pressed;
if (pressed)
{
// Remove all momentum on press
mMomentum = Vector3.zero;
mScroll = 0f;
// Disable the spring movement
DisableSpring();
// Remember the hit position
mLastPos = UICamera.lastHit.point;
// Create the plane to drag along
mPlane
= new Plane
(mTrans
.rotation * Vector3
.back, mLastPos
); }
else
{
_startOffsetSet = false;
if (restrictWithinPanel && mPanel.clipping != UIDrawCall.Clipping.None && dragEffect == DragEffect.MomentumAndSpring)
{
RestrictWithinBounds(false);
}
if (onDragFinished != null) onDragFinished();
}
}
}
/// <summary>
/// Drag the object along the plane.
/// </summary>
Vector2 _startOffset;
bool _startOffsetSet = false;
public void Drag (Vector2 delta)
{
if (enabled && NGUITools.GetActive(gameObject) && mShouldMove)
{
if (mDragID == -10) mDragID = UICamera.currentTouchID;
UICamera.currentTouch.clickNotification = UICamera.ClickNotification.BasedOnDelta;
if(!_startOffsetSet)
{
_startOffset = UICamera.currentTouch.totalDelta;
_startOffsetSet = true;
}
Ray ray = UICamera.currentCamera.ScreenPointToRay(UICamera.currentTouch.pos - _startOffset);
float dist = 0f;