// Start is called before the first frame update void Start() { _animator = GetComponent <Animator>(); //First batch of items itemsBatch = 0; //Set current coins and diamonds coinsLabel.text = Game.Instance.coins.ToString(); diamondsLabel.text = Game.Instance.diamonds.ToString(); //int len = ShopItemsList.Count; //Show first three items for (int i = 0; i < 3; i++) { item = Instantiate(ItemPrefab, Container); item.transform.GetChild(0).GetComponent <Image>().sprite = ShopItemsList[i].icon; item.transform.GetChild(1).GetComponent <Text>().text = ShopItemsList[i].price.ToString(); buyBtn = item.transform.GetChild(3).GetComponent <Button>(); buyBtn.interactable = !ShopItemsList[i].isPurchased; if (ShopItemsList[i].isPurchased) { buyBtn.transform.GetChild(0).GetComponent <Text>().text = "OWNED"; } //Add custom event to each button buyBtn.AddEventListener(i, OnShopItemBtnClicked); } }
// Start is called before the first frame update void Start() { for (int i = 0; i < ObstacleShopItemList.Count; i++) { purchasedObstaclesList.Add(false); } LoadPurchasedObstacles(); // Check for equipped obstacles if (!PlayerPrefs.HasKey("Obstacle Equipped")) { PlayerPrefs.SetInt("Obstacle Equipped", 8); PlayerPrefs.Save(); } EquippedItemIndex = PlayerPrefs.GetInt("Obstacle Equipped"); ItemTemplate = ShopScrollView.GetChild(0).gameObject; int len = ObstacleShopItemList.Count; for (int i = 0; i < len; i++) { Debug.Log(purchasedObstaclesList[i]); } ObstacleShopItemList[EquippedItemIndex].isEquipped = true; ObstacleShopItemList[EquippedItemIndex].isPurchased = true; savePurchasedObstacles(EquippedItemIndex); LoadPurchasedObstacles(); for (int i = 0; i < len; i++) { g = Instantiate(ItemTemplate, ShopScrollView); g.transform.GetChild(0).GetComponent <Image>().sprite = ObstacleShopItemList[i].itemImage; g.transform.GetChild(2).GetComponent <Text>().text = ObstacleShopItemList[i].price.ToString(); buyButton = g.transform.GetChild(3).GetComponent <Button>(); equipButton = g.transform.GetChild(4).GetComponent <Button>(); equipButton.interactable = !ObstacleShopItemList[i].isEquipped; if (ObstacleShopItemList[i].isEquipped) { buyButton.gameObject.SetActive(false); equipButton.gameObject.SetActive(true); equipButton.transform.GetChild(0).GetComponent <Text>().text = "EQUIPPED"; } //buyButton.interactable = !ObstacleShopItemList[i].isPurchased; buyButton.interactable = !(purchasedObstaclesList[i]); if (purchasedObstaclesList[i]) { changeButtonText(buyButton, i, "PURCHASED"); equipButton.gameObject.SetActive(true); } buyButton.AddEventListener(i, OnShopItemBtnClicked); equipButton.AddEventListener(i, OnEquipButtonClicked); if (i == 10) { buyButton.gameObject.SetActive(false); equipButton.gameObject.SetActive(true); } } Destroy(ItemTemplate); }
protected override void CreateChildren() { base.CreateChildren(); // Create the scroll track. if (null == Track) { Track = new Button { Id = "track", SkinClass = typeof(HSliderTrackSkin), FocusEnabled = false, //MinHeight = 30, Top = 0, Bottom = 0, Left = 0, Right = 0, VerticalCenter = 0, //CurrentState = "disabled" }; AddChild(Track); } _cover = new Button { SkinClass = typeof(HSliderButtonSkin), FocusEnabled = false, MouseEnabled = false, //MinHeight = 30, Top = 0, Bottom = 0, Left = 0, VerticalCenter = 0 }; AddChild(_cover); if (null == Thumb) { Thumb = new Button { Id = "thumb", SkinClass = typeof(HSliderButtonSkin), //MinHeight = 30, Top = 0, Bottom = 0, MinWidth = 20, FocusEnabled = false, //ResizeWithStyleBackground = true, VerticalCenter = 0 }; Thumb.AddEventListener(FrameworkEvent.X_CHANGED, OnThumbPositionChanged); AddChild(Thumb); } }
protected override void CreateChildren() { base.CreateChildren(); // Create the scroll track. if (null == Track) { Track = new Button { Id = "track", SkinClass = typeof(VSliderTrackSkin), FocusEnabled = false, //MinWidth = 48, Left = 0, Right = 0, Top = 0, Bottom = 0, HorizontalCenter = 0 }; AddChild(Track); } _cover = new Button { SkinClass = typeof(VSliderButtonSkin), FocusEnabled = false, MouseEnabled = false, //MinWidth = 50, Left = 0, Right = 0, Bottom = 0, HorizontalCenter = 0 }; AddChild(_cover); if (null == Thumb) { Thumb = new Button { Id = "thumb", SkinClass = typeof(VSliderButtonSkin), //MinWidth = 50, Left = 0, Right = 0, MinHeight = 30, FocusEnabled = false, HorizontalCenter = 0 }; Thumb.AddEventListener(FrameworkEvent.Y_CHANGED, OnThumbPositionChanged); AddChild(Thumb); } }
private void Start() { for (int i = 0; i < ShopItemList.Count; i++) { g = Instantiate(ItemTemplate, ShopScrollView); g.transform.GetChild(0).GetComponent <Image>().sprite = ShopItemList[i].image; g.transform.GetChild(1).GetChild(0).GetComponent <TextMeshProUGUI>().text = ShopItemList[i].Price.ToString(); buyBtn = g.transform.GetChild(2).GetComponent <Button>(); if (ShopItemList[i].IsPurchased) { DisableBuyButton(); } buyBtn.AddEventListener(i, OnShopItemBtnClicked); } }
public void GetShoes() { StartCoroutine(GetShoesRequest(result => { ItemTemplate = ShopScrollView.GetChild(0).gameObject; dataString = result; string jsonString = fixJson(dataString); ItemsClass[] items = JsonHelper.FromJson <ItemsClass>(jsonString); int len = items.Length - 1; for (int i = 0; i < len; i++) { if (items[i].type == "shoe") { Shoes.Add(new Shoe { type = items[i].type, name = items[i].name, color = items[i].color, price = items[i].price, id = items[i].id }); } } /*foreach (var s in Shoes) * { * Debug.Log("Item: " + s.type + " " + s.name + " " + s.color + " " + s.price + " " + s.id); * }*/ int x = ShoeImageList.Count; for (int i = 0; i < x; i++) { g = Instantiate(ItemTemplate, ShopScrollView); g.transform.GetChild(0).GetComponent <Image>().sprite = ShoeImageList[i].Image; g.transform.GetChild(1).GetChild(0).GetComponent <Text>().text = Shoes[i].price.ToString(); buyBtn = g.transform.GetChild(2).GetComponent <Button>(); buyBtn.interactable = !Shoes[i].IsPurchased; buyBtn.AddEventListener(i, OnShopItemBtnClicked); } Destroy(ItemTemplate); })); }
IEnumerator listUpgradeItem() { for (int i = 0; i < ItemManager.instance.ItemList.Count; i++) { yield return(new WaitForSeconds(0.15f)); upgradeITem = Instantiate(upgradeItemTemplate, upgradeItemScrollView); upgradeITem.transform.GetChild(0).GetComponent <Image>().sprite = ItemManager.instance.ItemList[i].image; upgradeITem.transform.GetChild(2).GetChild(2).GetComponent <Image>().sprite = ItemManager.instance.ItemList[i].image; upgradeITem.transform.GetChild(2).GetComponent <Slider>().value = ItemManager.instance.ItemList[i].level; SetEffectUpgradeText(i); RefreshUpgradeCostAndButton(i); upgradeButton = upgradeITem.transform.GetChild(1).GetComponent <Button>(); upgradeButton.AddEventListener(i, UpgradeButtonClicked); } }
// Use this for initialization void Start() { JsonData jd = Winter.Utils.Str2Json("skin2.txt"); WinterComponent wc = new WinterComponent(); wc.m_Entity = GameObject.Find("wPanel"); wc.skin = jd; //DisplayObject obj = Utils.GetDescendant(wc, "winterButton/winterImage"); //Debug.Log(obj); WinterComponent bb = wc.children["winterContainer"] as WinterComponent; Button _bb = bb.children["winterButton"] as Button; _bb.AddEventListener(UIButtonMessage.Trigger.OnClick, "OnClickHandler", gameObject, "winter"); WinterComponent bb2 = wc.children["winterContainer"] as WinterComponent; Button _bb2 = bb2.children["summerButton"] as Button; _bb2.AddEventListener(UIButtonMessage.Trigger.OnClick, "OnClickHandler", gameObject, "summer"); }
private void Start() { skinTemplate = shopScrollView.GetChild(0).gameObject; for (int i = 0; i < skinList.Count; i++) { skinList[i].knifeSkin = Instantiate(skinTemplate, shopScrollView); skinList[i].knifeSkin.transform.GetChild(1).GetComponent <Image>().sprite = skinList[i].knifeSkinSprite; skinBtn = skinList[i].knifeSkin.transform.GetChild(2).GetComponent <Button>(); skinBtn.AddEventListener(i, SkinButtonClick); SaveSkins.WriteSkins(skinList[i].nameSkin, skinList[i].isPurchased); } SaveSkins.LoadGame(); CheckNewSkin(); Destroy(skinTemplate); }
IEnumerator listSkin() { for (int i = 0; i < SkinManager.instance.ShopSkinList.Count; i++) { yield return(new WaitForSeconds(0.15f)); skin = Instantiate(shopSkinTemplate, shopSkinScrollView); skin.transform.GetChild(0).GetComponent <Image>().sprite = SkinManager.instance.ShopSkinList[i].image; skin.transform.GetChild(1).transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = SkinManager.instance.ShopSkinList[i].prize.ToString(); setCostType(i); buyButton = skin.transform.GetChild(1).GetComponent <Button>(); selectButton = skin.transform.GetChild(2).GetComponent <Button>(); buyButton.gameObject.SetActive(PlayerPrefs.GetInt(SkinManager.instance.ShopSkinList[i].name + "Skin", 0) == 0); if (buyButton.gameObject.activeSelf == true) { selectButton.gameObject.SetActive(false); } else { selectButton.gameObject.SetActive(true); shopSkinScrollView.GetChild(i).GetComponent <Animator>().SetBool("buyanim", true); } if (i == PlayerPrefs.GetInt("CurrentSkin", 0)) { selectButton = shopSkinScrollView.GetChild(i).GetChild(2).GetComponent <Button>(); //set current skin selected button to SELECTED text selectButton.gameObject.transform.GetChild(0).GetComponent <TextMeshProUGUI>().text = "SELECTED"; shopSkinScrollView.GetChild(i).GetComponent <Animator>().SetBool("buyanim", true); } buyButton.AddEventListener(i, ShopItemBuyButtonClicked); selectButton.AddEventListener(i, ShopItemSelectClicked); } }
private void Start() { ItemTemplate = ShopScrollView.GetChild(0).gameObject; int len = ShopItemsList.Count; for (int i = 0; i < len; i++) { ShopItemsList[i].isOpened = PlayerPrefs.GetInt(ShopItemsList[i].isOpened + "itemOpened"); g = Instantiate(ItemTemplate, ShopScrollView); if (ShopItemsList[i].icon != null && !isPurchasedApple) { g.transform.GetChild(0).GetChild(0).GetComponent <Image>().sprite = ShopItemsList[i].icon; } if (isPurchasedApple) { g.transform.GetChild(0).GetChild(0).GetComponent <Image>().sprite = apple; } if (ShopItemsList[i].Price != 0) { g.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <Text>().text = ShopItemsList[i].Price.ToString(); } else { g.transform.GetChild(0).GetChild(0).GetChild(0).GetComponent <Text>().text = ""; } g.transform.GetChild(0).GetComponent <Image>().color = clickColor; buyButton = g.transform.GetChild(0).GetComponent <Button>(); buyButton.interactable = !ShopItemsList[i].IsPurchased; buyButton.AddEventListener(i, OnClickedButton); if (ShopItemsList[i].isOpened == 1) { OpenThisItem(i); } } Destroy(ItemTemplate.gameObject); }
public InventoryRepository(GameObject storageWrap, GameObject markSign) { _markSign = markSign; _storageWrap = storageWrap; _selectedItems = new List <int>(); _itemsBox = _storageWrap.transform.GetChild(0).gameObject; _sellButton = _storageWrap.transform.GetChild(1).GetComponent <Button>(); Size = _itemsBox.transform.childCount - 1; for (int i = 0; i < Size; i++) { int code = i + 1; _allItems.Add(new Item(_itemsBox.transform.GetChild(code).GetComponent <Button>())); _allItems[i].Button.AddEventListener(code - 1, SelectItem); } _storageWrap.SetActive(false); ActivateSellButton(false); _sellButton.AddEventListener(Size, SellButtonClicked); }
private void Start() { for (int i = 0; i < tilesList.transform.childCount; i++) { GameObject tile = tilesList.transform.GetChild(i).gameObject; tile.transform.GetChild(0).GetComponent <Image>().sprite = TilesList[i].sprite; tile.transform.GetChild(1).GetChild(0).GetComponent <TextMeshProUGUI>().text = TilesList[i].price.ToString(); button = tile.transform.GetChild(2).GetComponent <Button>(); button.interactable = !TilesList[i].isPurchased; button.AddEventListener(i, OnTilesListPress); tile.SetActive(true); } for (int j = 0; j < backgroundsList.transform.childCount; j++) { GameObject background = backgroundsList.transform.GetChild(j).gameObject; background.transform.GetChild(0).GetComponent <Image>().sprite = BackgroundsList[j].sprite; background.transform.GetChild(1).GetChild(0).GetComponent <TextMeshProUGUI>().text = BackgroundsList[j].price.ToString(); button = background.transform.GetChild(2).GetComponent <Button>(); button.interactable = !BackgroundsList[j].isPurchased; button.AddEventListener(j, OnBackgroundsListPress); background.SetActive(true); } }
public IEnumerator ChangeStoreItems() { //Wait until Rope caontainer out of screen yield return(new WaitForSeconds(0.7f)); //Destroy old items GameObject[] oldItems = GameObject.FindGameObjectsWithTag("StoreItem"); for (int i = 0; i < oldItems.Length; i++) { Destroy(oldItems[i]); } //Instantiate next items batch for (int i = 0; i < 3; i++) { item = Instantiate(ItemPrefab, Container); item.transform.GetChild(0).GetComponent <Image>().sprite = ShopItemsList[itemsBatch * 3 + i].icon; item.transform.GetChild(1).GetComponent <Text>().text = ShopItemsList[itemsBatch * 3 + i].price.ToString(); //Check if premium to change coin icon if (ShopItemsList[itemsBatch * 3 + i].isPremium) { item.transform.GetChild(2).GetComponent <Image>().sprite = premiumSprite; } buyBtn = item.transform.GetChild(3).GetComponent <Button>(); buyBtn.interactable = !ShopItemsList[itemsBatch * 3 + i].isPurchased; if (ShopItemsList[itemsBatch * 3 + i].isPurchased) { buyBtn.transform.GetChild(0).GetComponent <Text>().text = "OWNED"; } //Add custom event to each button buyBtn.AddEventListener(itemsBatch * 3 + i, OnShopItemBtnClicked); } }
/// <summary> /// Note: Since Load could happen, if both scene containing OptionsToolbar, we wouldn't like to instantiate twice /// Thus we made 2 checks in for toolbar existance in this class /// </summary> protected override void CreateChildren() { if (HideInEditor && Application.isEditor) return; base.CreateChildren(); if (null != _vbox) return; // meaning toolbar created in the previous scene _vbox = new VGroup { Right = 10, MinWidth = 160, Gap = 0 }; OptionsToolbarStage.Instance.AddChild(_vbox); // add to InspectorOverlayStage _options = new Options(); _options.SetStyle("showBackground", true); _vbox.AddChild(_options); Button handle = new Button { StyleName = "handle_horiz", FocusEnabled = false, PercentWidth = 100, ResizeWithStyleBackground = true, Text = "Options" }; _vbox.AddChild(handle); handle.AddEventListener(MouseEvent.ROLL_OVER, delegate(Event e) { if (handle == e.Target) { Show(); } e.CancelAndStopPropagation(); }, EventPhase.Capture | EventPhase.Target ); _vbox.AddEventListener(MouseEvent.ROLL_OVER, // deffering hide delegate { if (null != _timer) { _timer.Reset(); _timer.Stop(); } }, EventPhase.Capture | EventPhase.Target ); _vbox.AddEventListener(MouseEvent.ROLL_OUT, delegate(Event e) { if (_vbox == e.Target) { if (null == _timer) _timer = new Timer(1, 1); _timer.Complete += delegate { Hide(); _timer.Dispose(); _timer = null; }; _timer.Start(); } e.CancelAndStopPropagation(); }, EventPhase.Capture | EventPhase.Target ); _vbox.ValidateNow(); // invoke measure float h = _options.Height; _vbox.Y = -h; _hide.YTo = -h; }
/// <summary> /// Note: Since Load could happen, if both scene containing OptionsToolbar, we wouldn't like to instantiate twice /// Thus we made 2 checks in for toolbar existance in this class /// </summary> protected override void CreateChildren() { if (HideInEditor && Application.isEditor) { return; } base.CreateChildren(); if (null != _vbox) { return; // meaning toolbar created in the previous scene } _vbox = new VGroup { Right = 10, MinWidth = 160, Gap = 0 }; OptionsToolbarStage.Instance.AddChild(_vbox); // add to InspectorOverlayStage _options = new Options(); _options.SetStyle("showBackground", true); _vbox.AddChild(_options); Button handle = new Button { StyleName = "handle_horiz", FocusEnabled = false, PercentWidth = 100, ResizeWithStyleBackground = true, Text = "Options" }; _vbox.AddChild(handle); handle.AddEventListener(MouseEvent.ROLL_OVER, delegate(Event e) { if (handle == e.Target) { Show(); } e.CancelAndStopPropagation(); }, EventPhase.Capture | EventPhase.Target ); _vbox.AddEventListener(MouseEvent.ROLL_OVER, // deffering hide delegate { if (null != _timer) { _timer.Reset(); _timer.Stop(); } }, EventPhase.Capture | EventPhase.Target ); _vbox.AddEventListener(MouseEvent.ROLL_OUT, delegate(Event e) { if (_vbox == e.Target) { if (null == _timer) { _timer = new Timer(1, 1); } _timer.Complete += delegate { Hide(); _timer.Dispose(); _timer = null; }; _timer.Start(); } e.CancelAndStopPropagation(); }, EventPhase.Capture | EventPhase.Target ); _vbox.ValidateNow(); // invoke measure float h = _options.Height; _vbox.Y = -h; _hide.YTo = -h; }
//[SerializeField] public bool[] purchaseBallsList = new bool[10]; // Start is called before the first frame update void Start() { for (int i = 0; i < BallShopItemList.Count; i++) { purchasedBallsList.Add(false); } LoadPurchasedBalls(); //purchasedBallsList = LoadPurchasedBalls(); /*for (int i=0;i<purchasedBallsList.Count;i++) * { * purchasedBallsList[i] = false; * }*/ /*for (int i = 0; i < purchasedBallsList.Count; i++) * { * //purchasedBallsList[i] = false; * Debug.Log(purchasedBallsList[i]); * }*/ if (!PlayerPrefs.HasKey("Ball Equipped")) { PlayerPrefs.SetInt("Ball Equipped", 0); PlayerPrefs.Save(); } EquippedItemIndex = PlayerPrefs.GetInt("Ball Equipped"); if (EquippedItemIndex == 10 && PlayerPrefs.GetInt("isTop") == 0) { EquippedItemIndex = 0; } ItemTemplate = ShopScrollView.GetChild(0).gameObject; int len = BallShopItemList.Count; for (int i = 0; i < len; i++) { Debug.Log(purchasedBallsList[i]); } BallShopItemList[EquippedItemIndex].isEquipped = true; BallShopItemList[EquippedItemIndex].isPurchased = true; savePurchasedBalls(EquippedItemIndex); LoadPurchasedBalls(); for (int i = 0; i < len; i++) { g = Instantiate(ItemTemplate, ShopScrollView); g.transform.GetChild(0).GetComponent <Image>().sprite = BallShopItemList[i].itemImage; g.transform.GetChild(2).GetComponent <Text>().text = BallShopItemList[i].price.ToString(); buyButton = g.transform.GetChild(3).GetComponent <Button>(); equipButton = g.transform.GetChild(4).GetComponent <Button>(); equipButton.interactable = !BallShopItemList[i].isEquipped; if (BallShopItemList[i].isEquipped) { buyButton.gameObject.SetActive(false); equipButton.gameObject.SetActive(true); equipButton.transform.GetChild(0).GetComponent <Text>().text = "EQUIPPED"; } //buyButton.interactable = !BallShopItemList[i].isPurchased; buyButton.interactable = !(purchasedBallsList[i]); if (purchasedBallsList[i]) { changeButtonText(buyButton, i, "PURCHASED"); equipButton.gameObject.SetActive(true); } //configureButton(i); buyButton.AddEventListener(i, OnShopItemBtnClicked); equipButton.AddEventListener(i, OnEquipButtonClicked); if (i == 10) { buyButton.gameObject.SetActive(false); equipButton.gameObject.SetActive(true); /*if (PlayerPrefs.GetInt("isTop") != 1) * { * equipButton.interactable = true; * }*/ } /*if (BallShopItemList[i].isPurchased) * { * purchasedBallsList.Add(BallShopItemList[i]); * }*/ } Destroy(ItemTemplate); }