Skip to content

A super simple, lightweight, and fast PubSub pattern for Unity.

License

Notifications You must be signed in to change notification settings

hieki-chan/simplest-pubsub-ever

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 

Repository files navigation

simplest-pubsub-ever

A super simple, lightweight, and fast PubSub pattern for Unity.

Import Package

Window > Package Manager > (+) Plus Button > Add Package form git Url

git URL:

https://github.com/hieki-chan/simplest-pubsub-ever.git?path=com.hieki.simplest-pubsub-ever

Example

using Hieki.Pubsub;

Topic

Topic loadTopic = Topic.FromMessage<LoadScenePayLoadMessage>();      //sample topic to publish

Message

internal readonly struct LoadScenePayLoadMessage : IMessage        //sample payload message
{
    public readonly float value;
    public readonly string state;

    public LoadScenePayLoadMessage(float value, string state)
    {
        this.value = value;
        this.state = state;
    }
}

Subscriber

ISubscriber subscriber { get; set; }

//subscribe with topic
subscriber.Subscribe<LoadScenePayLoadMessage>(Topic.FromMessage<LoadScenePayLoadMessage>(), static (payload) =>
{
    UnityEngine.Debug.Log($"state: {payload.state}, value: {payload.value}");
});

Publisher

IPublisher publisher { get; set; }

//create a message and publish to subscribers who are already subscribed to this event.
LoadScenePayLoadMessage payload = new LoadScenePayLoadMessage(999, "Success");
publisher.Publish(loadTopic, payload);

About

A super simple, lightweight, and fast PubSub pattern for Unity.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages