{"id":16209199,"url":"https://github.com/gilzoide/unity-playerloophelper","last_synced_at":"2025-10-28T23:31:56.431Z","repository":{"id":70590865,"uuid":"415384887","full_name":"gilzoide/unity-playerloophelper","owner":"gilzoide","description":"Single file helper class for registering/unregistering systems in Unity's PlayerLoop. ","archived":false,"fork":false,"pushed_at":"2021-10-16T07:46:14.000Z","size":19,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2024-12-21T11:09:40.665Z","etag":null,"topics":["package","playerloop","unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"unlicense","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gilzoide.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":"2021-10-09T18:02:47.000Z","updated_at":"2024-11-29T19:03:00.000Z","dependencies_parsed_at":"2023-04-25T22:01:07.840Z","dependency_job_id":null,"html_url":"https://github.com/gilzoide/unity-playerloophelper","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-playerloophelper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-playerloophelper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-playerloophelper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gilzoide%2Funity-playerloophelper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gilzoide","download_url":"https://codeload.github.com/gilzoide/unity-playerloophelper/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":238741412,"owners_count":19522776,"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":["package","playerloop","unity"],"created_at":"2024-10-10T10:28:35.663Z","updated_at":"2025-10-28T23:31:51.125Z","avatar_url":"https://github.com/gilzoide.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# PlayerLoopHelper\nSingle file helper class for registering/unregistering systems in [Unity](https://unity.com/)'s\n[PlayerLoop](https://docs.unity3d.com/ScriptReference/LowLevel.PlayerLoop.html).\n\n\n## How to install\nEither:\n\n- In the [Package Manager Window](https://docs.unity3d.com/Manual/upm-ui.html),\n  install using this repository's [Git URL](https://docs.unity3d.com/Manual/upm-ui-giturl.html):\u003cbr/\u003e\n  `https://github.com/gilzoide/unity-playerloophelper.git`\n- Copy the [PlayerLoopHelper.cs](Runtime/PlayerLoopHelper.cs) file anywhere inside your project.\n\n\n## Usage example\n```cs\nusing System;\nusing System.Collections.Concurrent;\nusing PlayerLoopHelper;\n\n// Class for scheduling tasks that will run in Unity's Main Thread.\n// \n// Using a PlayerLoopSystem avoids needing a living singleton GameObject\n// with a MonoBehaviour that overrides `Update`, which is the usual way\n// of implementing such functionality in Unity.\n//\n// Usage:\n//     MainThreadDispatcher.Dispatch(() =\u003e\n//     {\n//         Debug.Log(\"Some action that runs on Unity's Main Thread\"));\n//     }\npublic static class MainThreadDispatcher\n{\n    static readonly ConcurrentQueue\u003cAction\u003e _taskQueue;\n    static MainThreadDispatcher()\n    {\n        _taskQueue = new ConcurrentQueue\u003cAction\u003e();\n        Enable(); \n    }\n\n    public static bool Enable()\n    {\n        return PlayerLoopSystemHelper.Register(\n            // PlayerLoop systems are identified by their Type\n            typeof(MainThreadDispatcher),\n            // \"FirstChildOf Update\": this system will run as the first step\n            // in the Update phase, before other components\n            // For more phases, check out UnityEngine.PlayerLoop subclasses\n            // (e.g.: https://docs.unity3d.com/ScriptReference/PlayerLoop.Update.html)\n            InsertPosition.FirstChildOf,\n            typeof(UnityEngine.PlayerLoop.Update),\n            // Callback that will run once per frame\n            UpdateCallback\n        );\n    }\n\n    public static bool Disable()\n    {\n        return PlayerLoopSystemHelper.Unregister(typeof(MainThreadDispatcher));\n    }\n\n    public static void Dispatch(Action action)\n    {\n        _taskQueue.Enqueue(action);\n    }\n\n    static void UpdateCallback()\n    {\n        while (_taskQueue.TryDequeue(out Action task))\n        {\n            task();\n        }\n    }\n}\n```\n\n\n## API\n`enum InsertPosition`\n  - `Before`: insert new system before specified one, as its sibling\n  - `After`: insert new system after specified one, as its sibling\n  - `FirstChildOf`: insert new system as the first child of specified one\n  - `LastChildOf`: insert new system as the last child of specified one\n\n`class PlayerLoopSystemHelper`\n  - `static bool Register(Type type, InsertPosition position, Type anchorType, PlayerLoopSystem.UpdateFunction action)`\n\n    Registers a `PlayerLoopSystem` with the given `type` and `action` in\n    the specified `position` relative to `anchorType`.\n\n    Returns whether `anchorType` was found and system was inserted successfully.\n\n  - `static bool Unregister(Type type)`\n\n    Unregisters a `PlayerLoopSystem`.\n\n    Returns whether `type` was found and removed successfully.\n\n  - `static bool IsRegistered(Type type)`\n\n    Returns whether a `PlayerLoopSystem` with `type` is registered.\n\n\n## Other projects for injecting callbacks in Unity's PlayerLoop\n- https://github.com/Refsa/PlayerLoopInjector\n- https://github.com/sotanmochi/PlayerLooper","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Funity-playerloophelper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgilzoide%2Funity-playerloophelper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgilzoide%2Funity-playerloophelper/lists"}