示例#1
0
    /*
     *  @name       MoveCard()
     *  @purpose   Moves the card from the hand to the correct placement and takes in the index from the loop so it knows whch card to use
     *  also it updates the score
     */
    public void MoveCard(int pZ, string pParent, List <Card> pListPlacement)
    {
        //assigns where the game object with go to a object
        CardParent = GameObject.Find(pParent).transform;
        //sets the name so the sprite can show the front of card
        Holder.CardNameHolder = Hand[pZ].CardName;
        //creates a new card object
        GenerateCardObject();
        //creates the new sprite with the correct image
        Holder.setSprite(Sr);
        //tells the current game object at play where to go to
        //CardObject.transform.SetParent(CardParent);
        //resizes the card so it fits nicely on the placements
        CardObject.transform.localScale = new Vector3(1.0f, 1.0f, 0);

        //updates the score based off the value of the card played
        ChangeScore(Hand[pZ].PointValue);
        //adds the card from the hand to the correct list
        pListPlacement.Add(Hand[pZ]);
        //removes the card just played from the hand
        Hand.Remove(Hand[pZ]);

        //resets the card parent that way if anything funky happens it will return to the hand
        //but since its a computer nothing like that would probably happen casue there is no dragability for the computer
        CardParent = GameObject.Find(HandGameObject).transform;

        //to keep from a null excpetion error
        if (Hand.Count > 0)
        {
            Destroy(CardParent.GetChild(0).gameObject);
        }
    }
    public void PressChar(int index, int indexFull)
    {
        if (cardManagerVariables.indexCardtoChar == -1)
        {
            return;
        }
        else if (cardProperties.cardinMenu.Count > 0)
        {
            if (cardProperties.cardinChar[index] != null)
            {
                CardParent tempCard = new CardParent();
                CardParent tempCardMenu = new CardParent();
                int        tempBuild1, tempBuild2;
                GameObject build;

                Destroy(cardProperties.cardinMenuGameobject[cardManagerVariables.indexCardInMenu].gameObject);
                build = Instantiate(cardProperties.cardPrefab, transform.position, transform.rotation) as GameObject;
                build.transform.parent = cardProperties.parentCardPrefab.transform;
                build.transform.GetChild(0).GetComponent <Text>().text = "" + cardProperties.cardinMenu[cardManagerVariables.indexCardAllCollectionMenu[index]].cardiden.BestStats;
                build.transform.GetChild(1).GetComponent <Text>().text = "" + cardProperties.cardinMenu[cardManagerVariables.indexCardAllCollectionMenu[index]].cardiden.StatsSort[2];

                tempBuild1 = cardManagerVariables.indexCardAllCollectionMenu[index];
                tempBuild2 = cardManagerVariables.indexCardAllCollectionMenu[index];
                build.GetComponent <Button>().onClick.AddListener(delegate { DetailMenu(tempBuild1, tempBuild2); });

                cardProperties.cardinMenuGameobject[cardManagerVariables.indexCardAllCollectionMenu[index]] = build;
                cardProperties.cardinChar[index] = cardProperties.cardinMenu[cardManagerVariables.indexCardInMenu];
                cardManagerVariables.charButton[index].GetComponentInChildren <Text>().text = "" + cardProperties.cardinChar[index].cardiden.cardparentName;

                ManagerCard.instance.CardIdentityChecked[tempBuild1] = false;
                ManagerCard.instance.CardIdentityChecked[cardManagerVariables.indexCardtoChar] = true;

                cardManagerVariables.indexCardAllCollection[index]     = cardManagerVariables.indexCardtoChar;
                cardManagerVariables.indexCardAllCollectionMenu[index] = cardManagerVariables.indexCardInMenu;
                cardManagerVariables.indexCardtoChar = -1;
                Debug.Log(cardProperties.cardinMenu[cardManagerVariables.indexCardAllCollectionMenu[index]].cardiden.BestStats);

                undoSystem[index].cardparent = cardProperties.cardinChar[index];
                return;
            }
            cardManagerVariables.charButton[index].GetComponentInChildren <Text>().text = "" + ManagerCard.instance.CardIdentityCollection[cardManagerVariables.indexCardtoChar].cardiden.cardparentName;
            cardProperties.cardinChar[index] = cardProperties.cardinMenu[cardManagerVariables.indexCardInMenu];

            Destroy(cardProperties.cardinMenuGameobject[cardManagerVariables.indexCardInMenu].gameObject);
            ManagerCard.instance.CardIdentityChecked[cardManagerVariables.indexCardtoChar] = true;

            cardManagerVariables.indexCardAllCollection[index]     = cardManagerVariables.indexCardtoChar;
            cardManagerVariables.indexCardAllCollectionMenu[index] = cardManagerVariables.indexCardInMenu;
            cardManagerVariables.indexCardtoChar = -1;

            indexFull        = cardManagerVariables.indexCardInMenu;
            countCardinChar += 1;

            undoSystem[index].cardparent = cardProperties.cardinChar[index];
            cardManagerVariables.charButton[index].transform.GetChild(1).GetComponent <Button>().interactable = true;
        }
    }
    public void RandomCard()
    {
        statsCollection.Clear();

        CardParent cards = ScriptableObject.CreateInstance("CardParent") as CardParent;
        CardParent Cards = new CardParent();

        for (int i = 0; i < 3; i++)
        {
            statsCollection.Add(new StatsCardClass());
            statsCollection[i].randomStats      = (Random.Range(1, 9));
            statsCollection[i].StateIdStatsCard = (StatsCard)i + 1;
        }

        for (int i = 0; i < 3; i++)
        {
            cards.cardiden.Stats[i] = statsCollection[i].randomStats;
        }

        statsCollection.Sort(delegate(StatsCardClass a, StatsCardClass b) {
            return(a.randomStats.CompareTo(b.randomStats));
        });

        for (int i = 0; i < 3; i++)
        {
            if (statsCollection[2].StateIdStatsCard == (StatsCard)i + 1)
            {
                cards.cardiden.cardparentName = ((TypeCard)i + 1).ToString();
                cards.NameCardType            = ((TypeCard)i + 1).ToString();
            }
            cards.cardiden.StatsSort[i] = statsCollection[i].randomStats;
            cards.cardiden.BestStats    = statsCollection[i].StateIdStatsCard.ToString();
        }

        statsCollection.Add(new StatsCardClass());
        statsCollection[3].randomStats      = (Random.Range(3, 5));
        statsCollection[3].StateIdStatsCard = (StatsCard)4;
        cards.cardiden.Stats[3]             = statsCollection[3].randomStats;

        cards.cardiden.StateID      = (CardIdentity.ClassCard)cards.cardiden.IndeParentCard;
        cards.cardiden.NameTypeCard = cards.cardiden.StateID.ToString();
        cards.cardiden.cardParent   = cards;

        CardIdentityCollection.Add(cards);
        CardIdentityChecked.Add(false);

        SaveCard(cards);

        selectCardMenu.InserData = true;

        MenuRandom.SetActive(false);
        MenuChooseCard.SetActive(true);
    }
    public void LoadCard()
    {
        string jsonString = File.ReadAllText(Application.dataPath + "/PlayerData.json");

        CardIdentity[] player = JsonHelper.FromJson <CardIdentity>(jsonString);
        for (int i = 0; i < player.Length; i++)
        {
            CardParent curr = new CardParent();
            curr.name = player[i].cardparentName;
            CardIdentityCollection.Add(curr);
            Debug.Log(player[i].NameTypeCard);
        }
    }
    /// <summary>
    /// Se obtiene el padre de todos los renglones de cartas
    /// </summary>
    void GetCardsParent()
    {
        cardsParentsList = new List <GameObject>(); //Crea una nueva lista de objets

        ///Crea un nuevo arreglo de objetos de toda la escena
        GameObject[] objectArr = Resources.FindObjectsOfTypeAll <GameObject>() as GameObject[];

        ///Para cada uno de los objetos
        foreach (GameObject gameObject in objectArr)
        {
            CardParent cParent = gameObject.GetComponent <CardParent>(); ///Obren este componente
                                                                         ///Si no es nulo
            if (cParent != null)
            {
                cardsParentsList.Add(gameObject); ///Añádelo a la lista
            }
        }
    }
    public void SaveCard(CardParent card)
    {
        PlayerPrefs.SetString("SaveCard" + CardIdentityCollection.Count, card.NameCardType);
        PlayerPrefs.SetInt("SaveCardInt" + CardIdentityCollection.Count, card.IndexCard);

        CardIdentity[] car = new CardIdentity[CardIdentityCollection.Count];

        for (int i = 0; i < CardIdentityCollection.Count; i++)
        {
            car[i] = new CardIdentity();
            car[i].NameTypeCard   = CardIdentityCollection[i].cardiden.NameTypeCard;
            car[i].IndeParentCard = CardIdentityCollection[i].cardiden.IndeParentCard;
            car[i].cardparentName = CardIdentityCollection[i].NameCardType;
            car[i].cardParent     = CardIdentityCollection[i];

            for (int j = 0; j < 4; j++)
            {
                car[i].Stats[j] = CardIdentityCollection[i].cardiden.Stats[j];
            }
        }
        string json = JsonHelper.ToJson(car, true);

        File.WriteAllText(Application.dataPath + "/PlayerData.json", json + "\n");
    }