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;