public override void OnStart(StartState state) { StringCollectionParser parser = new StringCollectionParser(); parser.SetFromString(toggle); _toggle = parser; Type type = Parser.ModTypes.Find(t => t.Name == module && typeof(PartModule).IsAssignableFrom(t)); for (Int32 i = 0; i < part.Modules.Count; i++) { PartModule partModule = part.Modules[i]; if (!type.IsInstanceOfType(partModule)) { continue; } BaseField field = partModule.Fields[key]; String fieldValue = field.GetValue(partModule).ToString(); if (fieldValue != value) { continue; } _targetModule = partModule; break; } }
public override void OnStart(StartState state) { StringCollectionParser parser = new StringCollectionParser(); //Comma seperated list parser.SetFromString(toggle); //Actions to be triggered _toggle = parser; //list of actions //Find a Type where the name matches the targeted PartModule and the module is assignable from the assembly t Type type = Parser.ModTypes.Find(t => t.Name == module && typeof(PartModule).IsAssignableFrom(t)); for (Int32 i = 0; i < part.Modules.Count; i++) //Iterate through all modules on this part { PartModule partModule = part.Modules[i]; //if type is not an instance of this partmodule, skip the rest of this block and continue the loop if (!type.IsInstanceOfType(partModule)) { continue; } BaseField field = partModule.Fields[key]; //field = the field named the same as key String fieldValue = field.GetValue(partModule).ToString(); //get the value of that field if (fieldValue != value) //if that value isnt what we want, continue { continue; } _targetModule = partModule; //we found the right module break; //stop the loop } }