Skip to content

Commit 35f1d77

Browse files
committed
v1.4.0
1 parent b068e1a commit 35f1d77

File tree

2 files changed

+91
-7
lines changed

2 files changed

+91
-7
lines changed

README.md

+90-6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ Alternative Source Generator is built on the Unity native functions.
1111

1212
As you already know, Roslyn's source generator is too sophisticated. This framework provides more simple, ease of use and good enough functions for source code generation.
1313

14+
- [Troubleshooting](#troubleshooting)
15+
16+
1417
<p><details lang="ja" --open><summary><small>日本語 / JA</small></summary>
1518

1619
超簡単に使える Unity 向けソースジェネレーターです。
@@ -27,12 +30,14 @@ As you already know, Roslyn's source generator is too sophisticated. This framew
2730
- [Generic Generator](#generic-generator)
2831
- [Result](#result-1)
2932
- [Output Directory and File Name](#output-directory-and-file-name)
33+
- [Coding Goodies](#coding-goodies)
3034
- [Utility Functions for Build](#utility-functions-for-build)
3135
- [Technical Notes](#technical-notes)
3236
- [Naming Convention](#naming-convention)
3337
- [`<auto-generated/>` Tag](#auto-generated-tag)
3438
- [Installation](#installation)
3539
- [Editor Extensions](#editor-extensions)
40+
- [Troubleshooting](#troubleshooting)
3641
- [Copyright](#copyright)
3742
- [License](#license)
3843
- [Devnote](#devnote)
@@ -45,7 +50,8 @@ As you already know, Roslyn's source generator is too sophisticated. This framew
4550

4651

4752

48-
# Sample Code
53+
Sample Code
54+
===========
4955

5056
Minimal implementation codes of source generator.
5157

@@ -176,7 +182,8 @@ Hello World from Sample.MinimalGenerator
176182
```
177183

178184

179-
# Output Directory and File Name
185+
Output Directory and File Name
186+
==============================
180187

181188
Source Generator creates `USG.g` folder next to target script and append class names to file name.
182189

@@ -196,7 +203,68 @@ Resulting file path will be:
196203

197204

198205

199-
# Utility Functions for Build
206+
Coding Goodies
207+
==============
208+
209+
There are utility methods for coding source generator more efficient and readable.
210+
211+
- `StringBuilder` Extentions
212+
- `IndentLine` / `IndentAppend`
213+
- `IndentLevel` / `IndentChar` / `IndentSize`
214+
- `IndentBegin` / `IndentEnd`
215+
- `USGFullNameOf`
216+
- `usg`
217+
- `USGReflection`
218+
- `GetAllPublicInstanceFieldAndProperty`
219+
- `TryGetFieldOrPropertyType`
220+
- `GetEnumNamesAndValuesAsDictionary`
221+
- `GetEnumNamesAndValuesAsTuple`
222+
223+
`usg` is a special utility that is designed for refactoring-ready source generator more readable, script template import it as a static library by default.
224+
225+
226+
<p><details lang="ja" --open><summary><small>日本語 / JA</small></summary>
227+
228+
`System.Reflection` 系のユーティリティーと `StringBuilder` の拡張メソッド群。
229+
230+
`usg` は特殊で、クラス名やら何やらのリファクタリングに強いジェネレーターにすると読みづらくなってしまうのを緩和するためのモノ。
231+
232+
`{typeof(MyClass).FullName}.{nameof(MyClass.Property)}` どんどん長くなるだけなら良いけどクラス内クラスとか構造体の名前が + 付きの不正な状態で出てくる。その他にもジェネリッククラスへの対応とかなんとか、結局何かが必要になる。それならばと可能な限り短く書けるようにした。
233+
234+
インデント系はトリッキーだけど開発機での実行なのでまあ良し。
235+
236+
<!------- End of Details JA Tag -------></details></p>
237+
238+
239+
```csharp
240+
using static SatorImaging.UnitySourceGenerator.USGFullNameOf; // usg<T>() to work
241+
242+
// simple usage -> Full.Namespace.To.MyClass.MyStruct.MyField
243+
usg<MyClass>("MyStruct.MyField");
244+
// most strict refactoring-ready coding is...
245+
usg<MyClass>(nameof(MyClass.MyStruct), nameof(MyClass.MyStruct.MyField));
246+
247+
// indent utility
248+
sb.IndentChar(' '); // default
249+
sb.IndentSize(4); // default
250+
sb.IndentLevel(3); // template default
251+
sb.IndentBegin();
252+
{
253+
// cast int value to enum
254+
sb.IndentLine($"MyObject.EnumValue = ({usg<MyEnum>()})intValue");
255+
// --- or ---
256+
string CAST_MY_ENUM = "(" + usg(typeVariableCanBePassed) + ")";
257+
sb.IndentLine($"MyObject.EnumValue = {CAST_MY_ENUM}intValue");
258+
}
259+
sb.IndentEnd();
260+
```
261+
262+
> **NOTE**: Inner class, enum or struct (`MyClass+InnerEnum`) is supported. Generic class (<code>MyClass`1</code>) naming is not supported yet.
263+
264+
265+
266+
Utility Functions for Build
267+
===========================
200268

201269
There are utility functions to perform source code generation on build event.
202270

@@ -218,7 +286,8 @@ USGEngine.ProcessFile(assetPath);
218286

219287

220288

221-
# Technical Notes
289+
Technical Notes
290+
===============
222291

223292
As of C# 9.0, it doesn't allow to define `abstract static` methods in interface, USG reports error when source generator class doesn't implement required static methods.
224293

@@ -271,7 +340,8 @@ USG automatically adds document tag at the beginning of generated file. You can
271340

272341

273342

274-
# Installation
343+
Installation
344+
============
275345

276346
Use the following git URL in Unity Package Manager (UPM).
277347

@@ -280,7 +350,8 @@ Use the following git URL in Unity Package Manager (UPM).
280350

281351

282352

283-
# Editor Extensions
353+
Editor Extensions
354+
=================
284355

285356
<p><details lang="ja" --open><summary><small>日本語 / JA</small></summary>
286357

@@ -304,6 +375,19 @@ There is an ability to invoke source code generation by hand. With generator scr
304375

305376

306377

378+
Troubleshooting
379+
===============
380+
381+
#### Generator script update is not applied to generated file.
382+
383+
Usually, this problem happens when Unity automatically reloads updated scripts WITHOUT Editor window getting focus. To solve the problem:
384+
385+
1. Close Unity and Visual Studio.
386+
1. Restart Unity.
387+
1. Launch Visual Studio by double clicking `.cs` script in Unity Editor.
388+
389+
390+
307391

308392

309393
Copyright

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "com.sator-imaging.alt-source-generator",
33
"displayName": "Alternative Source Generator for Unity",
4-
"version": "1.3.0",
4+
"version": "1.4.0",
55
"unity": "2021.3",
66
"description": "Ease-of-Use Source Generator Alternative for Unity.",
77
"author": {

0 commit comments

Comments
 (0)