Decouple your Game Objects! Create a powerful Unity Event Bus that bootstraps itself at runtime using advanced C# and Unity techniques. Discover how to execute code before your scenes load and search Unity assemblies for your code. This video will help you take your skills to the next level, even if you feel like you are still a beginner!
A custom Event Bus is great for larger or more complex projects where decoupling is essential. It helps in organizing code in a way that various parts of your system can communicate without needing to reference each other directly. This way, you can change one part of your system without having a domino effect of changes across the codebase. It can help in categorizing events, logging, and even debugging to some extent by providing a clearer overview of what's happening in your game.
Advanced Topics:
- RuntimeInitializeOnLoadMethod
- InitializeOnLoadMethod
- Type.MakeGenericType(T)
- Unity Predefined Assemblies
Many people have asked, 'Why not create an EventBus at runtime instead of bootstrapping?'
Instantiating static classes in C# has some overhead, so if you have a lot of different Events it can be beneficial to create all your Event Busses ahead of time and avoid potential problems during gameplay. Additionally, it allows you to efficiently create a list of all Busses so that you can clear statics when coming out of Play Mode, something that is not guaranteed by Unity when Domain Reload is disabled, and can cause strange behaviour and memory leaks. Furthermore, you may wish to clear them anytime, or perform other debugging or diagnostics on all instances.
See the bit about Unity statics here:
[ Ссылка ]
🔔 Subscribe for more Unity Tutorials [ Ссылка ]
#unity3d #gamedev #indiedev
▬ Contents of this video ▬▬▬▬▬▬▬▬▬▬
0:00 Unity Event Bus
5:00 Assemblies Utility
8:35 Event Bus Bootstrapping
11:30 Event Bus in Action!
*Source code:* [ Ссылка ]
Extension Methods and Utils
[ Ссылка ]
*Assets Shown In This Video* (Affiliate Links)
Odin: [ Ссылка ]
Dungeon Mason Tiny Hero Duo: (FREE): [ Ссылка ]
Chromisu: Handpainted Forest MEGA Pack [ Ссылка ]
VFX Trees: [ Ссылка ]
Kronnect Liquid Volume 2: [ Ссылка ]
Kronnect Cloud Shadows: [ Ссылка ]
Kronnect Beautify: [ Ссылка ]
Kyeoms Hyper Casual FX 2: [ Ссылка ]
MalberS Animations: Forest Golems: [ Ссылка ]
Archanor VFX Portals: [ Ссылка ]
SineVFX: Better Crystals [ Ссылка ]
Unity Documentation on Predefined Assemblies: [ Ссылка ]
*Follow me!*
[ Ссылка ]
Ещё видео!