コード例 #1
0
    public CardVisual CardFactory(CardData data, string prefabname, Deck targetDeck = null, int index = 0)
    {
        GameObject activeCard = PhotonNetwork.Instantiate(prefabname, new Vector3(40f, 20f, 20f), Quaternion.identity, 0) as GameObject;
        CardVisual cardVisual = activeCard.GetComponent <CardVisual>();

        cardVisual.RegisterCard(cardVisual.photonView.viewID);
        cardVisual.RPCRegisterCard(PhotonTargets.OthersBuffered, cardVisual.photonView.viewID);

        cardVisual.cardData = data;
        RPCSetCardData(PhotonTargets.OthersBuffered, data.cardID, cardVisual.photonView.viewID);

        activeCards.Add(cardVisual);
        activeCard.transform.SetParent(GameObject.FindGameObjectWithTag("AllCards").transform, false); //TODO: make this happen in the card itself.

        AssignCardLocationAndOwner(activeCard, owner, this);
        cardVisual.RPCSetOwner(PhotonTargets.OthersBuffered);
        cardVisual.RPCSetParentDeck(PhotonTargets.OthersBuffered, decktype.ToString());

        cardVisual.RPCSetUpCardData(PhotonTargets.All);
        activeCard.name = cardVisual.cardData.cardName + " " + index;

        if (targetDeck != null)
        {
            switch (targetDeck.decktype)
            {
            case DeckType.Battlefield:

                if (owner.battleFieldManager.IsCollectionFull())
                {
                    if (owner.handManager.IsCollectionFull())
                    {
                        RPCTransferCard(PhotonTargets.AllBufferedViaServer, cardVisual, owner.activeCrypt.GetComponent <Deck>());
                    }
                    else
                    {
                        RPCTransferCard(PhotonTargets.AllBufferedViaServer, cardVisual, owner.myHand);
                    }
                }
                else
                {
                    RPCTransferCard(PhotonTargets.AllBufferedViaServer, cardVisual, targetDeck);
                }

                break;

            case DeckType.Hand:
                if (owner.handManager.IsCollectionFull())
                {
                    RPCTransferCard(PhotonTargets.AllBufferedViaServer, cardVisual, owner.activeCrypt.GetComponent <Deck>());
                }
                else
                {
                    RPCTransferCard(PhotonTargets.AllBufferedViaServer, cardVisual, targetDeck);
                }

                break;

            case DeckType.SoulCrypt:

                RPCTransferCard(PhotonTargets.AllBufferedViaServer, cardVisual, targetDeck);


                break;
            }
        }

        if (owner.player2)
        {
            activeCard.transform.localRotation = owner.p2HandRot.localRotation;
        }
        else
        {
            cardVisual.RPCRotateCard(PhotonTargets.OthersBuffered);
        }


        //Debug.Log(cardVisual.photonView.viewID + " has been created");
        //cardVisual.InitializeSpecialAbilities(cardVisual.photonView.viewID);

        return(cardVisual);
    }