Skip to content

Latest commit

 

History

History
70 lines (41 loc) · 1.38 KB

readme.md

File metadata and controls

70 lines (41 loc) · 1.38 KB

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);