Exemplo n.º 1
0
    private void OnItemPurchased(int index)
    {
        Character       character = characterDB.GetPurchased(index);
        CharacterItemUI uiItem    = GetItemUI(index);

        if (GameDataManager.CanSpendCoins(character.price))
        {
            GameDataManager.SpendCoins(character.price);

            purchaseFx.Play();

            GameSharedUI.Instance.UpdateCoinsUIText();

            characterDB.PurchasedCharacter(index);

            uiItem.SetCharacterAsPurchased();
            uiItem.OnItemSelect(index, OnItemSelect);

            GameDataManager.AddPurchasedCharacter(index);
        }
        else
        {
            AnimateNoMoreCoins();
            uiItem.AnimateShakeItem();
        }
    }
Exemplo n.º 2
0
    void OnItemPurchased(int index)
    {
        Character       character = characterDB.GetCharacter(index);
        CharacterItemUI uiItem    = GetItemUI(index);

        if (GameDataManager.CanSpendCoins(character.price))
        {
            //Proceed with the purchase operation
            GameDataManager.SpendCoins(character.price);

            //Play purchase FX
            purchaseFx.Play();

            //Update Coins UI text
            GameSharedUI.Instance.UpdateCoinsUIText();

            //Update DB's Data
            characterDB.PurchaseCharacter(index);

            uiItem.SetCharacterAsPurchased();
            uiItem.OnItemSelect(index, OnItemSelected);

            //Add purchased item to Shop Data
            GameDataManager.AddPurchasedCharacter(index);
        }
        else
        {
            //No enough coins..
            AnimateNoMoreCoinsText();
            uiItem.AnimateShakeItem();
        }
    }
Exemplo n.º 3
0
    void SelectItemUI(int itemIndex)
    {
        previousSelectedItemIndex = newSelectedItemIndex;
        newSelectedItemIndex      = itemIndex;

        CharacterItemUI prevUiItem = GetItemUI(previousSelectedItemIndex);
        CharacterItemUI newUiItem  = GetItemUI(newSelectedItemIndex);
    }
Exemplo n.º 4
0
    void GenerateShopItemsUI()
    {
        //Loop throw save purchased items and make them as purchased in the Database array
        for (int i = 0; i < GameDataManager.GetAllPurchasedCharacter().Count; i++)
        {
            int purchasedCharacterIndex = GameDataManager.GetPurchasedCharacter(i);
            characterDB.PurchaseCharacter(purchasedCharacterIndex);
        }

        //Delete itemTemplate after calculating item's Height :
        itemHeight = ShopItemsContainer.GetChild(0).GetComponent <RectTransform> ().sizeDelta.y;
        Destroy(ShopItemsContainer.GetChild(0).gameObject);
        //DetachChildren () will make sure to delete it from the hierarchy, otherwise if you
        //write ShopItemsContainer.ChildCount you w'll get "1"
        ShopItemsContainer.DetachChildren();

        //Generate Items
        for (int i = 0; i < characterDB.CharactersCount; i++)
        {
            //Create a Character and its corresponding UI element (uiItem)
            Character       character = characterDB.GetCharacter(i);
            CharacterItemUI uiItem    = Instantiate(itemPrefab, ShopItemsContainer).GetComponent <CharacterItemUI> ();

            //Move item to its position
            uiItem.SetItemPosition(Vector2.down * i * (itemHeight + itemSpacing));

            //Set Item name in Hierarchy (Not required)
            uiItem.gameObject.name = "Item" + i + "-" + character.name;

            //Add information to the UI (one item)
            uiItem.SetCharacterName(character.name);
            uiItem.SetCharacterImage(character.image);
            uiItem.SetCharacterSpeed(character.speed);
            uiItem.SetCharacterPower(character.power);
            uiItem.SetCharacterPrice(character.price);

            if (character.isPurchased)
            {
                //Character is Purchased
                uiItem.SetCharacterAsPurchased();
                uiItem.OnItemSelect(i, OnItemSelected);
            }
            else
            {
                //Character is not Purchased yet
                uiItem.OnItemPurchase(i, OnItemPurchased);
            }

            //Resize Items Container
            ShopItemsContainer.GetComponent <RectTransform> ().sizeDelta =
                Vector2.up * ((itemHeight + itemSpacing) * characterDB.CharactersCount + itemSpacing);

            //you can use VerticalLayoutGroup with ContentSizeFitter to skip all of this :
            //(moving items & resizing the container)
        }
    }
Exemplo n.º 5
0
    void SelectedItemUI(int itemIndex)
    {
        previousSelectedItemIndex = newSelectedItemIndex;
        newSelectedItemIndex      = itemIndex;

        CharacterItemUI previousUIItem = GetItemUI(previousSelectedItemIndex);
        CharacterItemUI newUIItem      = GetItemUI(newSelectedItemIndex);

        previousUIItem.DeselectItem();
        newUIItem.SelectItem();
    }
Exemplo n.º 6
0
    void OnItemPurchase(int index)
    {
        Character       character = characterDB.GetCharacter(index);
        CharacterItemUI uiItem    = GetItemUI(index);

        if (GameDataManager.CanSpendWater(character.price))
        {
            //proceed with purchase operation
            GameDataManager.SpendWater(character.price);

            //Update Coin UI text
            GameSharedUI.Instance.UpdateWaterUIText();

            Instantiate(character.fish, new Vector3(0, 60, 0), transform.rotation);
        }
        else
        {
            Debug.Log("Not enough water");
        }
    }
Exemplo n.º 7
0
    void GenerateShopItemUI()
    {
        //delete ItemTemplate after calculating items height
        itemHeight = ShopItemContainer.GetChild(0).GetComponent <RectTransform>().sizeDelta.y;
        Destroy(ShopItemContainer.GetChild(0).gameObject);
        ShopItemContainer.DetachChildren();

        //Generate item
        for (int i = 0; i < characterDB.CharactersCount; i++)
        {
            Character       character = characterDB.GetCharacter(i);
            CharacterItemUI uiItem    = Instantiate(ItemPrefab, ShopItemContainer).GetComponent <CharacterItemUI> ();

            //move item to its position
            uiItem.SetItemPosition(Vector2.down * i * (itemHeight + itemSpacing));

            //set item name in hierarchy
            uiItem.gameObject.name = "Item" + i + "-" + character.name;

            //Add information to the UI (one time)
            uiItem.SetCharacterName(character.name);
            uiItem.SetCharacterImage(character.image);
            uiItem.SetCharacterPrice(character.price);

            if (character.isPurchased)
            {
                //character is purchased
                uiItem.SetCharacterAsPurchased();
                uiItem.OnItemSelect(i, OnItemSelected);
            }
            else
            {
                uiItem.SetCharacterPrice(character.price);
                uiItem.OnItemPurchase(i, OnItemPurchase);
            }

            //Resize item container
            ShopItemContainer.GetComponent <RectTransform>().sizeDelta =
                Vector2.up * ((itemHeight + itemSpacing) * characterDB.CharactersCount + itemSpacing);
        }
    }
Exemplo n.º 8
0
    private void GenerateShopItemsUI()
    {
        for (int i = 0; i < GameDataManager.GetallPurchasedCharacter().Count; i++)
        {
            int purchasedCharacterIndex = GameDataManager.GetPurchasedCharacter(i);
            characterDB.PurchasedCharacter(purchasedCharacterIndex);
        }

        itemHeight = shopItemsContainer.GetChild(0).GetComponent <RectTransform>().sizeDelta.y;
        Destroy(shopItemsContainer.GetChild(0).gameObject);
        shopItemsContainer.DetachChildren();

        for (int i = 0; i < characterDB.CharacterCount; i++)
        {
            Character       character = characterDB.GetPurchased(i);
            CharacterItemUI uiItem    = Instantiate(itemPrefab, shopItemsContainer).GetComponent <CharacterItemUI>();

            uiItem.SetItemPosition(Vector2.down * i * (itemHeight + itemSpacing));

            uiItem.SetCharacterImage(character.image);
            uiItem.SetCharacterPrice(character.price);

            if (character.isPurchased)
            {
                uiItem.SetCharacterAsPurchased();
                uiItem.OnItemSelect(i, OnItemSelect);
            }
            else
            {
                uiItem.SetCharacterPrice(character.price);
                uiItem.OnItemPurchased(i, OnItemPurchased);
            }

            shopItemsContainer.GetComponent <RectTransform>().sizeDelta = Vector2.up * ((itemHeight + itemSpacing) * characterDB.CharacterCount + itemSpacing);
        }
    }