Skip to content

A simple Unity publish subscribe system implemented in Unity 2019.2.

Notifications You must be signed in to change notification settings

formatc2013/subPub

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 

Repository files navigation

subPub

A simple publish subscibe system implemented in Unity.

It uses one static class to communicate amongst scripts.

Publishing and subscribing works by using eventargs classes(structs will be used later on).

Your evenargs classes implementations depend on your specific needs.

An example of an EventArgs class.

 public class OnApplySettingsButtonPressedEventArgs {    

    public float MusicVolumeLevel { get; set; }

    public float EffectsVolumeLevel { get; set; }

    }

Publishing:

 var args=new new OnApplySettingsButtonPressedEventArgs(
      yourdatavalues...
 );

 pubsubsystem.PublishToListeners(args);

Subscription:

    pubsubsystem.AddListener<OnApplySettingsButtonPressedEventArgs>((o)=> {

        yourimplementation...
    
    });

or

     public void yourFunction(object o){
        yourfunctionality...
     };
     ...
     pubsubsystem.AddListener<OnApplySettingsButtonPressedEventArgs>(yourFunction);

Get your desired data from o (derived from object) or just ignore it.

Unsubscription:

     public void yourFunction(object o){
        yourfunctionality...
     };
     ...
     pubsubsystem.RemoveListener<OnApplySettingsButtonPressedEventArgs>(yourFunction);

About

A simple Unity publish subscribe system implemented in Unity 2019.2.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages