Skip to content

Conversation

@Extrys
Copy link

@Extrys Extrys commented Feb 16, 2020

Pull request checklist

  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been reviewed and added / updated if needed (for bug fixes / features)
  • No compiler errors or warnings

Pull request type

  • Bugfix
  • Feature
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Documentation content changes
  • Other (please describe):

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?

  • Yes
  • No, Its just an extension

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?

  • 2020.4 LTS
  • 2020.3
  • 2020.2
  • 2020.1
  • 2019.4 LTS
  • 2019.3
  • 2019.2
  • 2019.1
  • 2018.4 LTS

Scripting backend:

  • Mono
  • IL2CPP

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...
but 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 ISignalSaveGame 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 and abstractions to signals
Since you are firing a concrete signal with the action you are doing
And giving them functionality trough Interface implementations
@Extrys Extrys requested a review from svermeulen February 16, 2020 16:41
@Extrys Extrys force-pushed the SignalInterfaceCompatibility branch from f2367a6 to 271af69 Compare February 16, 2020 19:38
Extrys and others added 5 commits February 16, 2020 20:41
Removed async aproach for AbstractFire in intefraces
comments removed since documentation will give info about
Documentation explaining the use of Signals with Interfaces and advantages of using them
@Mathijs-Bakker Mathijs-Bakker linked an issue Feb 16, 2020 that may be closed by this pull request
@Mathijs-Bakker Mathijs-Bakker merged commit 2e93607 into modesttree:master Feb 16, 2020
@Mathijs-Bakker
Copy link
Collaborator

Cool, gracias!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Interface Support for Signals

2 participants