{"id":14960905,"url":"https://github.com/intothedev/signals","last_synced_at":"2025-10-24T19:30:31.693Z","repository":{"id":109559063,"uuid":"205546046","full_name":"IntoTheDev/Signals","owner":"IntoTheDev","description":"Lightweight type-safe messaging system","archived":false,"fork":false,"pushed_at":"2021-10-09T20:41:37.000Z","size":138,"stargazers_count":55,"open_issues_count":0,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-10-10T10:24:09.203Z","etag":null,"topics":["events","signals","unity","unity-scripts","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/IntoTheDev.png","metadata":{"files":{"readme":"README.md","changelog":"Changelog.md","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":"2019-08-31T13:10:19.000Z","updated_at":"2024-05-17T16:31:19.000Z","dependencies_parsed_at":"2023-07-28T16:46:09.092Z","dependency_job_id":null,"html_url":"https://github.com/IntoTheDev/Signals","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntoTheDev%2FSignals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntoTheDev%2FSignals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntoTheDev%2FSignals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/IntoTheDev%2FSignals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/IntoTheDev","download_url":"https://codeload.github.com/IntoTheDev/Signals/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219868063,"owners_count":16555878,"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":["events","signals","unity","unity-scripts","unity2d","unity3d"],"created_at":"2024-09-24T13:23:24.162Z","updated_at":"2025-10-24T19:30:31.327Z","avatar_url":"https://github.com/IntoTheDev.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Signals\n\n### TODO\n- [ ] Abstract signals\n\nUpdate: With my current knowledge I can't implement it without huge performance loss\n\n## Features\n- Type-safe\n- Very fast in terms of performance\n- Allows you to get last dispatched signal\n\n## How to Install\n### Git Installation (Best way to get latest version)\n\nIf you have Git on your computer, you can open Package Manager indside Unity, select \"Add package from Git url...\", and paste link ```https://github.com/IntoTheDev/Signals.git```\n\nor\n\nOpen the manifest.json file of your Unity project.\nAdd ```\"com.intothedev.signals\": \"https://github.com/IntoTheDev/Signals.git\"```\n\n### Manual Installation (Version can be outdated)\nDownload latest package from the Release section.\nImport Signals.unitypackage to your Unity Project\n\n## Usage\n\n### How to create a signal\n\nCreate a plain C# class or struct. I prefer to use readonly structs.\n\n```csharp\npublic readonly struct PlayerCreated\n{\n\tpublic readonly string Name;\n\tpublic readonly GameObject StartWeapon;\n\n\tpublic PlayerCreated(string name, GameObject startWeapon)\n\t{\n\t\tName = name;\n\t\tStartWeapon = startWeapon;\n\t}\n}\n```\n\n### How to send a signal\n\nYou need to call `Signal\u003cS\u003e.Dispatch(new S())`. Instead of `S` you need to pass in type of your signal.\n\n```csharp\npublic class Player : MonoBehaviour\n{\n\t[SerializeField] private string _name = \"\";\n\t[SerializeField] private GameObject _weapon = null;\n\n\tprivate void Start()\n\t{\n\t\tSignal\u003cPlayerCreated\u003e.Dispatch(new PlayerCreated(_name, _weapon));\n\t}\n}\n```\n\n### How to receive a signal\n\nYour class/struct must implement `IReceiver\u003cS\u003e` interface. Instead of `S` you need to pass in type of your signal.\n\n```csharp\npublic class PlayerUI : MonoBehaviour, IReceiver\u003cPlayerCreated\u003e\n{\n\t[SerializeField] private TMP_Text _playerName = null;\n\t[SerializeField] private Image _weaponIcon = null;\n\n\tprivate void Awake()\n    \t{\n\t\t// You can get last dispatched signal like this\n\t\t// This is useful if for example UI was created later then the player\n\t\tif (Signal\u003cPlayerCreated\u003e.TryGetLast(out var last))\n        \t\tReceive(last);\n    \t}\n\n\tprivate void OnEnable()\n\t{\n\t\t// Subscribing to signal\n\t\tSignal\u003cPlayerCreated\u003e.AddReceiver(this);\n\t}\n\n\tprivate void OnDisable()\n\t{\n\t\t// Unsubscribing from signal\n\t\tSignal\u003cPlayerCreated\u003e.RemoveReceiver(this);\n\t}\n\n\t// Receiving the signal\n\tpublic void Receive(in PlayerCreated value)\n\t{\n\t\t_playerName.text = value.Name;\n\t\t_weaponIcon.sprite = value.StartWeapon.GetComponent\u003cWeapon\u003e().Icon;\n\t}\n}\n```\n\n### UnityEvent\n\nCreate a class that inherits from `Listener\u003cSignalType\u003e` and attach it to any game object you want. Now you can invoke UnityEvent to corresponding Signal.\n\n```csharp\npublic class PlayerCreatedListener : Listener\u003cPlayerCreated\u003e { }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintothedev%2Fsignals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fintothedev%2Fsignals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fintothedev%2Fsignals/lists"}