{"id":16209908,"url":"https://github.com/annulusgames/unitycodegen","last_synced_at":"2025-10-15T19:59:47.813Z","repository":{"id":157192419,"uuid":"625460835","full_name":"annulusgames/UnityCodeGen","owner":"annulusgames","description":"Code Generation Library for Unity Editor","archived":false,"fork":false,"pushed_at":"2023-04-09T12:16:19.000Z","size":1226,"stargazers_count":159,"open_issues_count":0,"forks_count":24,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-04-29T06:33:49.257Z","etag":null,"topics":["codegenerator","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}},"created_at":"2023-04-09T07:10:16.000Z","updated_at":"2025-04-18T02:57:29.000Z","dependencies_parsed_at":"2024-01-13T23:17:33.033Z","dependency_job_id":"9f7d2f3d-ae88-4803-8f9e-ea7ec224782a","html_url":"https://github.com/annulusgames/UnityCodeGen","commit_stats":null,"previous_names":["yn01dev/unitycodegen","yn01-dev/unitycodegen","annulusgames/unitycodegen","nuskey8/unitycodegen"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/annulusgames/UnityCodeGen","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FUnityCodeGen","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FUnityCodeGen/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FUnityCodeGen/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FUnityCodeGen/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/annulusgames","download_url":"https://codeload.github.com/annulusgames/UnityCodeGen/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/annulusgames%2FUnityCodeGen/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279110365,"owners_count":26105906,"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","status":"online","status_checked_at":"2025-10-15T02:00:07.814Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["codegenerator","unity"],"created_at":"2024-10-10T10:33:58.474Z","updated_at":"2025-10-15T19:59:47.780Z","avatar_url":"https://github.com/annulusgames.png","language":"C#","readme":"# Unity CodeGen\nCode Generation Library for Unity Editor\n\n\u003cimg src=\"https://github.com/AnnulusGames/UnityCodeGen/blob/main/Assets/UnityCodeGen/Documentation~/Header.png\" width=\"800\"\u003e\n\n[![license](https://img.shields.io/badge/LICENSE-MIT-green.svg)](LICENSE)\n\n[日本語版READMEはこちら](README_JP.md)\n\n## Overview\nUnity CodeGen is a library that streamlines code generation on the Unity editor.\nBy defining your own Generator that inherits from ICodeGenerator, you can generate codeautomatically.\n\n### Features\n* Code generation can be implemented smoothly\n* Code can be generated automatically when compiling\n\n## Setup\n\n### Requirement\n* Unity 2020.1 or higher\n\n### Install\n1. Open the Package Manager from Window \u003e Package Manager\n2. \"+\" button \u003e Add package from git URL\n3. Enter the following to install\n   * https://github.com/AnnulusGames/UnityCodeGen.git?path=/Assets/UnityCodeGen\n\n\nor open Packages/manifest.json and add the following to the dependencies block.\n\n```json\n{\n    \"dependencies\": {\n        \"com.annulusgames.unity-codegen\": \"https://github.com/AnnulusGames/UnityCodeGen.git?path=/Assets/UnityCodeGen\"\n    }\n}\n```\n\n## Usage\nCreate a .cs file under any Editor folder and implement a class that inherits ICodeGenerator.\nBelow is a Generator that generates an empty Sample class.\n\n```cs\nusing UnityCodeGen;\n\n[Generator] // Add GeneratorAttribute\npublic class SampleGenerator : ICodeGenerator // Inherits ICodeGenerator\n{\n    public void Execute(GeneratorContext context) // Implement Execute method\n    {\n        context.AddCode(\"Sample.Generated.cs\", // File name\n@\"// \u003cauto-generated/\u003e\nnamespace SampleNamespace.Generated\n{\n    public class Sample\n    {\n\n    }\n}\"\n        );\n    }\n}\n```\n\nBack in the editor, select Tools/UnityCodeGen/Generate to generate code.\n\n\u003cimg src=\"https://github.com/AnnulusGames/UnityCodeGen/blob/main/Assets/UnityCodeGen/Documentation~/img1.png\" width=\"400\"\u003e\n\nGenerated code is placed in Assets/UnityCodeGen.Generated.\n\n```cs\n// \u003cauto-generated/\u003e\nnamespace SampleNamespace.Generated\n{\n    public class Sample\n    {\n\n    }\n}\n```\n\n## Specify Output Path\nBy using GeneratorContext.OverrideFolderPath, you can specify the output folder path.\n\n```cs\npublic void Execute(GeneratorContext context)\n{\n    context.OverrideFolderPath(\"Assets/YourFolder/Generated\");\n    ...\n}\n```\n\n## Auto-generate on Compile\nIt is possible to automate code generation by checking Tools/UnityCodeGen/Auto-generate on Compile.\n\n\u003cimg src=\"https://github.com/AnnulusGames/UnityCodeGen/blob/main/Assets/UnityCodeGen/Documentation~/img2.png\" width=\"400\"\u003e\n\nWhen Auto-generate on Compile is on, it will be automatically generated at the end of compilation and will be recompiled only if there is any change in the generated code.\n\n## Unity Code Gen Utility\nBy using the UnityCodeGenUtility class, it is also possible to operate from your script.\n\n``` cs\n// get default output folder path\nvar path = UnityCodeGenUtility.defaultFolderPath;\n\n// run generation\nUnityCodeGenUtility.Generate();\n```\n\n## Advanced\n\n### Perform processing on classes with specific attributes added\nBy using Unity's TypeCache, classes with specific attributes can be retrieved all at once.\nThis allows you to generate code for classes with specific attributes.\n\nAs an example, let's generate code that overrides ToString to display all public fields for a class with the AddToStringAttribute.\n\nFirst, define the attributes used to identify the Generator.\n\n```cs\nusing System;\n\npublic class AddToStringAttribute : Attribute { }\n```\n\nNext, create a Generator. Note that this file should be placed under any Editor folder.\n\n```cs\nusing System.Linq;\nusing UnityEditor;\nusing UnityCodeGen;\n\n[Generator]\npublic class AddToStringGenerator : ICodeGenerator\n{\n    public void Execute(GeneratorContext context)\n    {\n        var types = TypeCache.GetTypesWithAttribute\u003cAddToStringAttribute\u003e();\n        foreach (var t in types)\n        {\n            var publicFields = t.GetFields()\n                .Where(x =\u003e x.IsPublic \u0026\u0026 !x.IsStatic)\n                .Select(x =\u003e $\"{x.Name}:{{{x.Name}}}\");\n\n            var toString = string.Join(\", \", publicFields);\n            var code = \n$@\"// \u003cauto-generated/\u003e\npartial class {t.Name}\n{{\n    public override string ToString()\n    {{\n        return $\"\"{toString}\"\";\n    }}\n}}\";\n            context.AddCode($\"{t.FullName}.AddToString.Generated.cs\", code);\n        }\n    }\n}\n```\n\nYou are now ready to generate.\nCreate a class and add AddToStringAttribute.\n\n```cs\nusing UnityEngine;\n\n[AddToString]\npublic partial class FooClass\n{\n    public int foo;\n    public string bar;\n    public Vector3 baz;\n}\n```\n\nExecuting Generate will generate FooClass.AddToString.Generated.cs under the UnityCodeGen.Generated folder.\n\n```cs\n// \u003cauto-generated/\u003e\npartial class FooClass\n{\n    public override string ToString()\n    {\n        return $\"foo:{foo}, bar:{bar}, baz:{baz}\";\n    }\n}\n```\n\n## Samples\n\n\u003cimg src=\"https://github.com/AnnulusGames/UnityCodeGen/blob/main/Assets/UnityCodeGen/Documentation~/img3.png\" width=\"400\"\u003e\n\nUnity CodeGen samples are available from the Package Manager.\nBelow is a list of samples included in the package.\n\n|  Sample Name  |  Description  |\n| ---------- | ------ |\n|  Tags \u0026 Layers |  A sample that generates a class that manages Tags, Layers and Sorting Layers with constants. |\n\n\n## License\n\n[MIT License](LICENSE)","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fannulusgames%2Funitycodegen","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fannulusgames%2Funitycodegen","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fannulusgames%2Funitycodegen/lists"}