Skip to content

Commit 12ffe24

Browse files
committed
v3.0.0
1 parent e4bfd59 commit 12ffe24

File tree

3 files changed

+116
-51
lines changed

3 files changed

+116
-51
lines changed

CHANGELOG.md

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,29 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

88

9-
## [Unreleased]
9+
## [Unreleased](https://github.com/sator-imaging/Unity-AltSourceGenerator)
1010

11+
- nothing yet
12+
13+
14+
15+
## [3.0.0](https://github.com/sator-imaging/Unity-AltSourceGenerator/releases/tag/v3.0.0)
16+
17+
18+
### API Changes 😉
19+
20+
#### `USGEngine.ProcessFile()` will be removed
21+
22+
use `USGUtility.ForceGenerateByType(typeof(...))` instead.
23+
24+
#### `USGUtility.**ByName()` will be removed
25+
26+
methods still exist but obsolete. use `USGUtility.**ByType()` instead.
27+
28+
29+
30+
## [2.0.0](https://github.com/sator-imaging/Unity-AltSourceGenerator/releases/tag/v2.0.0)
1131

12-
## [2.0.0]()
1332

1433
### Breaking Changes ;-)
1534

@@ -26,7 +45,7 @@ now private. use `ProcessFile(path, *true*)` instead.
2645

2746
`showInProjectPanel` now false by default.
2847

29-
#### usg<T>(params string[] memberNames)
48+
#### usg\<T>(params string[] memberNames)
3049

3150
`global::` namespace will be added.
3251

README.md

Lines changed: 93 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -19,24 +19,24 @@ As you already know, Roslyn's source generator is too sophisticated. This framew
1919
<!------- End of Details JA Tag -------></details></p>
2020

2121

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)
2326

2427

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>
2829

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)
3331
- [Method Generator](#method-generator)
34-
- [How to Use](#how-to-use)
32+
- [How to Generate Source Code](#how-to-generate-source-code)
3533
- [Result](#result)
3634
- [Self-Emit Generator](#self-emit-generator)
3735
- [Result](#result-1)
3836
- [Output Directory and File Name](#output-directory-and-file-name)
3937
- [Coding Goodies](#coding-goodies)
38+
- [Samples](#samples)
39+
- [SceneBuildIndexGenerator](#scenebuildindexgenerator)
4040
- [Utility Functions for Build Event](#utility-functions-for-build-event)
4141
- [Technical Notes](#technical-notes)
4242
- [Naming Convention](#naming-convention)
@@ -57,8 +57,8 @@ As you already know, Roslyn's source generator is too sophisticated. This framew
5757

5858

5959

60-
Sample Code
61-
===========
60+
How to Use
61+
==========
6262

6363
Here is minimal implementation of source generator.
6464

@@ -107,7 +107,7 @@ namespace {context.TargetClass.Namespace}
107107

108108

109109

110-
### How to Use
110+
### How to Generate Source Code
111111

112112

113113
```csharp
@@ -221,27 +221,12 @@ There are utility methods for coding source generator more efficient and readabl
221221
- `IndentLevel` / `IndentChar` / `IndentSize`
222222
- `USGFullNameOf`
223223
- `usg`
224-
- `USGReflection`
224+
- `USGReflection` <sub><sup>* can be used on Unity runtime</sup></sub>
225225
- `GetAllPublicInstanceFieldAndProperty`
226226
- `TryGetFieldOrPropertyType`
227227
- `GetEnumNamesAndValuesAsDictionary`
228228
- `GetEnumNamesAndValuesAsTuple`
229229

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-
245230

246231
```csharp
247232
// indent utility
@@ -259,6 +244,23 @@ sb.IndentBegin("void MethodName() {");
259244
sb.IndentEnd("}");
260245
```
261246

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+
262264
```csharp
263265
using static SatorImaging.UnitySourceGenerator.USGFullNameOf; // usg<T>() to work
264266
@@ -279,6 +281,40 @@ usg(MyClass.Complex); // -> global::...Dictionary<int, global::...List<global::
279281

280282

281283

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+
282318
Utility Functions for Build Event
283319
=================================
284320

@@ -292,11 +328,11 @@ There are utility functions to perform source code generation on build event.
292328

293329

294330
```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));
297333

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));
300336
```
301337

302338

@@ -321,22 +357,22 @@ As of C# 9.0, it doesn't allow to define `abstract static` methods in interface,
321357

322358
## Naming Convention
323359

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.`~~
330366

331367

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

334-
- ジェネレータークラスの名前はファイル名と一致
335-
- ジェネレータクラスの名前はプロジェクト内で一意
336-
- クラスが以下で始まる名前のアセンブリで宣言されている場合は対象としない
337-
- `Unity` (末尾ドット無し)
338-
- `System.`
339-
- `Mono.`
370+
- ジェネレーター・対象クラスの名前はファイル名と一致
371+
- ~~ジェネレータクラスの名前はプロジェクト内で一意~~
372+
- ~~クラスが以下で始まる名前のアセンブリで宣言されている場合は対象としない~~
373+
- ~~`Unity` (末尾ドット無し)~~
374+
- ~~`System.`~~
375+
- ~~`Mono.`~~
340376

341377
<!------- End of Details JA Tag -------></details></p>
342378

@@ -363,6 +399,7 @@ Unity Editor Integration
363399
Use the following git URL in Unity Package Manager (UPM).
364400

365401
- Latest: https://github.com/sator-imaging/Unity-AltSourceGenerator.git
402+
- v3.0.0: https://github.com/sator-imaging/Unity-AltSourceGenerator.git#v3.0.0
366403
- v2.0.1: https://github.com/sator-imaging/Unity-AltSourceGenerator.git#v2.0.1
367404

368405

@@ -486,9 +523,16 @@ SOFTWARE.
486523

487524
# Devnote
488525

489-
490526
## TODO
491527

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+
492536
<!-- useless
493537
- Add new attribute option `UseCustomWriter` to use it's own file writer instead of builtin writer. For the "non-allocation" addicted developers.
494538
- `USGEngine.ProcessingFile()` doesn't care what happens in custom writer. just returns true in this situation.
@@ -497,16 +541,18 @@ SOFTWARE.
497541
-->
498542

499543

544+
<!--
500545
Clarify terminology of generator types, especially in source code comments.
501546
currently, referenced/referencing generator, or just generator, confusing!
502547
503548
- Generator class:
504549
- Class has `Emit()` method to generate code. And does NOT have `UnitySourceGenerator` attribute.
505550
- current -> "referenced" generator, "referenced only" generator, etc.
506551
507-
- Emitter class: (or Target, Source, Client, Igniter, Invoker, Caller?)
552+
- Target, or Emitter class:
508553
- Class has `UnitySourceGenerator` attribute to invoke code generation. And does NOT have `Emit()` method.
509554
- current -> "referencing" class, just generator, etc.
510555
511-
- Self-Emit class:
556+
- Self-Emit Generator (Self-Generator) class:
512557
- Class has both `Emit()` method and `UnitySourceGenerator` attribute. Works only a file. No dependencies.
558+
-->

package.json

Lines changed: 1 addition & 1 deletion
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": "2.0.1",
4+
"version": "3.0.0",
55
"unity": "2021.3",
66
"description": "Ease-of-Use Source Generator Alternative for Unity.",
77
"author": {

0 commit comments

Comments
 (0)