// one of the fingers holding a draggable object is moving. // Update the dragged object position accordingly. void draggable_OnDragMove(TBDrag sender) { // figure out our previous screen space finger position Vector2 prevFingerPos = sender.FingerPos - sender.MoveDelta; Vector3 fingerPos3d, prevFingerPos3d; // convert these to world-space coordinates, and compute the amount of motion we need to apply to the object if (ProjectScreenPointOnDragPlane(sender.transform.position, prevFingerPos, out prevFingerPos3d) && ProjectScreenPointOnDragPlane(sender.transform.position, sender.FingerPos, out fingerPos3d)) { Vector3 move = fingerPos3d - prevFingerPos3d; sender.transform.position += move; } }
public float dragPlaneOffset = 0.0f; // distance between dragged object and drag constraint plane void FingerGestures_OnFingerDragBegin(int fingerIndex, Vector2 fingerPos, Vector2 startPos) { // check if the object is draggable TBDrag draggable = PickComponent <TBDrag>(startPos); if (draggable && !draggable.Dragging) { // initiate the drag operation draggable.BeginDrag(fingerIndex, fingerPos); // register to the drag move & end events so we can update this object's position and unsubscribe to these events when done. draggable.OnDragMove += draggable_OnDragMove; draggable.OnDragEnd += draggable_OnDragEnd; } }
void draggable_OnDragEnd(TBDrag source) { // unsubscribe from this object's drag events source.OnDragMove -= draggable_OnDragMove; source.OnDragEnd -= draggable_OnDragEnd; }