Skip to main content

Indie game storeFree gamesFun gamesHorror games
Game developmentAssetsComics
SalesBundles
Jobs
Tags
(4 edits) (+1)

This part of code is just my prototyping/lazy programming left for later :D I've wanted to base it on event instead of leaving it in update, but forgot about it when preparing actual event :/

Adding your suggestions (with exception for foreach, just for readability sake) and moving it to be based on event it now looks and perform a lot better :)


void Start()
{
    sectionLines = GetComponent<PanelSectionLines>();
    title = transform.Find("Title").GetComponentInChildren<TextMeshProUGUI>();
    StationContent.Instance.OnContentChanged += HandleStationContentChanged;
}
private void HandleStationContentChanged(StationContent _stationContent)
{
    ItemContainer container = _stationContent.GetContainer();
    title.text = string.Format("Items {0:0} / {1:0}", container.CapacityUsed, container.Capacity); 
    sectionLines.RemoveAllLines();
    foreach (ItemStack stack in container.Items)
    {
       sectionLines.Set(Lang.ITEM_TYPE[stack.Type], string.Format("{0} {1:##}", Lang.ITEM_TYPE[stack.Type], stack.Amount));
    }
}
(5 edits)

That's great!

PS: Please don't over-rely on events (outside UI ofc). Those are 10x times slower and complicate future debugging considerably. If something can be just a method call - let it be just that, you will thank yourself for that later on (less time spent debugging==more productivity==happier you).