├── .gitattributes
├── .github
└── workflows
│ ├── activation.yml
│ └── main.yml
├── .gitignore
├── .releaserc.json
├── .unitypackageignore
├── CHANGELOG.md
├── CHANGELOG.md.meta
├── Documentation~
├── favicon.ico
├── header.png
├── index.md
├── logo.svg
├── manual
│ ├── contributing.md
│ ├── data-binding.md
│ ├── getting-started.md
│ └── toc.yml
├── scripts
│ ├── file-utils.patch
│ ├── generate-docs.ps1
│ ├── generate-docs.sh
│ ├── lib-visibility.patch
│ └── update-engine.ps1
└── toc.yml
├── Editor.meta
├── Editor
├── EditorExtensions.cs
├── EditorExtensions.cs.meta
├── EditorUtils.cs
├── EditorUtils.cs.meta
├── FasterGames.T4.Editor.asmdef
├── FasterGames.T4.Editor.asmdef.meta
├── ImporterVersion.cs
├── ImporterVersion.cs.meta
├── ReflectionUtils.cs
├── ReflectionUtils.cs.meta
├── TextTemplateImporter.cs
├── TextTemplateImporter.cs.meta
├── TextTemplateImporterEditor.cs
├── TextTemplateImporterEditor.cs.meta
├── TextTemplateIncludeImporter.cs
├── TextTemplateIncludeImporter.cs.meta
├── TextTemplating.meta
├── TextTemplating
│ ├── Microsoft.VisualStudio.TextTemplating.meta
│ ├── Microsoft.VisualStudio.TextTemplating
│ │ ├── DirectiveProcessor.cs
│ │ ├── DirectiveProcessor.cs.meta
│ │ ├── DirectiveProcessorException.cs
│ │ ├── DirectiveProcessorException.cs.meta
│ │ ├── EncodingHelper.cs
│ │ ├── EncodingHelper.cs.meta
│ │ ├── Engine.cs
│ │ ├── Engine.cs.meta
│ │ ├── Interfaces.cs
│ │ ├── Interfaces.cs.meta
│ │ ├── ParameterDirectiveProcessor.cs
│ │ ├── ParameterDirectiveProcessor.cs.meta
│ │ ├── RequiresProvidesDirectiveProcessor.cs
│ │ ├── RequiresProvidesDirectiveProcessor.cs.meta
│ │ ├── TextTemplatingSession.cs
│ │ ├── TextTemplatingSession.cs.meta
│ │ ├── TextTransformation.cs
│ │ ├── TextTransformation.cs.meta
│ │ ├── ToStringHelper.cs
│ │ └── ToStringHelper.cs.meta
│ ├── Mono.TextTemplating.CodeCompilation.meta
│ ├── Mono.TextTemplating.CodeCompilation
│ │ ├── CodeCompiler.cs
│ │ ├── CodeCompiler.cs.meta
│ │ ├── CodeCompilerArguments.cs
│ │ ├── CodeCompilerArguments.cs.meta
│ │ ├── CodeCompilerResult.cs
│ │ ├── CodeCompilerResult.cs.meta
│ │ ├── CscCodeCompiler.cs
│ │ ├── CscCodeCompiler.cs.meta
│ │ ├── MSBuildErrorParser.cs
│ │ ├── MSBuildErrorParser.cs.meta
│ │ ├── ProcessUtils.cs
│ │ ├── ProcessUtils.cs.meta
│ │ ├── RuntimeInfo.cs
│ │ └── RuntimeInfo.cs.meta
│ ├── Mono.TextTemplating.meta
│ └── Mono.TextTemplating
│ │ ├── CompiledTemplate.cs
│ │ ├── CompiledTemplate.cs.meta
│ │ ├── CrossAppDomainAssemblyResolver.cs
│ │ ├── CrossAppDomainAssemblyResolver.cs.meta
│ │ ├── FileUtil.cs
│ │ ├── FileUtil.cs.meta
│ │ ├── ParsedTemplate.cs
│ │ ├── ParsedTemplate.cs.meta
│ │ ├── RecyclableAppDomain.cs
│ │ ├── RecyclableAppDomain.cs.meta
│ │ ├── StringUtil.cs
│ │ ├── StringUtil.cs.meta
│ │ ├── TemplateGenerator.cs
│ │ ├── TemplateGenerator.cs.meta
│ │ ├── TemplateSettings.cs
│ │ ├── TemplateSettings.cs.meta
│ │ ├── TemplatingEngine.cs
│ │ ├── TemplatingEngine.cs.meta
│ │ ├── Tokeniser.cs
│ │ ├── Tokeniser.cs.meta
│ │ ├── Utf8.cs
│ │ └── Utf8.cs.meta
├── UnityDataHost.cs
└── UnityDataHost.cs.meta
├── LICENSE.md
├── LICENSE.md.meta
├── README.md
├── README.md.meta
├── Runtime.meta
├── Runtime
├── FasterGames.T4.Runtime.asmdef
├── FasterGames.T4.Runtime.asmdef.meta
├── IDataHost.cs
└── IDataHost.cs.meta
├── Samples~
└── .gitkeep
├── Tests.meta
├── Tests
├── Editor.meta
└── Editor
│ ├── EditorTestRuntime.meta
│ ├── EditorTestRuntime
│ ├── Data.cs
│ ├── Data.cs.meta
│ ├── FasterGames.T4.Editor.Tests.EditorTestRuntime.asmdef
│ └── FasterGames.T4.Editor.Tests.EditorTestRuntime.asmdef.meta
│ ├── Example.cs
│ ├── Example.cs.meta
│ ├── Example.tt
│ ├── Example.tt.meta
│ ├── FasterGames.T4.Editor.Tests.asmdef
│ ├── FasterGames.T4.Editor.Tests.asmdef.meta
│ ├── TextTemplating.meta
│ ├── TextTemplating
│ ├── DummyHost.cs
│ ├── DummyHost.cs.meta
│ ├── EngineTests.cs
│ ├── EngineTests.cs.meta
│ ├── GenerateIndentedClassCodeTests.cs
│ ├── GenerateIndentedClassCodeTests.cs.meta
│ ├── GenerationTests.cs
│ ├── GenerationTests.cs.meta
│ ├── ParsingTests.cs
│ ├── ParsingTests.cs.meta
│ ├── TemplateEnginePreprocessTemplateTests.cs
│ ├── TemplateEnginePreprocessTemplateTests.cs.meta
│ ├── TemplatingEngineHelper.cs
│ ├── TemplatingEngineHelper.cs.meta
│ ├── TextTemplatingSessionTests.cs
│ └── TextTemplatingSessionTests.cs.meta
│ ├── exampleData.asset
│ └── exampleData.asset.meta
├── Third Party Notices.md
├── Third Party Notices.md.meta
├── docfx.json
├── docfx.json.meta
├── package.json
└── package.json.meta
/.gitattributes:
--------------------------------------------------------------------------------
1 | * text=auto eol=lf
2 | *.anim merge=unityyamlmerge eol=lf
3 | *.asset merge=unityyamlmerge eol=lf
4 | *.controller merge=unityyamlmerge eol=lf
5 | *.mat merge=unityyamlmerge eol=lf
6 | *.meta merge=unityyamlmerge eol=lf
7 | *.physicsMaterial merge=unityyamlmerge eol=lf
8 | *.physicsMaterial2D merge=unityyamlmerge eol=lf
9 | *.prefab merge=unityyamlmerge eol=lf
10 | *.unity merge=unityyamlmerge eol=lf
11 |
--------------------------------------------------------------------------------
/.github/workflows/activation.yml:
--------------------------------------------------------------------------------
1 | name: Acquire activation file
2 | on:
3 | workflow_dispatch: {}
4 | jobs:
5 | activation:
6 | name: Request manual activation file 🔑
7 | runs-on: ubuntu-latest
8 | steps:
9 | - uses: actions/checkout@v2
10 |
11 | - name: get unityVersion
12 | id: unityVersion
13 | uses: notiz-dev/github-action-json-property@release
14 | with:
15 | path: 'package.json'
16 | prop_path: 'unity'
17 |
18 | - name: get unityReleaseVersion
19 | id: unityReleaseVersion
20 | uses: notiz-dev/github-action-json-property@release
21 | with:
22 | path: 'package.json'
23 | prop_path: 'unityRelease'
24 |
25 | - name: Request manual activation file
26 | id: getManualLicenseFile
27 | uses: game-ci/unity-request-activation-file@v2
28 | with:
29 | unityVersion: ${{steps.unityVersion.outputs.prop}}.${{steps.unityReleaseVersion.outputs.prop}}
30 |
31 | # Upload artifact (Unity_v20XX.X.XXXX.alf)
32 | - name: Expose as artifact
33 | uses: actions/upload-artifact@v2
34 | with:
35 | name: ${{ steps.getManualLicenseFile.outputs.filePath }}
36 | path: ${{ steps.getManualLicenseFile.outputs.filePath }}
37 |
--------------------------------------------------------------------------------
/.github/workflows/main.yml:
--------------------------------------------------------------------------------
1 | name: CI
2 |
3 | on:
4 | # Triggers the workflow on push or pull request events but only for the main branch
5 | push:
6 | branches: [ main ]
7 | pull_request:
8 | branches: [ main ]
9 |
10 | # Allows you to run this workflow manually from the Actions tab
11 | workflow_dispatch:
12 |
13 | jobs:
14 | # Tests
15 | testAllModes:
16 | name: Test in ${{ matrix.testMode }}
17 | runs-on: ubuntu-latest
18 | strategy:
19 | fail-fast: false
20 | matrix:
21 | testMode:
22 | - playmode
23 | - editmode
24 | steps:
25 | - uses: actions/checkout@v2
26 | with:
27 | repository: faster-games/package-testbed
28 | - uses: actions/checkout@v2
29 | with:
30 | path: Packages/com.faster-games.t4
31 | - uses: actions/cache@v2
32 | with:
33 | path: Library
34 | key: Library-TestPlatform
35 | restore-keys: |
36 | Library-
37 | - uses: game-ci/unity-test-runner@v2
38 | id: tests
39 | env:
40 | UNITY_LICENSE: ${{ secrets.UNITY_LICENSE }}
41 | with:
42 | projectPath: ./
43 | testMode: ${{ matrix.testMode }}
44 | artifactsPath: ${{ matrix.testMode }}-artifacts
45 | githubToken: ${{ secrets.GITHUB_TOKEN }}
46 | checkName: ${{ matrix.testMode }} Test Results
47 | release:
48 | name: Release
49 | needs: [testAllModes]
50 | if: ${{ github.ref == 'refs/heads/main' }}
51 | runs-on: ubuntu-latest
52 | steps:
53 | - uses: actions/checkout@v2
54 | - name: Create dist directory
55 | run: mkdir dist/
56 | - uses: actions/checkout@v2
57 | with:
58 | repository: faster-games/UnityFX
59 | path: dist/.unityfx
60 | - name: Install semantic-release plugins
61 | run: npm i --no-save @semantic-release/git @semantic-release/changelog
62 | - name: Export .unitypackage
63 | uses: bengreenier-actions/Unity-Package-Exporter@v1.0.0
64 | with:
65 | packagePath: ./
66 | outputPackagePath: dist/com.faster-games.t4.unitypackage
67 | - uses: bengreenier-actions/docfx-action@v1.0.0
68 | name: Build docs
69 | with:
70 | args: ./docfx.json
71 | - name: Deploy to GitHub Pages
72 | uses: Cecilapp/GitHub-Pages-deploy@v3
73 | env:
74 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75 | with:
76 | email: ben@bengreenier.com
77 | build_dir: dist/docs
78 | cname: t4.faster-games.com
79 | jekyll: no
80 | - name: Publish Release
81 | uses: codfish/semantic-release-action@v1
82 | env:
83 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
84 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # This .gitignore file should be placed at the root of your Unity project directory
2 | #
3 | # Get latest from https://github.com/github/gitignore/blob/master/Unity.gitignore
4 | #
5 | /[Ll]ibrary/
6 | /[Tt]emp/
7 | /[Oo]bj/
8 | /[Bb]uild/
9 | /[Bb]uilds/
10 | /[Ll]ogs/
11 | /[Mm]emoryCaptures/
12 |
13 | # Asset meta data should only be ignored when the corresponding asset is also ignored
14 | !/[Aa]ssets/**/*.meta
15 |
16 | # Uncomment this line if you wish to ignore the asset store tools plugin
17 | # /[Aa]ssets/AssetStoreTools*
18 |
19 | # Autogenerated Jetbrains Rider plugin
20 | [Aa]ssets/Plugins/Editor/JetBrains*
21 |
22 | # Visual Studio cache directory
23 | .vs/
24 |
25 | # Gradle cache directory
26 | .gradle/
27 |
28 | # Autogenerated VS/MD/Consulo solution and project files
29 | ExportedObj/
30 | .consulo/
31 | *.csproj
32 | *.unityproj
33 | *.sln
34 | *.suo
35 | *.tmp
36 | *.user
37 | *.userprefs
38 | *.pidb
39 | *.booproj
40 | *.svd
41 | *.pdb
42 | *.mdb
43 | *.opendb
44 | *.VC.db
45 |
46 | # Unity3D generated meta files
47 | *.pidb.meta
48 | *.pdb.meta
49 | *.mdb.meta
50 |
51 | # Unity3D generated file on crash reports
52 | sysinfo.txt
53 |
54 | # Builds
55 | *.apk
56 | *.unitypackage
57 |
58 | # Crashlytics generated file
59 | crashlytics-build.properties
60 |
61 | # docfx
62 | /**/DROP/
63 | /**/TEMP/
64 | /**/packages/
65 | /**/bin/
66 | /**/obj/
67 | _site
68 |
69 | # general dist
70 | dist/
71 | dist.meta
72 |
--------------------------------------------------------------------------------
/.releaserc.json:
--------------------------------------------------------------------------------
1 | {
2 | "branches": ["main"],
3 | "plugins": [
4 | ["@semantic-release/commit-analyzer"],
5 | ["@semantic-release/release-notes-generator"],
6 | ["@semantic-release/changelog"],
7 | [
8 | "@semantic-release/npm",
9 | {
10 | "npmPublish": false
11 | }
12 | ],
13 | [
14 | "@semantic-release/git",
15 | {
16 | "assets": ["package.json", "CHANGELOG.md", "!**/*.unitypackage"],
17 | "message": "chore(release): ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}"
18 | }
19 | ],
20 | [
21 | "@semantic-release/github",
22 | {
23 | "assets": [
24 | {
25 | "path": "dist/com.faster-games.t4.unitypackage",
26 | "name": "com.faster-games.t4-${nextRelease.gitTag}.unitypackage",
27 | "label": "FasterGames.T4 ${nextRelease.gitTag}"
28 | }
29 | ]
30 | }
31 | ]
32 | ]
33 | }
34 |
--------------------------------------------------------------------------------
/.unitypackageignore:
--------------------------------------------------------------------------------
1 | .git/
2 | .github/
3 | dist/
4 | Documentation~/
5 | node_modules/
6 | .gitignore
7 | .gitattributes
8 | .releaserc.json
9 | docfx.json
10 |
--------------------------------------------------------------------------------
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | ## [1.4.1](https://github.com/faster-games/t4/compare/v1.4.0...v1.4.1) (2021-07-22)
2 |
3 |
4 | ### Bug Fixes
5 |
6 | * **misc:** Embedded data namespaces, tests 🐛 ([#8](https://github.com/faster-games/t4/issues/8)) ([742d625](https://github.com/faster-games/t4/commit/742d6256dfe0f45eee67a433c6b860639e1f1873)), closes [#6](https://github.com/faster-games/t4/issues/6) [#7](https://github.com/faster-games/t4/issues/7)
7 |
8 | # [1.4.0](https://github.com/faster-games/t4/compare/v1.3.2...v1.4.0) (2021-07-22)
9 |
10 |
11 | ### Features
12 |
13 | * **data-binding:** Add data binding support 🧬 ([#5](https://github.com/faster-games/t4/issues/5)) ([e94bd96](https://github.com/faster-games/t4/commit/e94bd9623f8ed521ffcc92ee8acc453efc1669c4))
14 |
15 | ## [1.3.2](https://github.com/faster-games/t4/compare/v1.3.1...v1.3.2) (2021-07-20)
16 |
17 |
18 | ### Bug Fixes
19 |
20 | * **docs:** Update index page 📖 ([ff5613e](https://github.com/faster-games/t4/commit/ff5613eebb0da3fb79ad8beb093774d5a94a1816))
21 |
22 | ## [1.3.1](https://github.com/faster-games/t4/compare/v1.3.0...v1.3.1) (2021-07-19)
23 |
24 |
25 | ### Bug Fixes
26 |
27 | * **typo:** Replace readme typo 😅 ([dd1bb44](https://github.com/faster-games/t4/commit/dd1bb441b2bfb049b82094b6164431fa96815842))
28 |
29 | # [1.3.0](https://github.com/faster-games/t4/compare/v1.2.1...v1.3.0) (2021-07-19)
30 |
31 |
32 | ### Features
33 |
34 | * **docs:** Improve readme 📝 ([a5248fb](https://github.com/faster-games/t4/commit/a5248fba4f454a7fc20f5f2f3c9921e68cc44301))
35 |
36 | ## [1.2.1](https://github.com/faster-games/t4/compare/v1.2.0...v1.2.1) (2021-07-19)
37 |
38 |
39 | ### Bug Fixes
40 |
41 | * **docs:** Redirecting link to editor docs 📝 ([833e3bc](https://github.com/faster-games/t4/commit/833e3bc8d723381dbf8fe012603878d6ab4c08b4))
42 |
43 | # [1.2.0](https://github.com/faster-games/t4/compare/v1.1.0...v1.2.0) (2021-07-19)
44 |
45 |
46 | ### Bug Fixes
47 |
48 | * **docs:** fix example typo 🐛 ([#4](https://github.com/faster-games/t4/issues/4)) ([0051ae6](https://github.com/faster-games/t4/commit/0051ae6d7bb2e300a40d85336c3e62adad8a2433))
49 |
50 |
51 | ### Features
52 |
53 | * **mono-t4:** Add generation support 🚀 ([#3](https://github.com/faster-games/t4/issues/3)) ([612fbb0](https://github.com/faster-games/t4/commit/612fbb0dfe7e9828a62ee53e819e67a0fac4ea10))
54 |
55 | # [1.1.0](https://github.com/faster-games/t4/compare/v1.0.1...v1.1.0) (2021-07-19)
56 |
57 |
58 | ### Features
59 |
60 | * **dev-docs:** Update dev docs 📝 ([#2](https://github.com/faster-games/t4/issues/2)) ([9f1c588](https://github.com/faster-games/t4/commit/9f1c5887110e9c8e4efab655473f2a442e53a458))
61 |
62 | ## [1.0.1](https://github.com/faster-games/t4/compare/v1.0.0...v1.0.1) (2021-07-19)
63 |
64 |
65 | ### Bug Fixes
66 |
67 | * **header:** Update header images 🎨 ([1a23378](https://github.com/faster-games/t4/commit/1a23378e6243e9ad5c81595228b4c301108b4e99))
68 |
69 | # 1.0.0 (2021-07-19)
70 |
71 |
72 | ### Bug Fixes
73 |
74 | * **activation:** Add temp push trigger 🐛 ([9359e67](https://github.com/faster-games/t4/commit/9359e67083794c36c09f0fbd6830165551a39efe))
75 | * **activation:** Re-add activation workflow 🎛 ([#1](https://github.com/faster-games/t4/issues/1)) ([66331ab](https://github.com/faster-games/t4/commit/66331abd742a63850ccb0280c3a8ab43d81468d4))
76 | * **activation:** Remove push trigger ⚡ ([5b65f80](https://github.com/faster-games/t4/commit/5b65f80f43220fc7b035582998ee5c0d83f958fd))
77 | * **meta:** Add initial meta files 🎟 ([43555ad](https://github.com/faster-games/t4/commit/43555ad10d548f8ee212aa2c2148bf995ba032cc))
78 |
79 |
80 | ### Features
81 |
82 | * **init:** Create from package-template 🧩 ([c423d5d](https://github.com/faster-games/t4/commit/c423d5de6c219aac39263bc50fc59062e474df5e))
83 |
--------------------------------------------------------------------------------
/CHANGELOG.md.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 08e8a0aba2c5035419359f6a40e5361c
3 | TextScriptImporter:
4 | externalObjects: {}
5 | userData:
6 | assetBundleName:
7 | assetBundleVariant:
8 |
--------------------------------------------------------------------------------
/Documentation~/favicon.ico:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/faster-games/t4/954234411b76686e106e8da305fbd85d69a31cc9/Documentation~/favicon.ico
--------------------------------------------------------------------------------
/Documentation~/header.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/faster-games/t4/954234411b76686e106e8da305fbd85d69a31cc9/Documentation~/header.png
--------------------------------------------------------------------------------
/Documentation~/index.md:
--------------------------------------------------------------------------------
1 | # t4
2 |
3 | T4 text template generative importer for Unity3D. [View On GitHub](https://github.com/faster-games/t4) 📝🏗
4 |
5 |
6 |
7 | 
8 | [](https://openupm.com/packages/com.faster-games.t4/)
9 | [](https://github.com/faster-games/t4/actions/workflows/main.yml)
10 | [](https://discord.gg/QfQE6rWQqq)
11 |
12 | [T4 Text Templates](https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates) provide a way to generate csharp code from templates, which are a mixture of text blocks and control logic. If you've ever used [Mushtache](http://mustache.github.io/mustache.5.html) or [Go's html/template](https://gowebexamples.com/templates/), T4 templates are pretty similar. This package allows [Unity](http://unity3d.com/) developers to author T4 templates (`.tt` files), and rely on the [Editor](https://docs.unity3d.com/Manual/UsingTheEditor.html) to process them and generate code.
13 |
14 | ## Installing
15 |
16 | This package supports [openupm](https://openupm.com/packages/com.faster-games.t4/) - you can install it using the following command:
17 |
18 | ```
19 | openupm add com.faster-games.t4
20 | ```
21 |
22 | Or by adding directly to your `manifest.json`:
23 |
24 | > Note: You may also use specific versions by appending `#{version}` where version is a [Release tag](https://github.com/faster-games/t4/releases) - e.g. `#v1.2.0`.
25 |
26 | ```
27 | dependencies: {
28 | ...
29 | "com.faster-games.t4": "git+https://github.com/faster-games/t4.git"
30 | }
31 | ```
32 |
33 | Or by using [Package Manager](https://docs.unity3d.com/Manual/upm-ui-giturl.html) to "Add a package from Git URL", using the following url:
34 |
35 | ```
36 | https://github.com/faster-games/t4.git
37 | ```
38 |
39 | ## Documentation
40 |
41 | - [Manual 📖](https://t4.faster-games.com/manual/getting-started.html)
42 | - [Scripting API 🔎](https://t4.faster-games.com/ref/FasterGames.T4.Editor.html)
43 |
44 | Please also see these resources from Microsoft, as they are the authors and maintainers of the `T4` templating featureset and format:
45 |
46 | - [MS Docs: Code Generation and T4 Text Templates](https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates)
47 | - [MS Docs: Design Time Templates](https://docs.microsoft.com/en-us/visualstudio/modeling/design-time-code-generation-by-using-t4-text-templates)
48 |
49 | ### Quickstart
50 |
51 | - Add a `.tt` file under `Assets`
52 | - Select it in the [Project window](https://docs.unity3d.com/Manual/ProjectView.html)
53 | - Note that the importer used is `TextTemplateImporter` - that's us!
54 | - Any processing errors will be shown in the [Console](https://docs.unity3d.com/Manual/Console.html)
55 |
56 | ## Supporting the project
57 |
58 | If this project saved you some time, and you'd like to see it continue to be invested in, consider [buying me a coffee. ☕](https://www.buymeacoffee.com/bengreenier) I do this full-time, and every little bit helps! 💙
59 |
--------------------------------------------------------------------------------
/Documentation~/logo.svg:
--------------------------------------------------------------------------------
1 |
6 |
--------------------------------------------------------------------------------
/Documentation~/manual/contributing.md:
--------------------------------------------------------------------------------
1 | # Contributing
2 |
3 | To contribute to `faster-games/t4` here are some things you'll want to know:
4 |
5 | + `Documentation~\scripts\update-engine.ps1` can be used to pull `mono/t4` updates
6 | + `Documentation~\scripts\generate-docs.ps1` can be used to re-generate `docfx` docs
7 | + Min-supported Unity version is documented in `package.json`
8 | + `.gitattributes` should force `LF` endings
9 |
10 | Other than that, we use a normal fork and PR process to contribute! Feel free to send a PR, or open an Issue to discuss approaches.
11 |
--------------------------------------------------------------------------------
/Documentation~/manual/data-binding.md:
--------------------------------------------------------------------------------
1 | # Data Binding
2 |
3 | > Note: This is a `Beta` feature, and is being actively developed. To use this feature, you need [`importerVersion`](xref:FasterGames.T4.Editor.TextTemplateImporter.importerVersion) to be set to [`Beta`](xref:FasterGames.T4.Editor.ImporterVersion.Beta).
4 |
5 | Data binding allows sharing data from Unity with a template. This allows the template to access and use that data during generation.
6 |
7 | ## Getting started
8 |
9 |
10 | - Create a class to represent the data you wish to embed:
11 | ```
12 | [CreateAssetMenu(menuName = "EmbedData")]
13 | public class EmbedData : ScriptableObject
14 | {
15 | public List Animals;
16 | }
17 | ```
18 | - Create an instance of this data in the Editor [Project window](https://docs.unity3d.com/Manual/ProjectView.html) (Right click -> Create -> EmbedData)
19 | - Create a TT file to use this data:
20 | ```
21 | <#@ template debug="false" hostspecific="true" language="C#" #>
22 | <#@ output extension=".cs" #>
23 | <#@ import namespace="System.IO" #>
24 | using System;
25 |
26 | <#
27 | foreach (var animal in Host.Data.Animals)
28 | {
29 | #>
30 |
31 | [Serializable]
32 | public class <#= animal#>Test {}
33 |
34 | <#
35 | }
36 | #>
37 | ```
38 | - Select the TT file in the [Project window](https://docs.unity3d.com/Manual/ProjectView.html)
39 | - In the [Inspector](https://docs.unity3d.com/Manual/UsingTheInspector.html) ensure [`importerVersion`](xref:FasterGames.T4.Editor.TextTemplateImporter.importerVersion) is set to [`Beta`](xref:FasterGames.T4.Editor.ImporterVersion.Beta)
40 | - Drag the data instance you created in the [Project window](https://docs.unity3d.com/Manual/ProjectView.html) to the [`embeddedData`](xref:FasterGames.T4.Editor.TextTemplateImporter.embeddedData) section in the [Inspector](https://docs.unity3d.com/Manual/UsingTheInspector.html)
41 | - Select "Apply"
42 |
43 | This will cause the template to be run such that `Host.Data` is the instance of your data.
44 |
45 | ## Troubleshooting
46 |
47 | ### Does the template need to be host specific?
48 |
49 | Yes - to inform the template engine to use the host with our data, [`hostspecific`](https://docs.microsoft.com/en-us/visualstudio/modeling/t4-template-directive?view=vs-2019#hostspecific-attribute) must be set to `true`.
50 |
51 | For instance:
52 | ```
53 | <#@ template debug="false" hostspecific="true" language="C#" #>
54 | ```
55 |
56 | ### Why does my template break when embeddedData is enabled?
57 |
58 | If your template fails to generate content after embedding data, this may be because the data class you're using is complex, and references other types that the template environment is not aware of. Usually if this is the case, the error will inform you of what type is missing. You may specify this type in [`additionalTypes`](xref:FasterGames.T4.Editor.TextTemplateImporter.additionalTypes) list, or simplify your data class.
59 |
60 | If you're not able to get it working, please [open an Issue](https://github.com/faster-games/t4/issues/new).
61 |
62 | ### Why does my template break on first import?
63 |
64 | If your data class and your codegen classes are in the same assembly (asmdef folder), on first import you may experience an error indicating the `UnityEngine.Object` does not have required properties. This is because Unity wasn't able to generate the assembly with your data class before attempting the import - as such, your embedded data structure is missing.
65 |
66 | The quickest solution is to move your data class to it's own assembly:
67 | - Create a new folder
68 | - Create an Assembly Definition in that folder
69 | - Move the data class to this new folder
70 | - Add a reference to this new assembly in the codegen assembly
71 |
--------------------------------------------------------------------------------
/Documentation~/manual/getting-started.md:
--------------------------------------------------------------------------------
1 | # Getting Started
2 |
3 | Some tips and tricks on how to begin using T4 Templating.
4 |
5 | ## Official Docs
6 |
7 | - [MS Docs: Code Generation and T4 Text Templates](https://docs.microsoft.com/en-us/visualstudio/modeling/code-generation-and-t4-text-templates)
8 | - [MS Docs: Design Time Templates](https://docs.microsoft.com/en-us/visualstudio/modeling/design-time-code-generation-by-using-t4-text-templates)
9 |
10 | ## Quick Examples
11 |
12 | ### Generate UnityEvent classes
13 |
14 | Sometimes you may want to have many [UnityEvents](https://docs.unity3d.com/Manual/UnityEvents.html) with various typed parameters. Using a Text Template, you can quickly generate these classes:
15 |
16 | ```cs
17 | <#@ template language="C#" #>
18 | <#@ import namespace="System.Text" #>
19 | <#@ import namespace="System.Collections.Generic" #>
20 |
21 | using System;
22 | using UnityEngine;
23 | using UnityEngine.Events;
24 |
25 | namespace Events
26 | {
27 |
28 | <#
29 | foreach (var type in new string[] {"Vector2", "Vector3"})
30 | {
31 | #>
32 | [Serializable]
33 | public class <#= type #>Event : UnityEvent<<#= type #>> {}
34 |
35 | <#
36 | }
37 | #>
38 |
39 | }
40 | ```
41 |
42 | We embed a `foreach` loop that walks a list of type names (as strings). For each type, we create a class named `{Type}Event`, that inherits from `UnityEvent<{Type}>`. Here's the output:
43 |
44 | ```cs
45 |
46 | using System;
47 | using UnityEngine;
48 | using UnityEngine.Events;
49 |
50 | namespace Events
51 | {
52 | [Serializable]
53 | public class Vector2Event : UnityEvent {}
54 |
55 | [Serializable]
56 | public class Vector3Event : UnityEvent {}
57 | }
58 | ```
59 |
--------------------------------------------------------------------------------
/Documentation~/manual/toc.yml:
--------------------------------------------------------------------------------
1 | - name: Getting Started
2 | href: getting-started.md
3 | - name: Data Binding
4 | href: data-binding.md
5 | - name: Contributing
6 | href: contributing.md
7 |
--------------------------------------------------------------------------------
/Documentation~/scripts/file-utils.patch:
--------------------------------------------------------------------------------
1 | From fc256ed9990469023e1859653077f804ce007a1e Mon Sep 17 00:00:00 2001
2 | From: Ben Greenier
3 | Date: Mon, 19 Jul 2021 12:20:21 -0700
4 | Subject: [PATCH] patch file
5 |
6 | ---
7 | .../Mono.TextTemplating/FileUtil.cs | 77 +------------------
8 | 1 file changed, 4 insertions(+), 73 deletions(-)
9 |
10 | diff --git a/Editor/TextTemplating/Mono.TextTemplating/FileUtil.cs b/Editor/TextTemplating/Mono.TextTemplating/FileUtil.cs
11 | index 866b903..1222681 100644
12 | --- a/Editor/TextTemplating/Mono.TextTemplating/FileUtil.cs
13 | +++ b/Editor/TextTemplating/Mono.TextTemplating/FileUtil.cs
14 | @@ -31,80 +31,11 @@ namespace Mono.TextTemplating
15 | static class FileUtil
16 | {
17 | //from MonoDevelop.Core.FileService, copied here so Mono.TextTemplating can be used w/o MD dependency
18 | - public unsafe static string AbsoluteToRelativePath (string baseDirectoryPath, string absPath)
19 | + public static string AbsoluteToRelativePath (string baseDirectoryPath, string absPath)
20 | {
21 | - if (!Path.IsPathRooted (absPath) || string.IsNullOrEmpty (baseDirectoryPath))
22 | - return absPath;
23 | -
24 | - absPath = GetFullPath (absPath);
25 | - baseDirectoryPath = GetFullPath (baseDirectoryPath).TrimEnd (Path.DirectorySeparatorChar);
26 | -
27 | - fixed (char* bPtr = baseDirectoryPath, aPtr = absPath) {
28 | - var bEnd = bPtr + baseDirectoryPath.Length;
29 | - var aEnd = aPtr + absPath.Length;
30 | - char* lastStartA = aEnd;
31 | - char* lastStartB = bEnd;
32 | -
33 | - int indx = 0;
34 | - // search common base path
35 | - var a = aPtr;
36 | - var b = bPtr;
37 | - while (a < aEnd) {
38 | - if (*a != *b)
39 | - break;
40 | - if (IsSeparator (*a)) {
41 | - indx++;
42 | - lastStartA = a + 1;
43 | - lastStartB = b;
44 | - }
45 | - a++;
46 | - b++;
47 | - if (b >= bEnd) {
48 | - if (a >= aEnd || IsSeparator (*a)) {
49 | - indx++;
50 | - lastStartA = a + 1;
51 | - lastStartB = b;
52 | - }
53 | - break;
54 | - }
55 | - }
56 | - if (indx == 0)
57 | - return absPath;
58 | -
59 | - if (lastStartA >= aEnd)
60 | - return ".";
61 | -
62 | - // handle case a: some/path b: some/path/deeper...
63 | - if (a >= aEnd) {
64 | - if (IsSeparator (*b)) {
65 | - lastStartA = a + 1;
66 | - lastStartB = b;
67 | - }
68 | - }
69 | -
70 | - // look how many levels to go up into the base path
71 | - int goUpCount = 0;
72 | - while (lastStartB < bEnd) {
73 | - if (IsSeparator (*lastStartB))
74 | - goUpCount++;
75 | - lastStartB++;
76 | - }
77 | - var size = goUpCount * 2 + goUpCount + aEnd - lastStartA;
78 | - var result = new char [size];
79 | - fixed (char* rPtr = result) {
80 | - // go paths up
81 | - var r = rPtr;
82 | - for (int i = 0; i < goUpCount; i++) {
83 | - *(r++) = '.';
84 | - *(r++) = '.';
85 | - *(r++) = Path.DirectorySeparatorChar;
86 | - }
87 | - // copy the remaining absulute path
88 | - while (lastStartA < aEnd)
89 | - *(r++) = *(lastStartA++);
90 | - }
91 | - return new string (result);
92 | - }
93 | + var fileUri = new Uri(absPath);
94 | + var referenceUri = new Uri(baseDirectoryPath);
95 | + return Uri.UnescapeDataString(referenceUri.MakeRelativeUri(fileUri).ToString()).Replace('/', Path.DirectorySeparatorChar);
96 | }
97 |
98 | static bool IsSeparator (char ch)
99 | --
100 | 2.30.1.windows.1
101 |
102 |
--------------------------------------------------------------------------------
/Documentation~/scripts/generate-docs.ps1:
--------------------------------------------------------------------------------
1 | Remove-Item -Recurse -Force dist/
2 | Remove-Item -Recurse -Force obj/
3 |
4 | git clone https://github.com/faster-games/UnityFX.git dist/.unityfx
5 | docfx
6 |
--------------------------------------------------------------------------------
/Documentation~/scripts/generate-docs.sh:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | rm -rf dist/
4 | rm -rf obj/
5 |
6 | git clone https://github.com/faster-games/UnityFX.git dist/.unityfx
7 | docfx
8 |
--------------------------------------------------------------------------------
/Documentation~/scripts/lib-visibility.patch:
--------------------------------------------------------------------------------
1 | From acd71f305824e38b35621bb7f2aeee5a0aedf734 Mon Sep 17 00:00:00 2001
2 | From: Ben Greenier
3 | Date: Mon, 19 Jul 2021 12:48:24 -0700
4 | Subject: [PATCH] =?UTF-8?q?fix(patch-lib):=20Patch=20visibility=20for=20te?=
5 | =?UTF-8?q?sting=20=F0=9F=91=80?=
6 | MIME-Version: 1.0
7 | Content-Type: text/plain; charset=UTF-8
8 | Content-Transfer-Encoding: 8bit
9 |
10 | ---
11 | Editor/TextTemplating/Mono.TextTemplating/StringUtil.cs | 2 +-
12 | Editor/TextTemplating/Mono.TextTemplating/TemplateGenerator.cs | 2 +-
13 | 2 files changed, 2 insertions(+), 2 deletions(-)
14 |
15 | diff --git a/Editor/TextTemplating/Mono.TextTemplating/StringUtil.cs b/Editor/TextTemplating/Mono.TextTemplating/StringUtil.cs
16 | index bfcadb5..386fd53 100644
17 | --- a/Editor/TextTemplating/Mono.TextTemplating/StringUtil.cs
18 | +++ b/Editor/TextTemplating/Mono.TextTemplating/StringUtil.cs
19 | @@ -2,7 +2,7 @@ using System;
20 |
21 | namespace Mono.TextTemplating
22 | {
23 | - internal static class StringUtil
24 | + public static class StringUtil
25 | {
26 | public static Boolean IsNullOrWhiteSpace (String value)
27 | {
28 | diff --git a/Editor/TextTemplating/Mono.TextTemplating/TemplateGenerator.cs b/Editor/TextTemplating/Mono.TextTemplating/TemplateGenerator.cs
29 | index 24e7c3f..8986240 100644
30 | --- a/Editor/TextTemplating/Mono.TextTemplating/TemplateGenerator.cs
31 | +++ b/Editor/TextTemplating/Mono.TextTemplating/TemplateGenerator.cs
32 | @@ -307,7 +307,7 @@ namespace Mono.TextTemplating
33 | return false;
34 | }
35 |
36 | - internal static bool TryParseParameter (string parameter, out string processor, out string directive, out string name, out string value)
37 | + public static bool TryParseParameter (string parameter, out string processor, out string directive, out string name, out string value)
38 | {
39 | processor = directive = name = value = "";
40 |
41 | --
42 | 2.30.1.windows.1
43 |
44 |
--------------------------------------------------------------------------------
/Documentation~/scripts/update-engine.ps1:
--------------------------------------------------------------------------------
1 | param (
2 | [string]
3 | $Version = "2.0.5",
4 |
5 | [bool]
6 | $UpdateLib = $true,
7 |
8 | [bool]
9 | $UpdateTests = $true
10 | )
11 |
12 | $WorkingDirectory="dist/.t4"
13 | $LibDirectory="Editor/TextTemplating"
14 | $TestDirectory="Tests/Editor/TextTemplating"
15 |
16 | try {
17 | Remove-Item -Recurse -Force "$WorkingDirectory"
18 | } catch {}
19 |
20 | if (!(Test-Path $WorkingDirectory))
21 | {
22 | [System.IO.Directory]::CreateDirectory($WorkingDirectory)
23 | }
24 |
25 |
26 | Invoke-WebRequest -Uri "https://github.com/mono/t4/archive/refs/tags/v$Version.zip" -OutFile "$WorkingDirectory/lib.zip"
27 | Expand-Archive -Path "$WorkingDirectory/lib.zip" -DestinationPath "$WorkingDirectory/lib/"
28 | Copy-Item -Recurse -Path "$WorkingDirectory/lib/t4-$Version/Mono.TextTemplating/" -Destination "$WorkingDirectory/TextTemplating/"
29 | Copy-Item -Recurse -Path "$WorkingDirectory/lib/t4-$Version/Mono.TextTemplating.Tests/" -Destination "$WorkingDirectory/TextTemplating.Tests/"
30 | Remove-Item -Recurse -Force "$WorkingDirectory/lib"
31 | Remove-Item -Force "$WorkingDirectory/TextTemplating/Mono.TextTemplating.csproj"
32 | Remove-Item -Force "$WorkingDirectory/TextTemplating.Tests/Mono.TextTemplating.Tests.csproj"
33 | Remove-Item -Force "$WorkingDirectory/TextTemplating.Tests/MSBuildErrorParserTests.cs"
34 | Remove-Item -Force "$WorkingDirectory/TextTemplating/AssemblyInfo.cs"
35 | Remove-Item -Force "$WorkingDirectory/lib.zip"
36 |
37 | if ($UpdateLib)
38 | {
39 | try {
40 | Remove-Item -Recurse -Force "$LibDirectory/"
41 | } catch {}
42 | Copy-Item -Recurse -Path "$WorkingDirectory/TextTemplating/" -Destination "$LibDirectory/"
43 |
44 | git am Documentation~/scripts/file-utils.patch
45 | }
46 |
47 | if ($UpdateTests)
48 | {
49 | try {
50 | Remove-Item -Recurse -Force "$TestDirectory/"
51 | } catch {}
52 | Copy-Item -Recurse -Path "$WorkingDirectory/TextTemplating.Tests/" -Destination "$TestDirectory/"
53 |
54 | git am Documentation~/scripts/lib-visibility.patch
55 | }
56 |
--------------------------------------------------------------------------------
/Documentation~/toc.yml:
--------------------------------------------------------------------------------
1 | - name: Home
2 | href: index.md
3 | - name: Manual
4 | href: manual/
5 | homepage: manual/getting-started.md
6 | - name: Scripting API
7 | href: xref:FasterGames.T4.Editor
8 |
--------------------------------------------------------------------------------
/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e7f56891fc83f8a42aef87667478f85a
3 | folderAsset: yes
4 | DefaultImporter:
5 | externalObjects: {}
6 | userData:
7 | assetBundleName:
8 | assetBundleVariant:
9 |
--------------------------------------------------------------------------------
/Editor/EditorExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.IO;
2 | using UnityEditor;
3 | using UnityEngine;
4 |
5 | namespace FasterGames.T4.Editor
6 | {
7 | ///
8 | /// Editor extensions to add TT creation to right click menus
9 | ///
10 | public static class EditorExtensions
11 | {
12 | ///
13 | /// Asset menu to create TT (.tt) files
14 | ///
15 | [MenuItem("Assets/Create/T4 Template", priority = 100)]
16 | public static void CreateTTFile()
17 | {
18 | var assetName = CreateSafeName(Path.Combine(EditorUtils.GetCurrentAssetDirectory(), "textTemplate.tt"));
19 | File.Create(assetName).Dispose();
20 |
21 | AssetDatabase.ImportAsset(assetName);
22 | }
23 |
24 | ///
25 | /// Asset menu to create TTInclude (.ttinclude) files
26 | ///
27 | [MenuItem("Assets/Create/T4 Template Include", priority = 101)]
28 | public static void CreateTTIncludeFile()
29 | {
30 | var assetName = CreateSafeName(Path.Combine(EditorUtils.GetCurrentAssetDirectory(), "textTemplateInclude.ttinclude"));
31 | File.Create(assetName).Dispose();
32 | AssetDatabase.ImportAsset(assetName);
33 | }
34 |
35 | ///
36 | /// Creates a filename that isn't currently in use
37 | ///
38 | /// the name you desire
39 | /// the name that's available
40 | private static string CreateSafeName(string desiredName)
41 | {
42 | var name = desiredName;
43 | var i = 1;
44 | while (File.Exists(name))
45 | {
46 | name = Path.Combine(Path.GetDirectoryName(desiredName), $"{Path.GetFileNameWithoutExtension(desiredName)}{i}{Path.GetExtension(desiredName)}");
47 | i++;
48 | }
49 |
50 | return name;
51 | }
52 | }
53 | }
--------------------------------------------------------------------------------
/Editor/EditorExtensions.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 56b1fb9c95624706b2c83a9269ab0fb0
3 | timeCreated: 1626820143
--------------------------------------------------------------------------------
/Editor/EditorUtils.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using UnityEditor;
4 | using Object = UnityEngine.Object;
5 |
6 | namespace FasterGames.T4.Editor
7 | {
8 | ///
9 | /// Internal editor utilities
10 | ///
11 | internal static class EditorUtils
12 | {
13 | ///
14 | /// task runner
15 | ///
16 | ///
17 | /// This allows us to schedule work to be run once on Editor update
18 | ///
19 | /// task to run
20 | public static void Once(Action cb)
21 | {
22 | OnceTasks.Enqueue(cb);
23 | EditorApplication.update += OnceRunner;
24 | }
25 |
26 | ///
27 | /// Storage for tasks. See
28 | ///
29 | private static readonly Queue OnceTasks = new Queue();
30 |
31 | ///
32 | /// Worker job that runs on Editor update
33 | ///
34 | ///
35 | /// This checks if any jobs need to be run, and if so, runs them.
36 | ///
37 | private static void OnceRunner()
38 | {
39 | while (OnceTasks.Count > 0)
40 | {
41 | OnceTasks.Dequeue()();
42 | }
43 |
44 | EditorApplication.update -= OnceRunner;
45 | }
46 |
47 | ///
48 | /// Get the current asset directory
49 | ///
50 | ///
51 | /// From https://gist.github.com/allanolivei/9260107
52 | ///
53 | /// directory
54 | public static string GetCurrentAssetDirectory()
55 | {
56 | foreach (var obj in Selection.GetFiltered