예제 #1
0
    /// <summary>
    /// Attempt to switch this container's card to the other container's index
    /// </summary>
    public void SwitchCards(int this_index, GameObject card, GridContainer container, int other_index)
    {
        //Debug.Log("from container " + this.name + " switch " + card.name + " in index " + this_index + " to container " + container.name + " at index " + other_index);
        if (!ValidIndex(this_index))
        {
            return;
        }
        else if (!container.ValidIndex(other_index))
        {
            return;
        }

        GameObject other_card = container.GetCardFromIndex(other_index);

        if (other_card != null) //card exists in other container
        {
            other_card.transform.SetParent(null);
            AddCard(other_card, this_index);
            container.AddCard(card, other_index);
        }
        else
        {
            container.AddCard(card, other_index);
        }
    }
예제 #2
0
    public void EndDrag(GameObject card)
    {
        //Current lowest distance between grid and currently held card
        float lowest_distance = MinimumDragDistance;

        GridContainer container_final = null;

        int new_index = -1;

        //Check all active containers to detect where item should be placed
        foreach (GridContainer container in CurrentlyActiveContainers)
        {
            for (int i = 0; i < container.CardMax; ++i)
            {
                //print("iterating " + i);
                GameObject grid_space  = container.GridDisplay.transform.GetChild(i).gameObject;
                float      curr_lowest = Vector2.Distance(grid_space.transform.position, card.transform.position);
                if (curr_lowest < lowest_distance)
                {
                    lowest_distance = curr_lowest;
                    container_final = container;
                    new_index       = i;
                }
            }
        }

        if (new_index != -1) //Switch
        {
            LastContainer.SwitchCards(LastIndex, card, container_final, new_index);
        }
        else // Do not switch
        {
            LastContainer.AddCard(card, LastIndex);
        }
    }