File tree Expand file tree Collapse file tree 2 files changed +18
-2
lines changed
Expand file tree Collapse file tree 2 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -27,6 +27,8 @@ public class CompilationModule
2727
2828 public HashSet < FieldDeclarationSyntax > fieldsWithInitializers ;
2929
30+ public ClassDefinition compiledClassDefinition = null ;
31+
3032 public int ErrorCount { get ; private set ; } = 0 ;
3133
3234 public CompilationModule ( UdonSharpProgramAsset sourceAsset )
@@ -133,6 +135,8 @@ public int Compile(List<ClassDefinition> classDefinitions)
133135
134136 if ( errorCount == 0 )
135137 {
138+ compiledClassDefinition = classDefinitions . Where ( e => e . userClassType == visitor . visitorContext . behaviourUserType ) . FirstOrDefault ( ) ;
139+
136140 Profiler . BeginSample ( "Build assembly" ) ;
137141 string dataBlock = BuildHeapDataBlock ( ) ;
138142 string codeBlock = visitor . GetCompiledUasm ( ) ;
Original file line number Diff line number Diff line change @@ -196,16 +196,28 @@ private int RunFieldInitalizers(CompilationModule[] compiledModules)
196196 bool isConst = fieldDeclarationSyntax . Modifiers . Any ( t => t . ToString ( ) == "const" ) ;
197197 foreach ( var variable in fieldDeclarationSyntax . Declaration . Variables )
198198 {
199+ FieldDefinition fieldDef = module . compiledClassDefinition ? . fieldDefinitions ? . Find ( e => ( e . fieldSymbol . declarationType == SymbolDeclTypeFlags . Private || e . fieldSymbol . declarationType == SymbolDeclTypeFlags . Public ) &&
200+ e . fieldSymbol . symbolOriginalName == variable . Identifier . ToString ( ) ) ;
201+
202+ string typeQualifiedName = type . ToString ( ) ;
203+ if ( fieldDef != null )
204+ {
205+ if ( fieldDef . fieldSymbol . symbolCsType . Namespace . Length == 0 )
206+ typeQualifiedName = fieldDef . fieldSymbol . symbolCsType . Name ;
207+ else
208+ typeQualifiedName = fieldDef . fieldSymbol . symbolCsType . Namespace + "." + fieldDef . fieldSymbol . symbolCsType . Name ;
209+ }
210+
199211 if ( variable . Initializer != null )
200212 {
201213 string name = variable . Identifier . ToString ( ) ;
202214 if ( isConst )
203215 {
204- _class . Members . Add ( new CodeSnippetTypeMember ( $ "const { type } { name } { variable . Initializer } ;") ) ;
216+ _class . Members . Add ( new CodeSnippetTypeMember ( $ "const { typeQualifiedName } { name } { variable . Initializer } ;") ) ;
205217 }
206218 else
207219 {
208- method . Statements . Add ( new CodeSnippetStatement ( $ "{ type } { name } { variable . Initializer } ;") ) ;
220+ method . Statements . Add ( new CodeSnippetStatement ( $ "{ typeQualifiedName } { name } { variable . Initializer } ;") ) ;
209221 }
210222
211223 method . Statements . Add ( new CodeSnippetStatement (
You can’t perform that action at this time.
0 commit comments