Search Unity

Question How to Increase Modularity of a Reused Class

Discussion in 'Scripting' started by Judicator4, May 27, 2023.

  1. Judicator4

    Judicator4

    Joined:
    Feb 17, 2019
    Posts:
    1
    I have a InventoryManager class which handles the inventory UI panels display for multiple objects in my game. This is a crafting game, currently there are three different panels: inventory, furnace, and anvil.

    upload_2023-5-27_13-28-55.png

    upload_2023-5-27_13-25-24.png

    Using this one class worked great for starters but as I build new features I am finding that the anvil requires a slightly different implementation of the InventoryManager.

    For example it was okay that the player's inventory showed a fixed number of slots, but the anvil inventory I would like to dynamically show the number of items required to craft an item.

    What might be the best approach for making the Anvil Panel's implementation of Inventory Manager unique? I am trying to avoid using a line such as (to improve scalability):
    if (this.gameObject.name == "Anvil Panel")