コード例 #1
0
ファイル: UIShop.cs プロジェクト: hjj0416/Demo
    void ShowShop(int index)
    {
        int count = ShopGameObject.transform.childCount;

        while (count > 0)
        {
            count--;
            DestroyImmediate(ShopGameObject.transform.GetChild(0).gameObject);
        }
        Dictionary <int, BagItemBean> beans = BagItemBean.beans;

        foreach (var v in beans)
        {
            if (v.Value.type == index)
            {
                GameObject item = Instantiate(ShopItem);
                item.transform.SetParent(ShopGameObject.transform);
                if (!item.activeSelf)
                {
                    item.SetActive(true);
                }
                item.transform.localScale = Vector3.one;
                UIShopItem uiShopItem = item.GetComponent <UIShopItem>();
                uiShopItem.SetData(v.Value);
            }
        }
    }
コード例 #2
0
    /// <summary>
    /// 生成商店项目 并对UIShopItem赋值
    /// </summary>
    /// <returns></returns>
    IEnumerator InitItems()
    {
        int count = 0;
        int page  = 0;

        foreach (var kv in DataManager.Instance.ShopItems[this.shop.ID])
        {
            if (kv.Value.Status > 0)
            {
                GameObject go     = Instantiate(shopItem, itemRoot[page]);
                UIShopItem uiItem = go.GetComponent <UIShopItem>();
                uiItem.SetShopItem(kv.Key, kv.Value, this);
                //分页
                //count++;
                //if (count>=10)
                //{
                //    count = 0;
                //    page++;
                //    itemRoot[page].gameObject.SetActive(true);
                //}
            }
        }

        yield return(null);
    }
コード例 #3
0
    public void UpdateActiveItems(UIShopItem shopItem)
    {
        if (Id != shopItem.Source.GroupId)
        {
            return;
        }

        var shopController = GameController.Instance.ShopController;

        if (shopController.ActiveItems.TryGetValue(Id, out string prevActiveSkinId))
        {
            if (prevActiveSkinId != shopItem.Source.Id)
            {
                shopController.ActiveItems[Id] = shopItem.Source.Id;
                var prevActiveSkin = shopItems.Find(x => x.Source.Id == prevActiveSkinId);
                if (prevActiveSkin)
                {
                    prevActiveSkin.Source.State = State.Bought;
                    prevActiveSkin.UpdateItem();
                }
            }
        }
        else
        {
            shopController.ActiveItems.Add(Id, shopItem.Source.Id);
        }
        shopItem.UpdateItem();
    }
コード例 #4
0
 public void SelectShopItem(UIShopItem item)
 {
     if (selectShopItem != null)
     {
         selectShopItem.Selected = true;
     }
     selectShopItem = item;
 }
コード例 #5
0
ファイル: UIShop.cs プロジェクト: 1725038230/mmo
 public void SelectedShopItem(UIShopItem Item)
 {
     if (selectedItem != null)
     {
         selectedItem.Selceted = false;
     }
     selectedItem = Item;
 }
コード例 #6
0
 public void SelectShopItem(UIShopItem item)
 {
     //把上一个选中的项目改为否
     if (selectedItem != null)
     {
         selectedItem.Selected = false;
     }
     //绑定新的选中项目
     selectedItem = item;
 }
コード例 #7
0
    public void Equip()
    {
        if (equippedItem != null)
        {
            equippedItem.Unequip();
        }

        borderParent.SetActive(true);
        SetAllBorders(orangeColor);

        equippedItem = this;
    }
コード例 #8
0
 /// <summary>
 /// Use for refresh weapon list.
 /// </summary>
 void ReloadItems()
 {
     Weapon[] weaponTable = WeaponManager.instance.GetWeaponTable();
     shopItems = new UIShopItem[weaponTable.Length];
     foreach (Weapon item in weaponTable)
     {
         GameObject instance = GameObject.Instantiate <GameObject>(shopItemPrefab);
         instance.transform.SetParent(transform);
         UIShopItem shopItem = instance.GetComponent <UIShopItem>();
         shopItem.Initialize(item);
         shopItems[(int)item.type] = shopItem;
     }
 }
コード例 #9
0
ファイル: UIShop.cs プロジェクト: 1725038230/mmo
    IEnumerator InitItems()
    {
        int i = 0;

        foreach (var kv in DataManager.Instance.ShopItems[shop.ID])
        {
            if (kv.Value.Status > 0)
            {
                GameObject go = Instantiate(ShopItem, itemRoot[i / 22]);
                UIShopItem ui = go.GetComponent <UIShopItem>();
                ui.SetShopItem(kv.Key, kv.Value, this);
                i++;
            }
        }
        yield return(null);
    }
