Post news RSS Codville, Resources Managing(Code Architecture) #6

The classes architecture behind the game resources managing.

Posted by on

Today’s devlog we will explain the idea and structure behind the managing game resources of our game.
First, we wanted to have a central script that would allow every other script that we needed to check the game resources could use to access these values. So based on that idea, we created the ResourcesManager:


So in this script, we associated every resource controller. We use the Properties of the needed controller, so each class that has to interact with a resource just needs to have a reference to ResourcesManager. Let’s say that a script was made to sell codfish, it would only have to have access to ResourcesManager to change both the amount of codfish and the currency:


If the ResourcesManager centered all the resources, they would also have a controller:


Each resource has its own way of dealing with data, like CodfishController handles both amount of codfish and codfish storage, or the reputation controller that controls how the reputation is changing based on 2 other resources Happiness and Villager count. Which brings us to the next point that is how this info is displayed on the screen and how the ReputationController knows when to change. So each resource has a UnityEvent that is Invoked when the resource changes:


With this, the ReputationController can Add a Listener to both VillagerController and HappinessController, and adjust its values only when one of the resources changes. The Events are also being used to display the info for the audience, as each resource has a resource Display that adds a listener to that resource's controller and changes the displayed info every time the resource changes.


This sums up the main idea behind the resource controlling of the game. Below you can also check a simplified version of UML Diagram for this specific area of resource controlling, where it only shows Properties and UnityEvents of each class.

UMLDiagramAP drawio


Post a comment
Sign in or join with:

Only registered members can share their thoughts. So come on! Join the community today (totally free - or sign in with your social account on the right) and join in the conversation.