{"id":14960682,"url":"https://github.com/joanstinson/unitymessagingsystem","last_synced_at":"2025-10-24T18:32:04.507Z","repository":{"id":63925143,"uuid":"570899154","full_name":"JoanStinson/UnityMessagingSystem","owner":"JoanStinson","description":"A typesafe, lightweight Unity message bus system that respects the Open-Closed principle.","archived":false,"fork":false,"pushed_at":"2022-11-29T00:11:08.000Z","size":138,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":4,"default_branch":"main","last_synced_at":"2024-09-23T11:03:40.088Z","etag":null,"topics":["csharp","message-bus","open-closed-principle","unity-events","unity3d","unity3d-editor","unity3d-plugin"],"latest_commit_sha":null,"homepage":"","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/JoanStinson.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}},"created_at":"2022-11-26T13:49:22.000Z","updated_at":"2024-05-27T16:16:58.000Z","dependencies_parsed_at":"2023-01-14T14:30:30.174Z","dependency_job_id":null,"html_url":"https://github.com/JoanStinson/UnityMessagingSystem","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/JoanStinson%2FUnityMessagingSystem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoanStinson%2FUnityMessagingSystem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoanStinson%2FUnityMessagingSystem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JoanStinson%2FUnityMessagingSystem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JoanStinson","download_url":"https://codeload.github.com/JoanStinson/UnityMessagingSystem/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219867815,"owners_count":16554365,"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":["csharp","message-bus","open-closed-principle","unity-events","unity3d","unity3d-editor","unity3d-plugin"],"created_at":"2024-09-24T13:22:44.842Z","updated_at":"2025-10-24T18:32:03.291Z","avatar_url":"https://github.com/JoanStinson.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Unity Messaging System\nA typesafe, lightweight Unity message bus system that respects the Open-Closed principle.\n\n\u003cp align=\"center\"\u003e\n  \u003ca\u003e\n    \u003cimg alt=\"Made With Unity\" src=\"https://img.shields.io/badge/made%20with-Unity-57b9d3.svg?logo=Unity\"\u003e\n  \u003c/a\u003e\n  \u003ca\u003e\n    \u003cimg alt=\"License\" src=\"https://img.shields.io/github/license/JoanStinson/UnityMessagingSystem?logo=github\"\u003e\n  \u003c/a\u003e\n  \u003ca\u003e\n    \u003cimg alt=\"Last Commit\" src=\"https://img.shields.io/github/last-commit/JoanStinson/UnityMessagingSystem?logo=Mapbox\u0026color=orange\"\u003e\n  \u003c/a\u003e\n  \u003ca\u003e\n    \u003cimg alt=\"Repo Size\" src=\"https://img.shields.io/github/repo-size/JoanStinson/UnityMessagingSystem?logo=VirtualBox\"\u003e\n  \u003c/a\u003e\n  \u003ca\u003e\n    \u003cimg alt=\"Downloads\" src=\"https://img.shields.io/github/downloads/JoanStinson/UnityMessagingSystem/total?color=brightgreen\"\u003e\n  \u003c/a\u003e\n  \u003ca\u003e\n    \u003cimg alt=\"Last Release\" src=\"https://img.shields.io/github/v/release/JoanStinson/UnityMessagingSystem?include_prereleases\u0026logo=Dropbox\u0026color=yellow\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cbr\u003e\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/JoanStinson/UnityMessagingSystem/blob/main/megaphone.PNG\" width=\"30%\" height=\"30%\"\u003e\n\u003c/p\u003e\n\n## 📣 How It Works\nFor starters, import the package located in the [Releases](https://github.com/JoanStinson/UnityMessagingSystem/releases) section into your project.\n\n* ### Step 1 - Write a message. It can be a class or a struct.\n```csharp\npublic readonly struct PlayerSpawnMessage\n{\n    public readonly int Health;\n    public readonly float Speed;\n}\n```\n\u003e \u003cb\u003eStructs\u003c/b\u003e are \u003cb\u003epreferred\u003c/b\u003e to reduce GC work and because messages will 99% of the time only contain data.\n\nIf the message doesn't require data, you can have an empty class or struct too.\n```csharp\npublic readonly struct PlayerDeathMessage { }\n```\n\n* ### Step 2 - Inherit from IMessagingSubscriber\u003c\u003cType\u003e\u003e explicitly defining the message type and subscribe to it. \n```csharp\n    public class MessagingSubscriberExample : MonoBehaviour,\n        IMessagingSubscriber\u003cPlayerSpawnMessage\u003e,\n        IMessagingSubscriber\u003cPlayerDeathMessage\u003e\n    {\n        private void OnEnable()\n        {\n            MessagingSystem.Instance.Subscribe\u003cPlayerSpawnMessage\u003e(this);\n            MessagingSystem.Instance.Subscribe\u003cPlayerDeathMessage\u003e(this);\n        }\n\n        private void OnDisable()\n        {\n            MessagingSystem.Instance.Unsubscribe\u003cPlayerSpawnMessage\u003e(this);\n            MessagingSystem.Instance.Unsubscribe\u003cPlayerDeathMessage\u003e(this);\n        }\n\n        public void OnReceiveMessage(PlayerSpawnMessage message)\n        {\n            Debug.Log(message.ToString());\n        }\n\n        public void OnReceiveMessage(PlayerDeathMessage message)\n        {\n            Debug.Log(\"Received Player Death message\");\n        }\n    }\n```\n\u003e You can make use of the \u003cb\u003eDefaultMessagingSystem singleton\u003c/b\u003e via the \u003cb\u003eInstance\u003c/b\u003e property. Nevertheless, I \u003cb\u003eprefer to inject the dependency\u003c/b\u003e, so that later on I can mock it and do unit tests, apart from having a different messaging system implementation if it where required.\n\n* ### Step 3 - Create a message instance and dispatch it.\n```csharp\npublic class ExampleDispatcherClass : MonoBehaviour\n{\n    private void Update()\n    {\n        if (Input.GetKeyDown(KeyCode.Space))\n        {\n            MessagingSystem.Instance.Dispatch(new PlayerSpawnMessage(3, 5));\n            MessagingSystem.Instance.Dispatch(new PlayerDeathMessage());\n        }\n    }\n}\n```\n\u003e The same as I said before, be sure to have the \u003cb\u003esame instance referenced\u003c/b\u003e. Either by \u003cb\u003einjecting\u003c/b\u003e it via a constructor/initialize method \u003cb\u003eor\u003c/b\u003e making use of the \u003cb\u003esingleton Instance\u003c/b\u003e (although less recommended for obvious reasons, unless you are a beginner).\n\n## 🔍 Unit Tests\nUnit tested with 100% code coverage to be certain the messaging system implementation works properly.\n\u003cp align=\"center\"\u003e\n  \u003cimg src=\"https://github.com/JoanStinson/UnityMessagingSystem/blob/main/tests.PNG\"\u003e\n\u003c/p\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoanstinson%2Funitymessagingsystem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjoanstinson%2Funitymessagingsystem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjoanstinson%2Funitymessagingsystem/lists"}