Пример #1
0
    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;
    }
Пример #2
0
    public void SwapPickup(PickupSlot pickupSlot)
    {
        Pickup temp = this.pickup;

        this.EquipPickup(pickupSlot.GetPickup());
        pickupSlot.EquipPickup(temp);
    }
Пример #3
0
    private void Start()
    {
        // Set up the references to other game objects
        ball = GetComponent <BallController> ();

        PickupSlot[] slots = HUD.controller.GetComponentsInChildren <PickupSlot> ();

        foreach (PickupSlot slot in slots)
        {
            if (slot.name == "LeftPickupSlot")
            {
                leftSlot = slot;
            }
            else if (slot.name == "RightPickupSlot")
            {
                rightSlot = slot;
            }
            else if (slot.name == "UpperLeftPickupSlot")
            {
                upperLeftSlot = slot;
            }
            else if (slot.name == "UpperRightPickupSlot")
            {
                upperRightSlot = slot;
            }
        }

        dragManager = HUD.controller.GetComponentInChildren <DragManager> ();
    }
Пример #4
0
    //Highlights the pickup slot where the pickup would go if the player released their finger this frame
    private void UpdateCurrentDropTarget()
    {
        PickupSlot newDropTarget = DetermineDropTarget();

        if (newDropTarget != currentDropTarget)
        {
            if (currentDropTarget != null)
            {
                currentDropTarget.RemoveSlotHighlight();
            }
            newDropTarget.AddSlotHighlight();
            currentDropTarget = newDropTarget;
        }
    }
Пример #5
0
    private PickupSlot FindBestAvailableSlot()
    {
        PickupSlot slot = null;

        if (rightHander)
        {
            if (!rightSlot.IsEquipped())
            {
                slot = rightSlot;
            }
            else if (!leftSlot.IsEquipped())
            {
                slot = leftSlot;
            }
            else if (upperRightSlot != null && !upperRightSlot.IsEquipped())
            {
                slot = upperRightSlot;
            }
            else if (upperLeftSlot != null && !upperLeftSlot.IsEquipped())
            {
                slot = upperLeftSlot;
            }
        }
        else
        {
            if (!leftSlot.IsEquipped())
            {
                slot = leftSlot;
            }
            else if (!rightSlot.IsEquipped())
            {
                slot = rightSlot;
            }
            else if (upperLeftSlot != null && !upperLeftSlot.IsEquipped())
            {
                slot = upperLeftSlot;
            }
            else if (upperRightSlot != null && !upperRightSlot.IsEquipped())
            {
                slot = upperRightSlot;
            }
        }
        return(slot);
    }
Пример #6
0
    public void AddPickup(Pickup pickup)
    {
        //Play a particle effect
        pickupEffect.Play();
        HUD.controller.SendMessage("PickupAcquired", pickup);

        //Before adding pickup to a new slot, check if we already have it equipped somewhere...
        PickupSlot slot = FindSlotWithPickup(pickup);

        if (slot == null)
        {
            //... Otherwise find the best available slot for it to go
            slot = FindBestAvailableSlot();
        }
        if (slot != null)
        {
            slot.EquipPickup(pickup);
        }
        //PulseAllSlots ();
    }
Пример #7
0
    private PickupSlot FindSlotWithPickup(Pickup pickup)
    {
        PickupSlot slot = null;

        if (pickup.Equals(rightSlot.GetPickup()))
        {
            slot = rightSlot;
        }
        else if (pickup.Equals(leftSlot.GetPickup()))
        {
            slot = leftSlot;
        }
        else if (pickup.Equals(upperRightSlot != null && upperRightSlot.GetPickup()))
        {
            slot = upperRightSlot;
        }
        else if (pickup.Equals(upperLeftSlot != null && upperLeftSlot.GetPickup()))
        {
            slot = upperLeftSlot;
        }
        return(slot);
    }
Пример #8
0
    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();
        }
    }