public void CancelPurchase() { if (AnturaSpaceScene.I.TutorialMode) { return; } if (currentDraggedSlot) { currentDraggedSlot.Despawn(); } DeleteDecoration(currentDraggedDecoration); if (OnPurchaseCancelled != null) { OnPurchaseCancelled(); } SetContextPurchase(); }
private IEnumerator DragPlacementCO() { while (true) { // Get the closest assignable slot var allAssignableSlots = allShopDecorationSlots.Where(x => x.IsFreeAndAssignableTo(currentDraggedDecoration) || x.HasCurrentlyAssigned(currentDraggedDecoration)); ShopDecorationSlot closestSlot = null; float minDistance = Int32.MaxValue; foreach (var slot in allAssignableSlots) { var mousePos = AnturaSpaceUI.I.ScreenToUIPoint(Input.mousePosition); var slotPos = AnturaSpaceUI.I.WorldToUIPoint(slot.transform.position); float distance = (mousePos - slotPos).sqrMagnitude; if (distance < minDistance && distance < thresholdForPlacement * thresholdForPlacement) { minDistance = distance; closestSlot = slot; } } // Check whether we are close to the delete button, instead bool shouldBeDeleted = false; float distanceForDelete = (Camera.main.WorldToScreenPoint(deletePropButtonTransform.position) - Input.mousePosition).sqrMagnitude; if (distanceForDelete < thresholdForDelete * thresholdForDelete) { // First time: feedback if (currentDraggedSlot != null) { deletePropButtonTransform.GetComponent <Image>().color = Color.red; if (startDragSlot) { startDragSlot.Despawn(); } closestSlot = null; SwitchSlotTo(null); } shouldBeDeleted = true; } else { deletePropButtonTransform.GetComponent <Image>().color = new Color(188 / 255f, 81f / 255f, 177 / 255f); } // Place the object there (change slot) if (closestSlot != currentDraggedSlot && closestSlot != null) { SwitchSlotTo(closestSlot); } // Update highlights foreach (var slot in allShopDecorationSlots.Where(x => x.IsAssignableTo(currentDraggedDecoration))) { if (slot.HasCurrentlyAssigned(currentDraggedDecoration)) { slot.Highlight(true, ShopDecorationSlot.SlotHighlight.Correct); } else if (slot.Assigned) { slot.Highlight(true, ShopDecorationSlot.SlotHighlight.Wrong); } else { slot.Highlight(true, ShopDecorationSlot.SlotHighlight.Idle); } } // Check if we are stopping the dragging if (!Input.GetMouseButton(0)) { ReleaseDragPlacement(shouldBeDeleted); } yield return(null); } }