File tree Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Expand file tree Collapse file tree 4 files changed +23
-7
lines changed Original file line number Diff line number Diff line change @@ -195,6 +195,8 @@ public static bool ProcessFile(string assetsRelPath)
195
195
if ( ! isSaveFile || sb == null || string . IsNullOrWhiteSpace ( context . OutputPath ) )
196
196
return false ;
197
197
198
+ // NOTE: overwrite check must be done after Emit() due to allowing output path modification.
199
+ // TODO: code generation happens but file is not written. any way to skip code generation?
198
200
if ( File . Exists ( context . OutputPath ) &&
199
201
( ! info . Attribute . OverwriteIfFileExists && ! IgnoreOverwriteSettingByAttribute )
200
202
)
Original file line number Diff line number Diff line change @@ -26,15 +26,29 @@ static void ForceGenerateSelectedScripts()
26
26
}
27
27
28
28
29
- ///<summary>UNSAFE on use in build event due to this method calls fancy UI methods and fire import event. Use `GetAssetPathByName()` instead.</summary>
30
- public static void ForceGenerateInEditor ( string clsName , bool showInProjectPanel = true )
29
+ ///<summary>Force perform source code generation by class name.</summary>
30
+ ///<param name="showInProjectPanel">works only when Unity is not building app.</param>
31
+ public static void ForceGenerateByName ( string clsName , bool showInProjectPanel = true )
31
32
{
32
33
var path = GetAssetPathByName ( clsName ) ;
33
34
if ( path == null ) return ;
34
35
36
+
37
+ USGEngine . IgnoreOverwriteSettingByAttribute = true ; // always disabled after import event.
38
+
39
+ // NOTE: Invoking unity editor event while building app causes fatal error.
40
+ // just generate code and not need to import it.
41
+ if ( BuildPipeline . isBuildingPlayer )
42
+ {
43
+ USGEngine . ProcessFile ( path ) ;
44
+ return ;
45
+ }
46
+
47
+ // NOTE: When working in Unity Editor, Do NOT perform ProcessFile(...).
48
+ // It will generate code correctly but generated source code is not imported.
49
+ // To see changes, you need to import script and as you imagine, code generation happens again.
35
50
if ( showInProjectPanel )
36
51
EditorGUIUtility . PingObject ( AssetDatabase . LoadAssetAtPath < Object > ( path ) ) ;
37
- USGEngine . IgnoreOverwriteSettingByAttribute = true ; // always disabled after import event.
38
52
AssetDatabase . ImportAsset ( path ) ;
39
53
}
40
54
Original file line number Diff line number Diff line change @@ -208,10 +208,10 @@ There are utility functions to perform source code generation on build event.
208
208
209
209
210
210
``` csharp
211
- // search by class name if you don't know where it is.
212
- var assetPath = USGUtility .GetAssetPathByName (nameof (MinimalGenerator ));
211
+ // perform code generation by class name if you don't know where it is.
212
+ USGUtility .ForceGenerateByName (nameof (MinimalGenerator ));
213
213
214
- // perform code generation.
214
+ // perform code generation by known path .
215
215
USGEngine .IgnoreOverwriteSettingByAttribute = true ; // force overwrite
216
216
USGEngine .ProcessFile (assetPath );
217
217
```
Original file line number Diff line number Diff line change 1
1
{
2
2
"name" : " com.sator-imaging.alt-source-generator" ,
3
3
"displayName" : " Alternative Source Generator for Unity" ,
4
- "version" : " 1.2.0 " ,
4
+ "version" : " 1.2.1 " ,
5
5
"unity" : " 2021.3" ,
6
6
"description" : " Ease-of-Use Source Generator Alternative for Unity." ,
7
7
"author" : {
You can’t perform that action at this time.
0 commit comments