コード例 #10
0
    void ShowItem(List <EquipInfo> shopInfos, ShopItemType type)
    {
        if (null != m_prefab)
        {
            if (m_shopItems.Count < shopInfos.Count)
            {
                for (int i = m_shopItems.Count; i < shopInfos.Count; i++)
                {
                    GameObject uiObject = (GameObject)GameObject.Instantiate(m_prefab);
                    uiObject.transform.SetParent(m_parent);
                    uiObject.transform.localScale = Vector3.one;
                    UIShopItem item = Util.AddComponent <UIShopItem>(uiObject);
                    m_shopItems.Add(item);
                }
            }

            for (int i = 0; i < m_shopItems.Count; i++)
            {
                if (i < shopInfos.Count)
                {
                    if (type == ShopItemType.ShopItem_ALL)
                    {
                        m_shopItems[i].SetShopItemInfo(shopInfos[i]);
                        Util.SetActive(m_shopItems[i].Cache, true);
                    }
                    else
                    {
                        if (shopInfos[i].equipType + 1 == (int)type)
                        {
                            m_shopItems[i].SetShopItemInfo(shopInfos[i]);
                            Util.SetActive(m_shopItems[i].Cache, true);
                        }
                        else
                        {
                            Util.SetActive(m_shopItems[i].Cache, false);
                        }
                    }
                }
                else
                {
                    Util.SetActive(m_shopItems[i].Cache, false);
                }
            }
        }
    }
コード例 #11
0
 public void Init(UIShopItem shopItem, InventoryItem item)
 {
     originalColor = bgImg.color;
     uiShopItem    = shopItem;
     if (isDisabled)
     {
         DisableButton();
     }
     txtPrice.text = item.WeaponConfig.BasePrice.ToString();
     uiPointable   = GetComponent <UIPointable>();
     if (uiPointable != null)
     {
         uiPointable.Initialize(
             OnPointerEnter,
             OnPointerExit,
             OnPointerClick
             );
     }
 }
コード例 #12
0
    public void Init(string itemKey, bool equiped = false)
    {
        key = itemKey;

        GameController.StopItem data = GameController.instance.allShopItems[key];

        subTitleText.text = data.upgradeString;
        if (!data.weapon)
        {
            UpdateMainText();
            weaponIcon.enabled = false;
        }
        else
        {
            mainText.enabled  = false;
            weaponIcon.sprite = WeaponManager.instance.GetIconFromName(key);
        }

        int numLevels = data.costs.Length;

        for (int i = 0; i < numLevels; i++)
        {
            if (i > 0)
            {
                GameObject newBarObj = Instantiate(bars[0].gameObject, bars[0].transform.parent);
                bars.Add(newBarObj.GetComponent <Image>());
            }

            bars[i].color = (data.currentLevel > i) ? orangeColor : grayColor;
        }

        borders = borderParent.GetComponentsInChildren <Image>();

        if (equiped)
        {
            SetAllBorders(orangeColor);
            equippedItem = this;
        }
        else
        {
            borderParent.SetActive(false);
        }
    }
コード例 #13
0
ファイル: UIShop.cs プロジェクト: bradur/LD44
 public void DisplayItems(InventoryConfig inventoryConfig)
 {
     HideNextLevelButton();
     foreach (UIShopItem item in items)
     {
         if (item != null)
         {
             Destroy(item.gameObject);
         }
     }
     foreach (InventoryItem item in inventoryConfig.AvailableItems)
     {
         UIShopItem uiShopItem = Instantiate(config.UIShopItemPrefab);
         uiShopItem.Init(item);
         uiShopItem.SetParent(uiShopItemContainer);
         items.Add(uiShopItem);
     }
     SetCurrency(inventoryConfig.Currency);
 }
コード例 #14
0
    public void Select()
    {
        if (selectedItem != null)
        {
            selectedItem.Deselect();
        }

        borderParent.SetActive(true);

        if (!isEquipped)
        {
            SetAllBorders(Color.white);
        }
        else
        {
            SetAllBorders(orangeColor);
        }

        Shop.instance.OnItemSelected(key);
        selectedItem = this;
    }
