示例#1
0
    public void initCard(GameObject panel, GameObject nCard, LoadCards.cardProperties a,  bool tisEnemy)
    {
        string filePath = Application.dataPath;

        if(tisEnemy) nCard.transform.Find("BackOfCard").gameObject.SetActive(true);
        else nCard.transform.Find("BackOfCard").gameObject.SetActive(false);

        nCard.transform.SetParent(panel.transform, false);
         nCard.GetComponent<Statistics>().hp = a.obrona;
         nCard.GetComponent<Statistics>().atk = a.atak;
         nCard.GetComponent<CardResources>().like = a.like;
         nCard.GetComponent<CardResources>().tweet = a.tweet;
         nCard.GetComponent<CardResources>().snap = a.snap;
         nCard.GetComponent<Properties>().isEnemy = tisEnemy;
         if (a.typ.Equals("Archer"))
         {
             nCard.GetComponent<Properties>().type = Properties.typy.Archers;
         }
         else
         {
             nCard.GetComponent<Properties>().type = Properties.typy.Melee;
         }

         Text Title;
         Transform TitleTrans = nCard.transform.Find("UpperPanel").transform.Find("TitleImage").transform.Find("Text");
         Title = TitleTrans.GetComponentInChildren<Text>();
         Title.text = a.nazwa;

         //Text Description;
         //Transform DescriptionTrans = nCard.transform.Find("Description");
         //Description = DescriptionTrans.GetComponentInChildren<Text>();
         //Description.text = "l: " + nCard.GetComponent<Resources>().like + " t: " + nCard.GetComponent<Resources>().tweet + " s: " + nCard.GetComponent<Resources>().snap;

         Text Like;
         Transform LikeTrans = nCard.transform.Find("BottomPanel").transform.Find("LikeText");
         Like = LikeTrans.GetComponentInChildren<Text>();
         Like.text = nCard.GetComponent<CardResources>().like.ToString();

         Text Snap;
         Transform SnapTrans = nCard.transform.Find("BottomPanel").transform.Find("SnapText");
         Snap = SnapTrans.GetComponentInChildren<Text>();
         Snap.text = nCard.GetComponent<CardResources>().snap.ToString();

         Text Tweet;
         Transform TweetTrans = nCard.transform.Find("BottomPanel").transform.Find("TweetText");
         Tweet = TweetTrans.GetComponentInChildren<Text>();
         Tweet.text = nCard.GetComponent<CardResources>().tweet.ToString();

        nCard.GetComponent<Properties>().description = a.opis + "\n Typ: " + a.typ.ToString();

         if (File.Exists(filePath + "\\Tekstury\\" + a.nazwa + ".jpg"))
         {
             byte[] data = File.ReadAllBytes(Application.dataPath + "\\Tekstury\\" + a.nazwa + ".jpg");
             Texture2D texture = new Texture2D(64, 64, TextureFormat.ARGB32, false);
             texture.LoadImage(data);
             Sprite s = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
             nCard.transform.Find("CardImage").GetComponent<Image>().sprite = s;
         }
         else
         {
             byte[] data = File.ReadAllBytes(Application.dataPath + "\\Tekstury\\tmp.jpg");
             Texture2D texture = new Texture2D(64, 64, TextureFormat.ARGB32, false);
             texture.LoadImage(data);
             Sprite s = Sprite.Create(texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
             nCard.transform.Find("CardImage").GetComponent<Image>().sprite = s;
         }

        GameObject panelToReturn = GameObject.Find("Hand");
        nCard.GetComponent<Card>().parentToReturnTo = panelToReturn.transform;

        // Assign ID to card
        var gameWorld = GameObject.Find("GameWorld");
        nCard.GetComponent<Properties>().CardId = gameWorld.GetComponent<AssignID>().giveID();
        gameWorld.GetComponent<AssignID>().allCards.Add(nCard);
        Debug.Log("Nazwa: " + nCard.name + " Id: " + nCard.GetComponent<Properties>().CardId);
    }
 private void Client_LoadGiveCards(Dictionary <int, PlayerCard> cards)
 {
     LoadCards?.Invoke(cards);
 }