private void InitCategories(ShopCategory[] setupCategories) { // init array _shopTabs = new ShopTabView[setupCategories.Length]; // loop over all available categories - they come from the setup, see ShopCategory for (int index = 0; index < setupCategories.Length; index++) { // the current category ShopCategory setupCategory = setupCategories[index]; // spawn it ShopTabView tabView = Instantiate(_tabViewPrefab); tabView.InitTab(setupCategory); tabView.Hide(); _shopTabs[index] = tabView; // spawn the button opening the tab ShopTabButton tabButton = Instantiate(_tabButtonPrefab); tabButton.Init(index, setupCategory.name); // add tab to the screen _screen.AddTab(tabView, tabButton); } }
/// <summary> /// Switches current shop tab to the one with the respective index. /// </summary> /// <param name="tabIndex">Tab index to switch to</param> private void SwitchTab(int tabIndex) { // make sure we dont go out of bounds if ((tabIndex < 0) || (tabIndex >= _setup.Categories.Length)) { return; } // hide current tab, re assign and show again _currentTab.Hide(); _currentTab = _shopTabs[tabIndex]; _currentTab.Show(); }
private void OpenShop() { _currentTab = _shopTabs[_defaultTabIndex]; _currentTab.Show(); _screen.Show(); }