Пример #1
0
    void Move(GameObject newSelected)
    {
        Selectable origin      = selectedCard.GetComponent <Selectable>();
        Selectable destination = newSelected.GetComponent <Selectable>();

        float yOffset = 0.3f;

        //if the card is on the foundation or the card is a king, do not offset the card from the position object
        if (destination.onFoundation || (!destination.onFoundation && origin.rank == 13))
        {
            yOffset = 0;
        }

        //move the origin card to the destination cards location and offset by .3f; add the origin card to the parent object of the destination card
        selectedCard.transform.position = new Vector3(newSelected.transform.position.x, newSelected.transform.position.y - yOffset, newSelected.transform.position.z - 0.02f);
        //if the destination is a card, move to the cards parent
        if (destination.CompareTag("Card"))
        {
            selectedCard.transform.parent = newSelected.transform.parent;
        }
        //if the destination is a position, make it a child of that position gameobject
        else
        {
            selectedCard.transform.parent = newSelected.transform;
        }
        //if origin is in the waste pile, remove from the waste pile
        if (origin.inWaste)
        {
            emperor.waste.Remove(selectedCard.name);
        }
        //if the origin is on the foundation, reset the object to have a rank - 1 (for bookkeeping)
        else if (origin.onFoundation)
        {
            emperor.topPos[origin.posRow].GetComponent <Selectable>().rank = origin.rank - 1;
        }
        else
        {
            // emperor.tableaus[destination.posRow].Add(selectedCard.name);
            emperor.tableaus[origin.posRow].Remove(selectedCard.name);
        }

        origin.inWaste = false;
        origin.posRow  = destination.posRow;

        if (destination.onFoundation)
        {
            emperor.topPos[origin.posRow].GetComponent <Selectable>().suit = origin.suit;
            emperor.topPos[origin.posRow].GetComponent <Selectable>().rank = origin.rank;
            origin.onFoundation = true;
        }
        else
        {
            origin.onFoundation = false;
        }

        selectedCard = this.gameObject;
    }