{"id":14960291,"url":"https://github.com/Danila-Che/FakeMessageBus","last_synced_at":"2025-10-24T18:30:35.638Z","repository":{"id":253544500,"uuid":"843739755","full_name":"Danila-Che/FakeEventBus","owner":"Danila-Che","description":"A minimal event bus for Unity that is easy to use and provides simple navigation through the IDE","archived":false,"fork":false,"pushed_at":"2024-09-12T09:00:57.000Z","size":96,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-10-10T09:42:20.153Z","etag":null,"topics":["bus","event","event-bus","eventbus","unity","unity2d","unity3d"],"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/Danila-Che.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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-08-17T09:17:31.000Z","updated_at":"2024-09-17T05:24:26.000Z","dependencies_parsed_at":"2024-08-17T16:05:18.554Z","dependency_job_id":null,"html_url":"https://github.com/Danila-Che/FakeEventBus","commit_stats":null,"previous_names":["danila-che/fakeeventbus"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danila-Che%2FFakeEventBus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danila-Che%2FFakeEventBus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danila-Che%2FFakeEventBus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Danila-Che%2FFakeEventBus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Danila-Che","download_url":"https://codeload.github.com/Danila-Che/FakeEventBus/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219868213,"owners_count":16555876,"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":["bus","event","event-bus","eventbus","unity","unity2d","unity3d"],"created_at":"2024-09-24T13:21:58.720Z","updated_at":"2025-10-24T18:30:35.629Z","avatar_url":"https://github.com/Danila-Che.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# FakeMessageBus\nA minimal message bus for Unity that is easy to use. FakeMessageBus can form the basis of an message bus or command bus.\n\n## Installation\n\n### Unity Package Manager\n```\nhttps://github.com/Danila-Che/FakeMessageBus.git?path=/Assets/FakeMessageBus\n```\n\n1. In Unity, open **Window** → **Package Manager**.\n2. Press the **+** button, choose \"**Add package from git URL...**\"\n3. Enter url above and press **Add**.\n\n## Usage\nFull code that uses the message bus (any type can be used, such as value types or reference types):\n\n1. Declare a message type.\n\n```csharp\nusing System;\n\npublic class ExampleMessage { ... }\n\npublic struct AthotherExampleMessage { ... }\n```\n\n2. Then simply register/unregister an object with callbacks decorated with the `ObserveMessage` attribute on the message bus.\n\n\u003e The callback method must have only one parameter.\n\n```csharp\nusing FakeMessageBus;\nusing System;\n\npublic class ExampleObserver : IDisposable\n{\n    private MessageBus m_MessageBus;\n\n    public ExampleObserver(MessageBus messageBus)\n    {\n        m_MessageBus = messageBus;\n\n        m_MessageBus.Register(this);\n    }\n\n    public void Dispose()\n    {\n        m_MessageBus.Unregister(this);\n    }\n\n    [ObserveMessage]\n    public void On(ExampleMessage message)\n    {\n        ...\n    }\n\n    [ObserveMessage]\n    public void On(AthotherExampleMessage message)\n    {\n        ...\n    }\n    \n    [ObserveMessage]\n    public void On(int message)\n    {\n        ...\n    }\n    \n    [ObserveMessage]\n    public void On(string message)\n    {\n        ...\n    }\n}\n```\n\n3. At the end, simply send the message using the `Send` method.\n\n```csharp\nusing FakeMessageBus;\n\npublic class ExampleMessageHandler\n{\n    private MessageBus m_MessageBus;\n\n    public OnRaiseMessage()\n    {\n        m_MessageBus.Send(new ExampleMessage(42));\n    }\n}\n```\n\n## MessageBusProxy\n`MessageBusProxy` encapsulates an message bus using the singleton pattern. It has static methods implementing various registration and unregistration strategies for `GameObject`.\n\n### RegisterSingle(GameObject)\n### RegisterObject(GameObject)\n### RegisterRecursive(GameObject)\n\n### UnregisterSingle(GameObject)\n### UnregisterObject(GameObject)\n### UnregisterRecursive(GameObject)\n\nOther static methods:\n### Clear()\n### Notify\u003cT\u003e(T)\n\n## GameObjectSelfRegistration\nInteracts with `MessageBusProxy` to automatically register and unregister with selected strategy (Single, Object, and Recursive). Register `GameObject` with the `OnEnable` callback and uregister `GameObject` with the `OnDisable` callback.\n\n## Dependency injection\n`MessageBus` implements the `IMessageBus` interface. I use the `Reflex` framework to inject `MessageBus`.\n\n```csharp\nusing Reflex.Core;\nusing UnityEngine;\n\npublic class ProjectInstaller : MonoBehaviour, IInstaller\n{\n    public void InstallBindings(ContainerBuilder builder)\n    {\n        builder.AddSingleton(typeof(MessageBus), typeof(IMessageBus));\n    }\n}\n```\n\n```csharp\nusing FakeMessageBus;\nusing Reflex.Core;\n\npublic class ExampleObserver : MonoBehaviour\n{\n    [Inject] private IMessageBus m_MessageBus;\n\n    private void OnEnable()\n    {\n        m_MessageBus.Register(this);\n    }\n\n    private void OnDisable()\n    {\n        m_MessageBus.Unregister(this);\n    }\n    \n    ...\n}\n```\n\n## MessageBus Component\n### Register(object)\nRegister an observer with the `MessageBus` if the observer has valid callbacks. A callback contains only one parameter. The observer will not be registered callback if it contains zero or greater than one parameter.\n#### Exceptions\n`InvalidCallbackException`\nObserver has at least one callback is invalid.\n\n### Unregister(object)\nUnregister an observer from `MessageBus`.\n\n### Send\u003cT\u003e(T)\nRaises an message with the specified arguments.\n#### Parameter\n`messageArgs` T\nThe message args to be sended to all registered observer callback.\n\n### Clear()\nRemoves all callbacks (observers) from the `MessageBus`.\n\n### GetActiveObserverCount\u003cT\u003e()\nGets the number of registered callback for the specified `MessageArgs` type. \n#### Return\nint\nThe number of registered callback\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanila-Che%2FFakeMessageBus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FDanila-Che%2FFakeMessageBus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FDanila-Che%2FFakeMessageBus/lists"}