private void AddItemsOnBoard()
 {
     if (itemsFormServer.Items != null)
     {
         if (itemsFormServer.Items.Length > 0)
         {
             errorText.text = "";
             int x = 0;
             int y = 0;
             for (int i = 0; i < itemsFormServer.Items.Length; i++)
             {
                 var newItem = Instantiate(marketItemPrefab,
                                           new Vector3(
                                               transform.position.x + startPos.x + _xOffset * x,
                                               transform.position.y + startPos.y + _yOffset * y),
                                           Quaternion.identity, transform);
                 var item = itemsFormServer.Items[i];
                 StartCoroutine(loadItem.LoadIemIconFromWorkshop(item.ItemID, newItem));
                 newItem.GetComponent <MarketItemInfo>().SetInfo(item.MarketID, item.ItemID, item.Cost);
                 x++;
                 if (x >= 3)
                 {
                     x = 0;
                     y++;
                 }
             }
         }
         else
         {
             errorText.text = "Market Is Empty(";
         }
         return;
     }
     if (itemsFormServer.authCode == TestAPI.AuthCode.NoAuth)
     {
         errorText.text = "Auth is bad";
         if (authPanel != null)
         {
             StartCoroutine(VisibleAuthPanel());
         }
     }
     else
     {
         errorText.text = "Market Load Error";
     }
 }
Beispiel #2
0
    public void CreateItemFunction(int itemID, int craftID, TimeSpan timeToCraft)
    {
        this.itemID = itemID;
        int childCount = transform.childCount;
        var newItem    = Instantiate(
            itemPrefab,
            new Vector3(
                transform.position.x + startPos.x + _xOffset * childCount,
                transform.position.y + startPos.y,
                0),
            Quaternion.identity,
            transform);

        newItem.SetActive(false);

        newItem.name = $"{itemPrefab.name} {childCount + 1}";
        StartCoroutine(loadItemScript.LoadIemIconFromWorkshop(this.itemID, newItem));
        newItem.SetActive(true);

        var craftInfo = newItem.GetComponent <CraftItemInfo>();

        craftInfo.CraftID = craftID;
        craftInfo.ItemID  = itemID;

        var itemTime = newItem.GetComponent <TimeToCraft>();

        if (itemTime != null)
        {
            itemTime.SetTime(timeToCraft);
        }
        if (childCount >= 3)
        {
            RectTransform contentRect = GetComponent <RectTransform>();
            contentRect.sizeDelta = new Vector2(85 * (childCount - 2),
                                                //distance between 2 item * rows.count * yOffset
                                                contentRect.sizeDelta.y);
        }
    }