@@ -19,24 +19,24 @@ As you already know, Roslyn's source generator is too sophisticated. This framew
19
19
<!-- ----- End of Details JA Tag -------> </details ></p >
20
20
21
21
22
- ![ ] ( https://dl.dropbox.com/scl/fi/jijclnarrruxdt590vss1/USG_Panel.png?rlkey=k44lc9swk0mmui849ck7tappk&dl=0 )
22
+ - [ 🎉 USG Control Centre <sup ><sub ><sup >* New* </sup ></sub ></sup >] ( #usg-control-panel--window )
23
+ ![ ] ( https://dl.dropbox.com/scl/fi/jijclnarrruxdt590vss1/USG_Panel.png?rlkey=k44lc9swk0mmui849ck7tappk&dl=0 )
24
+ - [ 🛠 Breaking Changes] ( CHANGELOG.md )
25
+ - [ ✅ TODO] ( #todo )
23
26
24
27
25
- - [ USG Control Centre <sup ><sup ><sub >* New* </sub ></sup ></sup >] ( #usg-control-panel--window )
26
- - [ Breaking Changes in v2.0] ( CHANGELOG.md )
27
- - [ TODO] ( #todo )
28
+ <p ><details lang =" en " open ><summary >📃 Table of Contents</summary >
28
29
29
-
30
- <p ><details lang =" en " open ><summary >Table of Contents</summary >
31
-
32
- - [ Sample Code] ( #sample-code )
30
+ - [ How to Use] ( #how-to-use )
33
31
- [ Method Generator] ( #method-generator )
34
- - [ How to Use ] ( #how-to-use )
32
+ - [ How to Generate Source Code ] ( #how-to-generate-source-code )
35
33
- [ Result] ( #result )
36
34
- [ Self-Emit Generator] ( #self-emit-generator )
37
35
- [ Result] ( #result-1 )
38
36
- [ Output Directory and File Name] ( #output-directory-and-file-name )
39
37
- [ Coding Goodies] ( #coding-goodies )
38
+ - [ Samples] ( #samples )
39
+ - [ SceneBuildIndexGenerator] ( #scenebuildindexgenerator )
40
40
- [ Utility Functions for Build Event] ( #utility-functions-for-build-event )
41
41
- [ Technical Notes] ( #technical-notes )
42
42
- [ Naming Convention] ( #naming-convention )
@@ -57,8 +57,8 @@ As you already know, Roslyn's source generator is too sophisticated. This framew
57
57
58
58
59
59
60
- Sample Code
61
- ===========
60
+ How to Use
61
+ ==========
62
62
63
63
Here is minimal implementation of source generator.
64
64
@@ -107,7 +107,7 @@ namespace {context.TargetClass.Namespace}
107
107
108
108
109
109
110
- ### How to Use
110
+ ### How to Generate Source Code
111
111
112
112
113
113
``` csharp
@@ -221,27 +221,12 @@ There are utility methods for coding source generator more efficient and readabl
221
221
- ` IndentLevel ` / ` IndentChar ` / ` IndentSize `
222
222
- ` USGFullNameOf `
223
223
- ` usg `
224
- - ` USGReflection `
224
+ - ` USGReflection ` < sub >< sup > * can be used on Unity runtime</ sup ></ sub >
225
225
- ` GetAllPublicInstanceFieldAndProperty `
226
226
- ` TryGetFieldOrPropertyType `
227
227
- ` GetEnumNamesAndValuesAsDictionary `
228
228
- ` GetEnumNamesAndValuesAsTuple `
229
229
230
- ` 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.
231
-
232
-
233
- <p ><details lang =" ja " --open ><summary ><small >日本語 / JA</small ></summary >
234
-
235
- ` System.Reflection ` 系のユーティリティーと ` StringBuilder ` の拡張メソッド群。
236
-
237
- ` usg ` は特殊で、クラス名やら何やらのリファクタリングに強いジェネレーターにすると読みづらくなってしまうのを緩和するためのモノ。
238
-
239
- ` {typeof(MyClass).FullName}.{nameof(MyClass.Property)} ` どんどん長くなるだけなら良いけどクラス内クラスとか構造体の名前が + 付きの不正な状態で出てくる。その他にもジェネリッククラスへの対応とかなんとか、結局何かが必要になる。それならばと可能な限り短く書けるようにした。
240
-
241
- インデント系はトリッキーだけど開発機での実行なのでまあ良し。
242
-
243
- <!-- ----- End of Details JA Tag -------> </details ></p >
244
-
245
230
246
231
``` csharp
247
232
// indent utility
@@ -259,6 +244,23 @@ sb.IndentBegin("void MethodName() {");
259
244
sb .IndentEnd (" }" );
260
245
```
261
246
247
+
248
+ ` 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.
249
+
250
+
251
+ <p ><details lang =" ja " --open ><summary ><small >日本語 / JA</small ></summary >
252
+
253
+ ` System.Reflection ` 系のユーティリティーと ` StringBuilder ` の拡張メソッド群。
254
+
255
+ ` usg ` は特殊で、クラス名やら何やらのリファクタリングに強いジェネレーターにすると読みづらくなってしまうのを緩和するためのモノ。
256
+
257
+ ` {typeof(MyClass).FullName}.{nameof(MyClass.Property)} ` どんどん長くなるだけなら良いけどクラス内クラスとか構造体の名前が + 付きの不正な状態で出てくる。その他にもジェネリッククラスへの対応とかなんとか、結局何かが必要になる。それならばと可能な限り短く書けるようにした。
258
+
259
+ インデント系はトリッキーだけど開発機での実行なのでまあ良し。
260
+
261
+ <!-- ----- End of Details JA Tag -------> </details ></p >
262
+
263
+
262
264
``` csharp
263
265
using static SatorImaging .UnitySourceGenerator .USGFullNameOf ; // usg<T>() to work
264
266
@@ -279,6 +281,40 @@ usg(MyClass.Complex); // -> global::...Dictionary<int, global::...List<global::
279
281
280
282
281
283
284
+ Samples
285
+ =======
286
+
287
+ SceneBuildIndexGenerator
288
+ ------------------------
289
+
290
+ This sample allows you to handle scene index more efficiently.
291
+
292
+ To use this sample, add ` [UnitySourceGenerator(typeof(SceneBuildIndexGenerator))] ` attribute to your class. after that, you can use the following enum and helper methods.
293
+
294
+
295
+ - enum ` SceneBuildIndex `
296
+
297
+ - enum consists of scene file names which registered in build settings.
298
+ - easy to use with Unity inspector. note that class field doesn't track build index changes.
299
+
300
+ - static class ` SceneBuildIndexResolver `
301
+
302
+ - ` GetByName(string sceneFileNameWithoutExtension) `
303
+ - get build index by scene name or throws if scene is not found.
304
+ - this method ensures the scene must be included in build and also track build index changes.
305
+ ```csharp
306
+ // use like this in entry point to validate scene existence
307
+ SceneBuildIndex ImportantSceneIndex = SceneBuildIndexResolver.GetByName("Scene_Must_Be_Included_in_Build");
308
+ ```
309
+
310
+ - ` GetListByPrefix(string fileNamePrefix) `
311
+ - Get list of index which starts with prefix.
312
+
313
+ - ` GetListByPath(string assetsPath) `
314
+ - Path must be started with ** "Assets/"** .
315
+
316
+
317
+
282
318
Utility Functions for Build Event
283
319
=================================
284
320
@@ -292,11 +328,11 @@ There are utility functions to perform source code generation on build event.
292
328
293
329
294
330
``` csharp
295
- // perform code generation by class name if you don't know where it is.
296
- USGUtility .ForceGenerateByName ( nameof (MinimalGenerator ));
331
+ // generate code for specified generator type
332
+ USGUtility .ForceGenerateByType ( typeof (MinimalGenerator ));
297
333
298
- // perform code generation by known path.
299
- USGEngine . ProcessFile ( assetPath , true , true ); // force re-generate all related files
334
+ // or for the emitter type
335
+ USGUtility . ForceGenerateByType ( typeof ( ClassHasUSGAttribute ));
300
336
```
301
337
302
338
@@ -321,22 +357,22 @@ As of C# 9.0, it doesn't allow to define `abstract static` methods in interface,
321
357
322
358
## Naming Convention
323
359
324
- - Generator class name and filename must be matched.
325
- - Class name must be unique in whole project.
326
- - Classes are ignored if defined in assembly which name starts with:
327
- - ` Unity ` (no trailing dot)
328
- - ` System. `
329
- - ` Mono. `
360
+ - Generator/target class name and filename must be matched.
361
+ - ~~ Class name must be unique in whole project.~~
362
+ - ~~ Classes are ignored if defined in assembly which name starts with:~~
363
+ - ~~ ` Unity ` (no trailing dot)~~
364
+ - ~~ ` System. ` ~~
365
+ - ~~ ` Mono. ` ~~
330
366
331
367
332
368
<p ><details lang =" ja " --open ><summary ><small >日本語 / JA</small ></summary >
333
369
334
- - ジェネレータークラスの名前はファイル名と一致
335
- - ジェネレータクラスの名前はプロジェクト内で一意
336
- - クラスが以下で始まる名前のアセンブリで宣言されている場合は対象としない
337
- - ` Unity ` (末尾ドット無し)
338
- - ` System. `
339
- - ` Mono. `
370
+ - ジェネレーター・対象クラスの名前はファイル名と一致
371
+ - ~~ ジェネレータクラスの名前はプロジェクト内で一意~~
372
+ - ~~ クラスが以下で始まる名前のアセンブリで宣言されている場合は対象としない~~
373
+ - ~~ ` Unity ` (末尾ドット無し)~~
374
+ - ~~ ` System. ` ~~
375
+ - ~~ ` Mono. ` ~~
340
376
341
377
<!-- ----- End of Details JA Tag -------> </details ></p >
342
378
@@ -363,6 +399,7 @@ Unity Editor Integration
363
399
Use the following git URL in Unity Package Manager (UPM).
364
400
365
401
- Latest: https://github.com/sator-imaging/Unity-AltSourceGenerator.git
402
+ - v3.0.0: https://github.com/sator-imaging/Unity-AltSourceGenerator.git#v3.0.0
366
403
- v2.0.1: https://github.com/sator-imaging/Unity-AltSourceGenerator.git#v2.0.1
367
404
368
405
@@ -486,9 +523,16 @@ SOFTWARE.
486
523
487
524
# Devnote
488
525
489
-
490
526
## TODO
491
527
528
+ - ` GenerateOnce ` attribute parameter
529
+ - currently USG generates same class/enum multiple times when multiple classes refer enum/singleton generator.
530
+ - ex. ` SceneBuildIndex ` must be referred only once in project to avoid conflict
531
+ - v4: remove obsolete functions
532
+ - support C# 11 language features (waiting for Unity 6 update!!)
533
+ - see also: [ CHANGELOG] ( CHANGELOG.md#unreleased )
534
+
535
+
492
536
<!-- useless
493
537
- Add new attribute option `UseCustomWriter` to use it's own file writer instead of builtin writer. For the "non-allocation" addicted developers.
494
538
- `USGEngine.ProcessingFile()` doesn't care what happens in custom writer. just returns true in this situation.
@@ -497,16 +541,18 @@ SOFTWARE.
497
541
-->
498
542
499
543
544
+ <!--
500
545
Clarify terminology of generator types, especially in source code comments.
501
546
currently, referenced/referencing generator, or just generator, confusing!
502
547
503
548
- Generator class:
504
549
- Class has `Emit()` method to generate code. And does NOT have `UnitySourceGenerator` attribute.
505
550
- current -> "referenced" generator, "referenced only" generator, etc.
506
551
507
- - Emitter class: (or Target, Source, Client, Igniter, Invoker, Caller?)
552
+ - Target, or Emitter class:
508
553
- Class has `UnitySourceGenerator` attribute to invoke code generation. And does NOT have `Emit()` method.
509
554
- current -> "referencing" class, just generator, etc.
510
555
511
- - Self-Emit class:
556
+ - Self-Emit Generator (Self-Generator) class:
512
557
- Class has both `Emit()` method and `UnitySourceGenerator` attribute. Works only a file. No dependencies.
558
+ -->
0 commit comments