コード例 #15
0
 public void RefreshItems()
 {
     _shopItemGrid.Clear();
     if (Main.netMode == 1)
     {
         MessageSender.SendGetNormalShop(-1);
     }
     else
     {
         for (var i = 0; i < 19; i++)
         {
             var testinfo = new JsonData.SimplifiedMarketItem
             {
                 ItemID   = Main.rand.Next(Main.itemTexture.Length),
                 Price    = Main.rand.Next(1, 10) * 10000,
                 Discount = Main.rand.Next(0, 5) * 5,
             };
             var bar = new UIShopItem(testinfo);
             _shopItemGrid.Add(bar);
         }
     }
     _relaxTimer = 180;
     _rotation   = 0f;
 }
コード例 #16
0
    public void Init()
    {
        //float currentHeight = 0;
        string equipedWeapon = PlayerPrefs.GetString("weapon", "pistol");

        List <GameController.StopItem> upgradeItems = new List <GameController.StopItem>();
        List <GameController.StopItem> weaponItems  = new List <GameController.StopItem>();

        foreach (KeyValuePair <string, GameController.StopItem> pair in GameController.instance.allShopItems)
        {
            if (pair.Value.weapon)
            {
                weaponItems.Add(pair.Value);
            }
            else
            {
                upgradeItems.Add(pair.Value);
            }
        }

        foreach (GameController.StopItem item in upgradeItems)
        {
            GameObject newItem = Instantiate(shopItemPrefab, content.transform);
            UIShopItem ui      = newItem.GetComponent <UIShopItem>();
            ui.Init(item.upgradeString);

            uiShopItems.Add(item.upgradeString, ui);
        }

        foreach (GameController.StopItem item in weaponItems)
        {
            GameObject newItem = Instantiate(shopItemPrefab, content.transform);
            UIShopItem ui      = newItem.GetComponent <UIShopItem>();
            ui.Init(item.upgradeString, item.upgradeString == equipedWeapon);

            uiShopItems.Add(item.upgradeString, ui);
        }

        // FOR SEPARATE GRIDS
        //upgradeTitleText.rectTransform.anchoredPosition = new Vector2(0, -currentHeight);
        //currentHeight += upgradeTitleText.rectTransform.rect.height + padding;

        //foreach (GameController.StopItem item in upgradeItems) {
        //    GameObject newItem = Instantiate(shopItemPrefab, upgradeParent.transform);
        //    UIShopItem ui = newItem.GetComponent<UIShopItem>();
        //    ui.Init(item.upgradeString);

        //    uiShopItems.Add(item.upgradeString, ui);
        //}

        //RectTransform upgradeRT = upgradeParent.GetComponent<RectTransform>();
        //upgradeRT.anchoredPosition = new Vector2(0, -currentHeight);
        //int numUpgradeRows = Mathf.CeilToInt(upgradeItems.Count / (upgradeRT.rect.width / (upgradeParent.cellSize.x + upgradeParent.spacing.x)));
        //currentHeight += Mathf.Abs(numUpgradeRows * upgradeParent.cellSize.y + padding);
        //if (Mathf.Abs(numUpgradeRows) > 1) {
        //    currentHeight += upgradeParent.spacing.y * (numUpgradeRows - 1);
        //}

        //weaponTitleText.rectTransform.anchoredPosition = new Vector2(0, -currentHeight);
        //currentHeight += weaponTitleText.rectTransform.rect.height + padding;

        //foreach (GameController.StopItem item in weaponItems) {
        //    GameObject newItem = Instantiate(shopItemPrefab, weaponParent.transform);
        //    UIShopItem ui = newItem.GetComponent<UIShopItem>();
        //    ui.Init(item.upgradeString);

        //    if (item.equiped) {
        //        newItem.GetComponent<UIShopItem>().Equip();
        //    }

        //    uiShopItems.Add(item.upgradeString, ui);
        //}

        //RectTransform weaponRT = weaponParent.GetComponent<RectTransform>();
        //weaponRT.anchoredPosition = new Vector2(0, -currentHeight);
        //int numWeaponRows = Mathf.CeilToInt(upgradeItems.Count / (weaponRT.rect.width / (weaponParent.cellSize.x + weaponParent.spacing.x)));
        //currentHeight += Mathf.Abs(numWeaponRows * weaponParent.cellSize.y + padding);
        //if (Mathf.Abs(numWeaponRows) > 1) {
        //    currentHeight += weaponParent.spacing.y * (numWeaponRows - 1);
        //}

        //content.sizeDelta = new Vector2(0, currentHeight);

        Reset();
    }
コード例 #17
0
ファイル: ShopPanel.cs プロジェクト: wmj12/unity-
 private void OnClick_Shop(UIShopItem shop)
 {
     ItemManager.Instance.AddItem(shop.id, shop.count);
 }