public static (List <FieldDefinition> syncVars, Dictionary <FieldDefinition, FieldDefinition> syncVarNetIds) ProcessSyncVars(TypeDefinition td) { List <FieldDefinition> syncVars = new List <FieldDefinition>(); Dictionary <FieldDefinition, FieldDefinition> syncVarNetIds = new Dictionary <FieldDefinition, FieldDefinition>(); // the mapping of dirtybits to sync-vars is implicit in the order of the fields here. this order is recorded in m_replacementProperties. // start assigning syncvars at the place the base class stopped, if any int dirtyBitCounter = Editor.Weaver.Weaver.WeaveLists.GetSyncVarStart(td.BaseType.FullName); // find syncvars foreach (FieldDefinition fd in td.Fields) { if (fd.HasCustomAttribute <SyncVarAttribute>()) { if ((fd.Attributes & FieldAttributes.Static) != 0) { Editor.Weaver.Weaver.Error($"{fd.Name} cannot be static", fd); continue; } if (fd.FieldType.IsArray) { Editor.Weaver.Weaver.Error($"{fd.Name} has invalid type. Use SyncLists instead of arrays", fd); continue; } if (SyncObjectInitializer.ImplementsSyncObject(fd.FieldType)) { Editor.Weaver.Weaver.Warning($"{fd.Name} has [SyncVar] attribute. SyncLists should not be marked with SyncVar", fd); } else { syncVars.Add(fd); ProcessSyncVar(td, fd, syncVarNetIds, 1L << dirtyBitCounter); dirtyBitCounter += 1; if (dirtyBitCounter == SyncVarLimit) { Editor.Weaver.Weaver.Error($"{td.Name} has too many SyncVars. Consider refactoring your class into multiple components", td); continue; } } } } // add all the new SyncVar __netId fields foreach (FieldDefinition fd in syncVarNetIds.Values) { td.Fields.Add(fd); } Editor.Weaver.Weaver.WeaveLists.SetNumSyncVars(td.FullName, syncVars.Count); return(syncVars, syncVarNetIds); }
static void ProcessSyncVars(TypeDefinition td) { // find syncvars foreach (FieldDefinition fd in td.Fields) { if (fd.HasCustomAttribute <SyncVarAttribute>()) { Editor.Weaver.Weaver.Error($"SyncVar {fd.Name} must be inside a NetworkBehaviour. {td.Name} is not a NetworkBehaviour", fd); } if (SyncObjectInitializer.ImplementsSyncObject(fd.FieldType)) { Editor.Weaver.Weaver.Error($"{fd.Name} is a SyncObject and must be inside a NetworkBehaviour. {td.Name} is not a NetworkBehaviour", fd); } } }