{"id":20290017,"url":"https://github.com/extrys/lightweightsignalbuses","last_synced_at":"2025-04-11T10:59:12.314Z","repository":{"id":191609770,"uuid":"461220720","full_name":"Extrys/LightWeightSignalBuses","owner":"Extrys","description":"Lightweight type-based messaging system for decoupling your code, includes 2 different workflows, the LightWeight and the Interface Compatible one","archived":false,"fork":false,"pushed_at":"2024-05-23T08:15:43.000Z","size":34,"stargazers_count":5,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T07:23:05.766Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Extrys.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2022-02-19T14:47:34.000Z","updated_at":"2024-07-18T00:36:00.000Z","dependencies_parsed_at":null,"dependency_job_id":"a9f9f9c4-95aa-43b1-8d3b-a3ce0f7e167e","html_url":"https://github.com/Extrys/LightWeightSignalBuses","commit_stats":null,"previous_names":["extrys/lightweightsignalbuses"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Extrys%2FLightWeightSignalBuses","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Extrys%2FLightWeightSignalBuses/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Extrys%2FLightWeightSignalBuses/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Extrys%2FLightWeightSignalBuses/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Extrys","download_url":"https://codeload.github.com/Extrys/LightWeightSignalBuses/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248381704,"owners_count":21094525,"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-11-14T15:05:56.980Z","updated_at":"2025-04-11T10:59:12.292Z","avatar_url":"https://github.com/Extrys.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n# LightWeightSignalBuses\nThese are just a couple of scripts used mainly to use as messaging system, these systems uses types and the variables wrapped on these types\nthis messaging system has been inspired by Zenject SignalBus,and also supports signal interfaces in the same way that the \"AbstractSignals\" feature i added in Zenject/Extenject (see mentioned pull request about Abstract Signals here https://github.com/modesttree/Zenject/pull/91)\n\nAlso comes with a little CompositeDisposable implementation inspired from UniRx/CysharpUnitask.\n\nfast integration and easy to use, perfect for light projects.\n\n\n\nexample for LightWeightSignalBus usage\n```csharp\npublic class Player : MonoBehaviour\n{\n    float hp;\n  \n    void OnPayerDamaged(float damage)\n    {\n        hp-=damage;\n    \n        //We fire a signal in this way\n        SignalBus\u003cSignalPlayerDamaged\u003e.Fire(new SignalPlayerDamaged{playerHp = hp});\n    }\n    \n    void OnPayerHealed(float heal)\n    {\n        hp+=heal;\n        SignalBus\u003cSignalPlayerHealed\u003e.Fire(new SignalPlayerHealed{playerHp = hp});\n    }\n}\n\npublic class HpBar : MonoBehaviour\n{\n    //Needed to dispose the signals when HpBar is destroyed\n    CompositeDisposable disposables = new CompositeDisposable();\n\n    void Start()\n    {\n        //This register the signal so every time each signal is fired it calls ShowHP with its data\n        SignalBus\u003cSignalPlayerDamaged\u003e.Subscribe(x=\u003e ShowHP(x.playerHp)).AddTo(disposables);\n        SignalBus\u003cSignalPlayerHealed\u003e.Subscribe(x=\u003e ShowHP(x.playerHp)).AddTo(disposables);\n    }\n  \n    void ShowHp(float hpToShow)\n    {\n        //Do something to show the hpToShowValue in a ui bar or something\n    }\n    \n    void OnDestroy()\n    {\n        //Ensures que signal is not called anymore when  player gets damage, when the HpBar is destroyed\n        //This is important because if you dont dispose it, after destroying the HpBar, the signal will try to call ShowHP of the Destroyed HpBar\n        //So BOOOM! Errors if you dont do it!\n        disposables.Dispose();\n    }\n}\n\n//The signal struct\npublic struct SignalPlayerDamaged\n{\n    public float playerHp;\n}\npublic struct SignalPlayerHealed\n{\n    public float playerHp;\n}\n```\n\n\nexample for InterfaceCompatibleSignalBus usage\n```csharp\npublic class Player : MonoBehaviour\n{\n    float hp;\n  \n    void OnPayerDamaged(float damage)\n    {\n        hp-=damage;\n    \n        //We fire a signal with their interfaces in this way\n        SignalBus.AbstractFire\u003cSignalPlayerDamaged\u003e(new SignalPlayerDamaged{playerHp = hp});\n    }\n    \n    void OnPayerHealed(float heal)\n    {\n        hp+=heal;\n        //Different signal but with the same interface implementation\n        SignalBus.AbstractFire\u003cSignalPlayerHealed\u003e(new SignalPlayerHealed{playerHp = hp});\n    }\n}\n\npublic class HpBar : MonoBehaviour\n{\n    void Start()\n    {\n        //This register the signal so every time this signal is fired it calls ShowHP with its data;\n        SignalBus\u003cISignalPlayerHpChanged\u003e.Subscribe(x=\u003e ShowHP(x.playerHp))\n    }\n  \n    void ShowHp(float hpToShow)\n    {\n        //Do something to show the hpToShowValue in a ui bar or something\n    }\n}\n\n//The signal types\npublic struct SignalPlayerDamaged : ISignalPlayerHpChanged\n{\n    float ISignalPlayerHpChanged.PlayerHp =\u003e playerHp;\n    public float playerHp;\n}\npublic struct SignalPlayerHealed : ISignalPlayerHpChanged\n{\n    float ISignalPlayerHpChanged.PlayerHp =\u003e playerHp;\n    public float playerHp;\n}\n\n//The interface for the signals\npublic interface ISignalPlayerHpChanged\n{\n    float PlayerHp { get; }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextrys%2Flightweightsignalbuses","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fextrys%2Flightweightsignalbuses","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fextrys%2Flightweightsignalbuses/lists"}