// Throws an error if passed a null item. // Raises InventoryItemAddedCallback when item is added. public bool AddItem(SpawnMenuItem item) { if (item == null) { Debug.LogError("Trying to add a null item to a menu page"); return(false); } items.Add(item); if (cbInventoryItemAdded != null) { cbInventoryItemAdded(this.label, item); } return(true); }
// Load all posters in given filepath // TODO: Get rid of static function public List <SpawnMenuItem> LoadPosters(string texturePath) { List <SpawnMenuItem> posters = new List <SpawnMenuItem>(); string posterPrefabPath = Poster.PrefabPath; Object[] sprites = Resources.LoadAll(texturePath, typeof(Sprite)); foreach (Object s in sprites) { Sprite sprite = (Sprite)s; PosterInitData newPosterData = new PosterInitData(posterPrefabPath, s.name, sprite.texture); // TODO : Parse name (human-readable) into something prettier? SpawnMenuItem newPoster = new SpawnMenuItem(s.name, sprite, newPosterData); posters.Add(newPoster); } return(posters); }
void OnMenuItemAdded(string pageLabel, SpawnMenuItem item) { /////////////////////////// /// Add a menu item button /////////////////////////// Transform parent = pageLabelScrollViewMap[pageLabel].transform.Find("Viewport/Content"); MenuButton menuButton = Instantiate(MenuButtonPrefab, parent).GetComponent <MenuButton>(); if (menuButton == null) { Debug.LogError("A MenuButtonPrefab was instantiated without the MenuButton component - no bueno"); return; } // Link the menu button to a SpawnController method menuButton.onClick.AddListener(() => { spawnHandler.OnSpawnMenuButtonClicked(menuButton, item.ObjectInitData); }); menuButton.Label = item.Label; menuButton.Background = item.Icon; }