Dependencies
Dependencies in CCBK are used similarly to IOC Containers in other areas of development. The implementation however is stripped down to a minimum to accommodate the performance needs of games.
Basically Dependencies allow the registration and retrieval of interfaces. This allows the implementation to be changed and moved without having to rewire all entities that depend on it.
Most systems in CCBK have some central manager component that all the components need access to. Theses managers are not wired up in the editor or implemented as singletons.
Instead the system includes an interface for that manager. The Behaviour that actually implements the interface calls Register on Dependencies when it awakens in the scene. Any components that need the manager call Get on Dependencies.
When possible keep changes to CCBK to a minimum. Instead remove the default implementation from the scene and add your own.
Let’s say you wanted to change how the production components are prioritized for delivered raw materials.
- copy DefaultItemManager to the project folder and rename it to something like MyProjectItemManager
- change the code to fit your project
- replace the item manager in the scene
- pro tip: switch to debug mode in the inspector and replace the script to keep the field values
Many of the default managers register multiple interfaces for convenience, these can be easily split up thanks to the Dependency system. To replace just one of those interfaces with a custom implementation comment out the line in Awake where that interface is registered. That change will be lost if the Asset is upgraded but should be easy enough to restore.
Dependencies are automatically cleared between scenes.
All interfaces registered with Dependencies are effectively singletons. A possible extension of the system would be passing a tag when registering and getting to partition different areas of dependencies(eg different road managers for underground, ground and sky). CCBK does not include such an extension to keep performance optimal for those that do not need it.