{"id":16210366,"url":"https://github.com/sandrofigo/simple-code-generator-unity3d","last_synced_at":"2025-04-02T19:33:26.461Z","repository":{"id":188442281,"uuid":"678737480","full_name":"sandrofigo/Simple-Code-Generator-Unity3D","owner":"sandrofigo","description":"A library for generating source code from templates in Unity","archived":false,"fork":false,"pushed_at":"2024-11-17T21:55:28.000Z","size":113,"stargazers_count":5,"open_issues_count":3,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-17T13:05:32.035Z","etag":null,"topics":["code-generator","generator","parser","template","unity","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/sandrofigo.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":"2023-08-15T08:54:38.000Z","updated_at":"2025-03-06T12:57:27.000Z","dependencies_parsed_at":"2024-02-06T15:53:03.406Z","dependency_job_id":null,"html_url":"https://github.com/sandrofigo/Simple-Code-Generator-Unity3D","commit_stats":null,"previous_names":["sandrofigo/simple-code-generator-unity3d"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandrofigo%2FSimple-Code-Generator-Unity3D","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandrofigo%2FSimple-Code-Generator-Unity3D/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandrofigo%2FSimple-Code-Generator-Unity3D/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sandrofigo%2FSimple-Code-Generator-Unity3D/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sandrofigo","download_url":"https://codeload.github.com/sandrofigo/Simple-Code-Generator-Unity3D/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246880457,"owners_count":20848863,"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":["code-generator","generator","parser","template","unity","unity3d"],"created_at":"2024-10-10T10:37:40.253Z","updated_at":"2025-04-02T19:33:21.449Z","avatar_url":"https://github.com/sandrofigo.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Simple Code Generator\n\n[![openupm](https://img.shields.io/npm/v/com.sandrofigo.simplecodegenerator?label=openupm\u0026registry_uri=https://package.openupm.com)](https://openupm.com/packages/com.sandrofigo.simplecodegenerator/)\n[![tests](https://github.com/sandrofigo/Simple-Code-Generator-Unity3D/actions/workflows/tests.yml/badge.svg)](https://github.com/sandrofigo/Simple-Code-Generator-Unity3D/actions/workflows/tests.yml)\n\nA library for generating source code from templates in Unity\n\n---\n\n## Installation\n\n- Install [OpenUPM CLI](https://github.com/openupm/openupm-cli#installation)\n- Run the following command in your Unity project folder\n\n  ```\n  openupm add com.sandrofigo.simplecodegenerator\n  ```\n\n## Usage\n\nCreate a `public static void` method in a class anywhere in your Unity project and decorate it with the `[CodeGenerationMethod]` attribute. This will make the method visible to the code generator.\n\nIf you want to expose the method to the \"Code Generation\" menu add a `[MenuItem(...)]` attribute.\n\n```csharp\npublic static class MyClass\n{\n    [CodeGenerationMethod]\n    [MenuItem(\"Code Generation/Generate My Code\")]\n    public static void GenerateMyCode()\n    {\n        var data = new\n        {\n            Text = \"Hello World!\",\n            Colors = new[] { \"Red\", \"Green\", \"Blue\" },\n            Animal = new\n            {\n                Type = \"fox\",\n                Color = \"brown\",\n            }\n        };\n\n        CodeGenerator.GenerateFromTemplate(\"Scripts/Templates/MyTemplate.txt\", \"Scripts/Generated/MyTemplate.generated.cs\", data);\n    }\n}\n```\n\nAdditionally you need a template file e.g. `MyTemplate.txt` in your project which the code generator can use.\n\n```\n// This is a sample template\n\n// The value of the property \"Text\" is: {{ Text }}\n\n// The quick {{ Animal.Color }} {{ Animal.Type }} jumps over the lazy dog\n\n{{ for color in Colors }}\n\npublic class My{{ color }}Class\n{\n    // Some implementation\n}\n\n{{ end }}\n```\n\nValue names are case sensitive e.g. if you want to insert the value of the `data.Text` property from the data object you can do this by surrounding it with `{{  }}`. Accessing nested properties is the same as in C# e.g. `Animal.Color`.\n\nThe generated file `MyTemplate.generated.cs` from this example will look like this:\n\n```csharp\n// This is a sample template\n\n// The value of the property \"Text\" is: Hello World!\n\n// The quick brown fox jumps over the lazy dog\n\n\npublic class MyRedClass\n{\n    // Some implementation\n}\n\n\npublic class MyGreenClass\n{\n    // Some implementation\n}\n\n\npublic class MyBlueClass\n{\n    // Some implementation\n}\n\n```\n\nCode generation is automatically triggered when a `*.cs`, `*.txt` or `*.json` file has changed in your project. Additionally you can trigger the code generation manually under the \"Code Generation\" menu item.\n\n## Community\n\nSupport this project with a ⭐️, report an issue or if you feel adventurous and would like to extend the functionality open a pull request.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandrofigo%2Fsimple-code-generator-unity3d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsandrofigo%2Fsimple-code-generator-unity3d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsandrofigo%2Fsimple-code-generator-unity3d/lists"}