Ejemplo n.º 1
0
        private void SwitchSlotTo(ShopDecorationSlot newSlot)
        {
            if (currentDraggedSlot != null)
            {
                currentDraggedSlot.Free();
            }

            if (startDragSlot == null)
            {
                startDragSlot = newSlot;
                //Debug.LogWarning("SET START: " + startDragSlot);
            }

            //Debug.Log("Switching to " + newSlot);
            //Debug.Log("Deco is " + currentDraggedDecoration);

            currentDraggedSlot = newSlot;
            if (currentDraggedSlot == null)
            {
                currentDraggedDecoration.transform.position = Vector3.right * 10000;
            }
            else
            {
                currentDraggedSlot.Assign(currentDraggedDecoration);
            }
        }
Ejemplo n.º 2
0
 private void EndPlacementContext()
 {
     ResetSlotHighlights();
     currentDraggedDecoration = null;
     currentDraggedSlot       = null;
     startDragSlot            = null;
 }
Ejemplo n.º 3
0
        public void StartDragPlacement(ShopDecorationObject decoToDrag, bool isNew)
        {
            if (isNew)
            {
                SetContextNewPlacement();
            }
            else
            {
                SetContextMovingPlacement();
            }

            currentDraggedSlot       = null;
            currentDraggedDecoration = decoToDrag;
            currentDraggedDecoration.FocusHighlight(true);
            dragCoroutine = StartCoroutine(DragPlacementCO());

            if (OnDragStart != null)
            {
                OnDragStart(decoToDrag);
            }
        }
Ejemplo n.º 4
0
        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);
            }
        }
Ejemplo n.º 5
0
 public bool MatchesSlot(ShopDecorationSlot slot)
 {
     return(slotType == slot.slotType && slotIndex == slot.slotIndex);
 }