Skip to content

kaichi-oda-tiv/UniCom

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

UniCom

Pub/Sub library for Unity.

Unicom is a middleware based on UniRX.

How to use

  1. Add Unicom.Publisher instance
  2. Set Topic in the constructor of the Publisher instance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExamplePublisher : MonoBehaviour
{
    private UniCom.Publisher<bool> pub_;

    public bool BoolValue;

    public string Topic;

    public string NameSpace;

	// Use this for initialization
	void Start ()
    {
        pub_ = new UniCom.Publisher<bool>(Topic);
    }
	
	// Update is called once per frame
	void Update ()
    {
        Debug.Log(NameSpace + ":" + BoolValue);
        pub_.Publish(BoolValue);
	}
}
  1. Add Unicom.Subscriber instance
  2. Set Topic in the constructor of the Subscriber instance
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class ExampleSubscriber : MonoBehaviour {

    public string Topic;
    public string NameSpace;
    private UniCom.Subscriber<bool> subscriber;

	// Use this for initialization
	void Start ()
    {
        subscriber = new UniCom.Subscriber<bool>(Topic,callback);
	}
	
	// Update is called once per frame
	void Update ()
    {
		
	}

    public void callback(bool data)
    {
        Debug.Log(NameSpace + ":" + data);
    }
}

if the topic and it's type is matched, the callback function was called.

Demo

  1. Open SampleScene.Unity and Run

Image Alt Text

About

Pub/Sub Library for Unity.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • C# 100.0%