{"id":16209914,"url":"https://github.com/annulusgames/componentcachegenerator","last_synced_at":"2025-03-02T08:35:02.405Z","repository":{"id":224012770,"uuid":"762137489","full_name":"annulusgames/ComponentCacheGenerator","owner":"annulusgames","description":"A source generator that automatically generates a cache of components for Unity.","archived":false,"fork":false,"pushed_at":"2024-02-23T12:11:37.000Z","size":96,"stargazers_count":33,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-03-02T03:24:15.745Z","etag":null,"topics":["cache","sourcegenerator","unity"],"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/annulusgames.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-02-23T06:49:54.000Z","updated_at":"2024-10-09T16:47:08.000Z","dependencies_parsed_at":"2024-02-23T09:20:15.103Z","dependency_job_id":"17e28624-04a0-485e-8aad-a767f87f2e07","html_url":"https://github.com/annulusgames/ComponentCacheGenerator","commit_stats":null,"previous_names":["annulusgames/componentcachegenerator","yn01dev/componentcachegenerator","yn01-dev/componentcachegenerator"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FComponentCacheGenerator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FComponentCacheGenerator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FComponentCacheGenerator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FComponentCacheGenerator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/annulusgames","download_url":"https://codeload.github.com/annulusgames/ComponentCacheGenerator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241481967,"owners_count":19969833,"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":["cache","sourcegenerator","unity"],"created_at":"2024-10-10T10:34:06.107Z","updated_at":"2025-03-02T08:35:02.377Z","avatar_url":"https://github.com/annulusgames.png","language":"C#","readme":"# ComponentCacheGenerator\n A source generator that automatically generates a cache of components for Unity.\n\n[![license](https://img.shields.io/badge/LICENSE-MIT-green.svg)](LICENSE)\n![unity-version](https://img.shields.io/badge/unity-2022.2+-000.svg)\n[![releases](https://img.shields.io/github/release/AnnulusGames/ComponentCacheGenerator.svg)](https://github.com/AnnulusGames/ComponentCacheGenerator/releases)\n\n[日本語版READMEはこちら](README_JA.md)\n\nComponentCacheGenerator provides automatic generation of component caching code for Unity by generating code to cache `GetComponent\u003cT\u003e()` retrievals using a source generator, reducing the amount of code you need to write.\n\n## Setup\n\n### Requirements\n\n* Unity 2022.2 or later\n\n### Installation\n\n1. Open the Package Manager from Window \u003e Package Manager.\n2. Click the \"+\" button \u003e Add package from git URL.\n3. Enter the following URL:\n\n```\nhttps://github.com/AnnulusGames/ComponentCacheGenerator.git?path=src/ComponentCacheGenerator/Assets/ComponentCacheGenerator\n```\n\nAlternatively, open Packages/manifest.json and add the following to the dependencies block:\n\n```json\n{\n    \"dependencies\": {\n        \"com.annulusgames.component-cache-generator\": \"https://github.com/AnnulusGames/ComponentCacheGenerator.git?path=src/ComponentCacheGenerator/Assets/ComponentCacheGenerator\"\n    }\n}\n```\n\n## Basic Usage\n\nIn Unity, retrieving components with `GetComponent\u003cT\u003e()` is known to be costly, so it's common practice to cache references beforehand in `Awake()` or `Start()`. Additionally, `[RequireComponent(typeof(T))]` is often used to prevent forgetting to add components. While these practices are necessary for performance and maintainability, they can lead to increased code verbosity as the number of components grows.\n\n```cs\nusing UnityEngine;\n\n[RequireComponent(typeof(FooComponent))]\n[RequireComponent(typeof(BarComponent))]\n[RequireComponent(typeof(BazComponent))]\npublic class SomeBehaviour : MonoBehaviour\n{\n    FooComponent fooComponent;\n    BarComponent barComponent;\n    BazComponent bazComponent;\n\n    void Awake()\n    {\n        fooComponent = GetComponent\u003cFooComponent\u003e();\n        barComponent = GetComponent\u003cBarComponent\u003e();\n        bazComponent = GetComponent\u003cBazComponent\u003e();\n    }\n\n    void Update()\n    {\n        fooComponent.Foo();\n        barComponent.Bar();\n        bazComponent.Baz();\n    }\n}\n```\n\nComponentCacheGenerator automatically generates this code using the `[GenerateComponentCache]` attribute.\n\n```cs\nusing UnityEngine;\nusing ComponentCacheGenerator;\n\n[GenerateComponentCache(typeof(FooComponent))]\n[GenerateComponentCache(typeof(BarComponent))]\n[GenerateComponentCache(typeof(BazComponent))]\npublic partial class SomeBehaviour : MonoBehaviour\n{\n    void Update()\n    {\n        fooComponent.Foo();\n        barComponent.Bar();\n        bazComponent.Baz();\n    }\n}\n```\n\nComponentCacheGenerator generates properties to cache each component and a `CacheComponents()` method. If the target class does not have an `Awake()` method, one will be automatically added to the class. (Note: If the target class already has an `Awake()` method, you need to manually call `CacheComponents()`.)\n\n```cs\n// Automatically added if Awake does not exist\nvoid Awake()\n{\n    CacheComponents()\n}\n```\n\nIt is also possible to specify the property name of the generated cache. If not specified, the class name of the target component converted to lower camel case will be used.\n\n```cs\nusing UnityEngine;\nusing ComponentCacheGenerator;\n\n[GenerateComponentCache(typeof(FooComponent), \"foo\")]\n[GenerateComponentCache(typeof(BarComponent), \"bar\")]\n[GenerateComponentCache(typeof(BazComponent), \"baz\")]\npublic partial class SomeBehaviour : MonoBehaviour\n{\n    void Update()\n    {\n        foo.Foo();\n        bar.Bar();\n        baz.Baz();\n    }\n}\n```\n\n## Generation Options\n\nYou can specify generation code settings by specifying values for properties in the `[GenerateComponentCache]` attribute.\n\n| Property | Description |\n| - | - |\n| SearchScope | Specifies the scope to search for components. If multiple are specified, the search will be performed in the order of Self \u003e Children \u003e Parent. (Default is Self) |\n| IsRequired | If IsRequired is true, an exception will be thrown if the component is not found when `CacheComponents()` is called. If the search scope is Self, `[RequireComponent]` attribute will be automatically generated. (Default is true) |\n\n## License\n\n[MIT License](LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fannulusgames%2Fcomponentcachegenerator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fannulusgames%2Fcomponentcachegenerator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fannulusgames%2Fcomponentcachegenerator/lists"}