private IEnumerator SwapPickups() { //We only need to swap to/from the slots that actually have something equipped bool sourceFinished = !dragSlot.IsEquipped(); bool targetFinished = !currentDropTarget.IsEquipped(); //Lerp the pickup icons between the swapped slot locations while (!sourceFinished || !targetFinished) { if (!sourceFinished) { dragSlot.GetTransform().position = Vector3.MoveTowards(dragSlot.GetTransform().position, currentDropTarget.GetHomeCoords(), Time.deltaTime * swapSpeed); sourceFinished = dragSlot.GetTransform().position.Equals(currentDropTarget.GetHomeCoords()); } if (!targetFinished) { currentDropTarget.GetTransform().position = Vector3.MoveTowards(currentDropTarget.GetTransform().position, dragSlot.GetHomeCoords(), Time.deltaTime * swapSpeed); targetFinished = currentDropTarget.GetTransform().position.Equals(dragSlot.GetHomeCoords()); } yield return(0); } //Remove the highlights that were established as part of the drag dragSlot.RemovePickupHighlight(); currentDropTarget.RemoveSlotHighlight(); //Complete the actual swap of the pickups dragSlot.SwapPickup(currentDropTarget); //The slots that have pickups equipped may have changed so recalculate which ones need to be visible ResetVisibilityOnAllSlots(); //End this drag dragSlot = null; currentDropTarget = null; }
public void Drag(Vector2 fingerPosition) { if (!IsDragging()) { Debug.Log("Received drag request with no corresponding start drag request so it will be ignored"); } else { //Move the icon to follow the players finger movements Vector2 fingerDelta = fingerPosition - lastFrameFingerPosition; dragTargetPosition = dragTargetPosition + new Vector3(fingerDelta.x, fingerDelta.y); dragSlot.GetTransform().position = Vector3.Lerp(dragSlot.GetTransform().position, dragTargetPosition, Time.deltaTime * dragSpeed); lastFrameFingerPosition = fingerPosition; UpdateCurrentDropTarget(); } }
public void StartDragging(PickupSlot dragSlot, int reflectXAxis, Vector2 fingerPosition) { if (IsDragging()) { Debug.Log("Received request to start a drag but we are already dragging something else so it will be ignored"); } else { this.dragSlot = dragSlot; //Note that reflect x axis is used here so that we can snap either to the left or right of the origin depending on what side of the screen the origin is this.dragCentre = dragSlot.GetTransform().position + new Vector3((dragSnapDistance + currentSlotBias) * reflectXAxis, dragSnapDistance + currentSlotBias); this.lastFrameFingerPosition = fingerPosition; //Snap the icon to the specified bias from the dragCentre Vector3 biasToOrigin = new Vector3(-currentSlotBias * reflectXAxis, -currentSlotBias); dragSlot.GetTransform().position = dragCentre + biasToOrigin; dragTargetPosition = dragSlot.GetTransform().position; UpdateCurrentDropTarget(); //Make all slots visible during a drag so we can see the highlighted slot where the player is dragging towards ShowAllSlots(); } }