{"id":13544667,"url":"https://github.com/kyubuns/Kuchen","last_synced_at":"2025-04-02T14:31:45.861Z","repository":{"id":144733003,"uuid":"51754702","full_name":"kyubuns/Kuchen","owner":"kyubuns","description":"Pub/Sub for Unity","archived":false,"fork":false,"pushed_at":"2017-11-22T04:31:23.000Z","size":46,"stargazers_count":34,"open_issues_count":1,"forks_count":6,"subscribers_count":6,"default_branch":"master","last_synced_at":"2024-11-03T11:34:13.491Z","etag":null,"topics":["unity"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kyubuns.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}},"created_at":"2016-02-15T12:42:14.000Z","updated_at":"2024-02-16T04:35:03.000Z","dependencies_parsed_at":"2024-01-19T06:28:38.056Z","dependency_job_id":"7328c6e1-9586-452a-90eb-a84d2f48e965","html_url":"https://github.com/kyubuns/Kuchen","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/kyubuns%2FKuchen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyubuns%2FKuchen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyubuns%2FKuchen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kyubuns%2FKuchen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kyubuns","download_url":"https://codeload.github.com/kyubuns/Kuchen/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246832460,"owners_count":20841169,"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":["unity"],"created_at":"2024-08-01T11:00:52.085Z","updated_at":"2025-04-02T14:31:40.846Z","avatar_url":"https://github.com/kyubuns.png","language":"C#","funding_links":[],"categories":["Unity3d"],"sub_categories":["Miscs"],"readme":"追記: UniRxのMessageBrokerを使いましょう。\n\n===\n\n# Kuchen\n\nPub/Sub Library for Unity\n\n## 使い方\n\n### シンプルに\n\n```C#\nusing UnityEngine;\nusing Kuchen;\n\npublic class SimpleSample : MonoBehaviour\n{\n    void Start()\n    {\n        this.Subscribe(\"SampleTopic\", () =\u003e { Debug.Log(\"baum\") });\n    }\n}\n```\n```C#\nusing UnityEngine;\nusing Kuchen;\n\npublic class SimpleButton : MonoBehaviour\n{\n    void OnClick()\n    {\n        this.Publish(\"SampleTopic\");\n    }\n}\n```\n\n### 引数付き\n\n```C#\nusing UnityEngine;\nusing Kuchen;\n\npublic class WithArgs : MonoBehaviour\n{\n    void Start()\n    {\n        this.Subscribe(\"SampleTopic\", (string message, int number) =\u003e {\n            Debug.LogFormat(\"{0}: {1}\", message, number);\n        });\n\n        this.Publish(\"SampleTopic\", \"test message\", 611);\n    }\n}\n```\n\n### コルーチンで\n\n```C#\nusing System.Collections;\nusing UnityEngine;\nusing Kuchen;\n\npublic class KuchenCoroutineSample : MonoBehaviour\n{\n    public IEnumerator Start()\n    {\n        Debug.Log(\"SampleTopicが送信されるまで待つよ。\");\n        yield return this.WaitForMessage(\"SampleTopic\");\n        Debug.Log(\"SampleTopicが呼ばれたよ！\");\n    }\n}\n```\n\n### ワイルドカード\n\n```C#\nusing UnityEngine;\nusing Kuchen;\n\npublic class Wildcard : MonoBehaviour\n{\n    void Start()\n    {\n        this.SubscribeWithTopic(\"Topic.*\", (topic) =\u003e { Debug.Log(topic); });\n\n        this.Publish(\"Topic.Hoge\");\n        this.Publish(\"Topic.Fuga\");\n    }\n}\n```\n\n### 複数トピック\n\n```C#\nusing UnityEngine;\nusing Kuchen;\n\npublic class Multiple : MonoBehaviour\n{\n    void Start()\n    {\n        this.SubscribeWithTopic(new string[]{\"Topic.Hoge\", \"Topic.Fuga\"}, (topic) =\u003e { Debug.Log(topic); });\n\n        this.Publish(\"Topic.Hoge\");\n        this.Publish(\"Topic.Fuga\");\n    }\n}\n```\n\n### SubscribeOnce\n\n```C#\nusing UnityEngine;\nusing Kuchen;\n\npublic class SubscribeOnce : MonoBehaviour\n{\n    void Start()\n    {\n        this.Subscribe(\"SampleTopic\", () =\u003e { Debug.Log(\"!\"); }).Once();\n\n        this.Publish(\"SampleTopic\");\n        this.Publish(\"SampleTopic\"); // 2回目は呼び出されない\n    }\n}\n```\n\n### SubscribeAndStartCoroutine\n\n```C#\nusing System.Collections;\nusing UnityEngine;\nusing Kuchen;\n\npublic class SubscribeAndStartCoroutine : MonoBehaviour\n{\n    void Start()\n    {\n        this.SubscribeAndStartCoroutine(\"SampleTopic\", Coroutine);\n        this.Publish(\"SampleTopic\");\n    }\n\n    IEnumerator Coroutine()\n    {\n        yield return null;\n    }\n}\n```\n\n### Mute\n\n```C#\nusing System.Collections;\nusing UnityEngine;\nusing Kuchen;\n\npublic class SubscribeWithCoroutine : MonoBehaviour\n{\n    void Start()\n    {\n        this.SubscribeWithCoroutine(\"SampleTopic\", () =\u003e { Debug.Log(\"!\"); });\n\n        this.Publish(\"SampleTopic\");\n\n        this.Mute(\"SampleTopic\");\n        this.Publish(\"SampleTopic\"); // Muteしてる間は呼ばれない\n        this.Unmute(\"SampleTopic\");\n\n        this.Publish(\"SampleTopic\");\n    }\n}\n```\n\n### GameObject無し\n\n```C#\nusing Kuchen;\n\npublic class NonGameObject\n{\n\tvoid SubscribeTest()\n\t{\n\t\tusing(var subscriber = new Subscriber())\n\t\t{\n\t\t\tsubscriber.Subscribe(\"SampleTopic\", () =\u003e { /* hoge */ });\n\t\t\tPublisher.Publish(\"SampleTopic\");\n\t\t}\n\t}\n}\n```\n\n\n## Special Thanks\n\n* Y.O.\n* MiniRegex(@kimika127)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyubuns%2FKuchen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkyubuns%2FKuchen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkyubuns%2FKuchen/lists"}