{"id":13786209,"url":"https://github.com/KLab/klab-messagebuses-unity","last_synced_at":"2025-05-11T22:30:43.838Z","repository":{"id":141236441,"uuid":"154222084","full_name":"KLab/klab-messagebuses-unity","owner":"KLab","description":"Message bus library for Unity","archived":false,"fork":false,"pushed_at":"2019-05-09T03:13:15.000Z","size":29,"stargazers_count":40,"open_issues_count":0,"forks_count":3,"subscribers_count":23,"default_branch":"master","last_synced_at":"2024-11-17T22:36:11.682Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/KLab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2018-10-22T21:50:34.000Z","updated_at":"2024-06-30T03:09:06.000Z","dependencies_parsed_at":"2024-01-17T05:14:02.323Z","dependency_job_id":"6c27b378-3258-4c07-a865-65f9fca3e2c0","html_url":"https://github.com/KLab/klab-messagebuses-unity","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KLab%2Fklab-messagebuses-unity","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KLab%2Fklab-messagebuses-unity/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KLab%2Fklab-messagebuses-unity/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/KLab%2Fklab-messagebuses-unity/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/KLab","download_url":"https://codeload.github.com/KLab/klab-messagebuses-unity/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253645092,"owners_count":21941311,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T19:01:11.724Z","updated_at":"2025-05-11T22:30:43.403Z","avatar_url":"https://github.com/KLab.png","language":"C#","readme":"# *KLab Message Buses for Unity*\n\nWhile not silver bullets, message buses (or [event buses as *Lumberyard* calls them](https://docs.aws.amazon.com/lumberyard/latest/userguide/ebus-in-depth.html))\ncan be an effective mechanism for loosen up coupling between systems.\n*KLab Message Buses for Unity* provides a simple API \nfor using buses in *Unity* with low runtime overhead.\n\n\n## Usage\n\nUsing a message bus basically consists of 3 steps.\n\n1. You declare a message bus\n1. You connect to it (and later disconnect from it)\n1. You send messages through the bus\n\nThe below is a minimal example.\n(The example uses *Unity* components for handling connecting and sending,\nbut you can also use message buses in pure *C#* classes).\n\n```cs\nusing KLab.MessageBuses;\nusing UnityEngine;\n\n\npublic sealed class MyMessageBus : MessageBus\u003cstring\u003e {}\n\n\npublic sealed class Sender : MonoBehaviour\n{\n    private const string Message = \"Hello, World!\";\n\n    private MyMessageBus Bus { get; set; }\n\n\n\n    private void Start ()\n    {\n        Bus = MessageBus.GetBus\u003cMyMessageBus\u003e();\n    }\n\n    private void Update ()\n    {\n        Bus.Broadcast(Message);\n    }\n}\n\n\npublic sealed class Receiver : MonoBehaviour\n{\n    private void OnMessage(string message)\n    {\n        Debug.Log(message);\n    }\n\n\n    private void OnEnable()\n    {\n        MessageBus\n            .GetBus\u003cMyMessageBus\u003e()\n            .Connect(OnMessage);\n    }\n\n    private void OnDisable()\n    {\n        MessageBus\n            .GetBus\u003cMyMessageBus\u003e()\n            .Disconnect(OnMessage);\n    }\n}\n```\n\nSee [here](./Runtime/KLab/MessageBuses/MessageBus.cs#L90) for bus types available.\n\n\n### Advanced Usage\n\n#### Setting Initial Container Capacities\n\nYou can set initial capacities of the underlying containers used by a bus\nby decorating the bus with [options](./Runtime/KLab/MessageBuses/MessageBus.cs#L25).\n\n```cs\nusing KLab.MessageBuses;\n\n\n[MessageBusOptions(connectionsCapacity : 1024)]\npublic sealed class MyMessageBus : MessageBus\u003cstring\u003e {}\n```\n\n#### Finding All Connection Propertiess For Later Query\n\nSee [here](./Examples/KLab/MessageBuses/AdvancedExamples.cs#L32).\n\n\n#### Finding All Waive Methods For Later Invokation\n\nSee [here](./Examples/KLab/MessageBuses/AdvancedExamples.cs#L106).\n\n\n#### Creating A Non-global Bus\n\nIf you want to create a non-global message bus,\nsimply instantiate the message bus class directly\ninstead of getting the global singleton through ```MessageBus.GetBus\u003cT\u003e()```.\n\n\n## Unity Import\n\nThe library can be imported easily as a Unity package.\nIt doesn't have any dependencies on other packages.\n\n\n## Changelog\n\nAll notable changes to this project will be documented in this file.\n\nThe format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)\nand this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).\n\n### [1.1.0] - 2019-05-09\n\n#### Added\n\n- Add options for controlling message bus container capacities\n\n#### Changed\n\n- Rename package from `com.klab.messagebuses` to `com.klab.message-buses`\n- Rename runtime *asmdef* from `KLab.MessageBuses` to `KLab.MessageBuses.Runtime`\n\n\n## Feedback\n\n- Request a new feature on GitHub\n- File a bug in GitHub Issues\n\n\n## License\n\nCopyright (c) KLab Inc.. All rights reserved.\n\nLicensed under the [MIT](LICENSE) License.\n","funding_links":[],"categories":["GamePlay","Message Bus"],"sub_categories":["HUD"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKLab%2Fklab-messagebuses-unity","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FKLab%2Fklab-messagebuses-unity","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FKLab%2Fklab-messagebuses-unity/lists"}