File tree Expand file tree Collapse file tree 1 file changed +12
-2
lines changed
MLAPI/MonoBehaviours/Core Expand file tree Collapse file tree 1 file changed +12
-2
lines changed Original file line number Diff line number Diff line change @@ -680,7 +680,8 @@ internal void SyncVarInit()
680
680
if ( syncVarInit )
681
681
return ;
682
682
syncVarInit = true ;
683
- FieldInfo [ ] sortedFields = GetType ( ) . GetFields ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . FlattenHierarchy | BindingFlags . Instance ) . OrderBy ( x => x . Name ) . ToArray ( ) ;
683
+
684
+ FieldInfo [ ] sortedFields = GetFieldInfoForType ( GetType ( ) ) ;
684
685
for ( int i = 0 ; i < sortedFields . Length ; i ++ )
685
686
{
686
687
if ( sortedFields [ i ] . IsDefined ( typeof ( SyncedVar ) , true ) )
@@ -931,13 +932,22 @@ private bool SetDirtyness()
931
932
private readonly List < HashSet < int > > channelMappedVarIndexes = new List < HashSet < int > > ( ) ;
932
933
private readonly List < string > channelsForVarGroups = new List < string > ( ) ;
933
934
internal readonly List < INetworkedVar > networkedVarFields = new List < INetworkedVar > ( ) ;
935
+ private static readonly Dictionary < Type , FieldInfo [ ] > fieldTypes = new Dictionary < Type , FieldInfo [ ] > ( ) ;
936
+
937
+ private static FieldInfo [ ] GetFieldInfoForType ( Type type )
938
+ {
939
+ if ( ! fieldTypes . ContainsKey ( type ) )
940
+ fieldTypes . Add ( type , type . GetFields ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . FlattenHierarchy | BindingFlags . Instance ) . OrderBy ( x => x . Name ) . ToArray ( ) ) ;
941
+ return fieldTypes [ type ] ;
942
+ }
943
+
934
944
internal void NetworkedVarInit ( )
935
945
{
936
946
if ( networkedVarInit )
937
947
return ;
938
948
networkedVarInit = true ;
939
949
940
- FieldInfo [ ] sortedFields = GetType ( ) . GetFields ( BindingFlags . Public | BindingFlags . NonPublic | BindingFlags . FlattenHierarchy | BindingFlags . Instance ) . OrderBy ( x => x . Name ) . ToArray ( ) ;
950
+ FieldInfo [ ] sortedFields = GetFieldInfoForType ( GetType ( ) ) ;
941
951
for ( int i = 0 ; i < sortedFields . Length ; i ++ )
942
952
{
943
953
Type fieldType = sortedFields [ i ] . FieldType ;
You can’t perform that action at this time.
0 commit comments