Interface Compatibility for Signals #91
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull request checklist
Pull request type
Issue Number #90
What is the current behavior?
Normally you can not declare concrete interfaces
and then subscribe to their interface types
and you realice you are coupling your concrete signal types to the receivers
for example.
Lets say I have a player and i want to save the game when i finish a level
Ok, easy I create "signalLevelCompleted" and then I subscribe it to my "SaveGameSystem"
then I also want to save when i reach a checkpoint
Again i create "SignalCheckpointReached"
and then I subscribe it to my "SaveGameSystem"
And then you realize you are coupling the types
"signalLevelCompleted" and "SignalCheckpointReached" to your "SaveGameSystem"
ohhh its not too good...
What is the new behavior?
Lets give the power of the interfaces to the signals
So i have the SignalCheckPoint reached
and SignalLevelCompleted
Both implements ISignalGameSaver
My GameSaverSystem just Subscribes to ISignalGameSaver for saving the game
So when i shot any of that signals i automatically save the game
and if for example i create another signal for Achievements "SignalAchievementCompleted"
I just have to implement the interface to it so it saves the game automatically
It offers a lot of modularity, abstractions and flexibility to signals
Since you are firing a concrete signal with the type of what you are doing
And giving them functionality trough Interface implementations
Does this introduce a breaking change?
How to use
All you have to do is "signalBus.AbstractFire" instead "signalBus.Fire"
In this way you are firing also the interfaces, and they need to be declared too
in this way "Container.DeclareSignalWithInterfaces()" insteas of
"Container.DeclareSignal()"
other ways it will give an exception for not declaring also interfaces when doing AbstractFire
On which Unity version has this been tested?
Scripting backend: