コード例 #1
0
    public void loadItem()
    {
        if (shopType == EShopType.ITEM)
        {
            return;
        }

        shopType = EShopType.ITEM;
        target   = null;

        AutoDestroy.destroyChildren(towerPanel, PlayNameHashIDs.Collider);
        towerPanel.transform.localPosition = Vector3.zero;
        towerPanel.GetComponent <UIPanel> ().clipOffset = Vector2.zero;

        setSpriteButton(EShopType.ITEM);

        int i = 0;

        foreach (System.Collections.Generic.KeyValuePair <string, ItemData> item in ReadDatabase.Instance.ItemInfo)
        {
            GameObject _itemShop = Instantiate(itemShopModel) as GameObject;
            _itemShop.transform.parent     = towerPanel.transform;
            _itemShop.transform.localScale = Vector3.one;

            UIAnchor anchor = _itemShop.GetComponent <UIAnchor>();
            anchor.container      = towerPanel.gameObject;
            anchor.relativeOffset = new Vector2(PlayConfig.TowerShopAnchor.PanelAnchorStart + i * PlayConfig.TowerShopAnchor.PanelAnchorDistance, 0);

            ItemShopController itemShopController = _itemShop.GetComponent <ItemShopController>();
            itemShopController.ID        = item.Key;
            itemShopController.ItemState = ItemManager.getItemState(item.Key);

            //set name
            string[] arr      = item.Value.Name.Split('-');
            string   text     = "";
            string   mainName = "";
            for (int k = 0; k < arr.Length; k++)
            {
                text     += arr[k];
                mainName += arr[k] + " ";
                if (k + 1 < arr.Length)
                {
                    text += "\n";
                }
            }
            text     = text.Trim();
            mainName = mainName.Trim();

            itemShopController.Name.text = text;
            itemShopController.MainName  = mainName;

            //set text value
            itemShopController.Value.text = item.Value.ValueText;

            //set background stretch
            foreach (Transform child in _itemShop.transform)
            {
                if (child.name == "Background")
                {
                    child.GetComponent <UIStretch>().container = towerPanel;
                    break;
                }
            }

            //set icon
            itemShopController.icon.spriteName = "item-" + item.Key.ToLower();
            itemShopController.setColor(false);

            itemShopController.icon.keepAspectRatio = UIWidget.AspectRatioSource.Free;
            itemShopController.icon.SetDimensions(itemShopController.icon.mainTexture.width, itemShopController.icon.mainTexture.height);
            itemShopController.icon.keepAspectRatio = UIWidget.AspectRatioSource.BasedOnHeight;

            UIStretch uiStretch = itemShopController.icon.GetComponent <UIStretch>();
            uiStretch.enabled = true;

            if (target == null)
            {
                target = _itemShop;
            }

            i++;
        }
        if (target != null)
        {
            target.GetComponentInChildren <ItemShopController>().setColor(true);
        }

        loadInfoItem();
    }