public static void CreateMaterial(string name) { var material = new EntityMaterial(); material.Name = name; try { InitializeFromXml(ref material, name); // create Materials[name] = material; // store } catch (XmlException e) { Debug.Log($"Warning: MaterialFactory could not create material [{name}]."); } }
private static void InitializeFromXml(ref EntityMaterial material, string name) { material.Hardness = _materialXmlReader.GetFloat(new List <string>() { name, HardnessField }); material.Restoration = _materialXmlReader.GetFloat(new List <string>() { name, RestorationField }); material.Flammability = _materialXmlReader.GetFloat(new List <string>() { name, FlammabilityField }); var damageTypes = Damages.DamageTypes; material.DamageMultipliers = new Damage[damageTypes.Count]; for (int i = 0; i < damageTypes.Count; i++) { var damageType = damageTypes[i]; // not all types of damage may be present in the xml defs; default fallback is unit (1.0) multiplier float multiplier = 1f; try { // try read damage type multipliers from xml file multiplier = _materialXmlReader.GetFloat( new List <string>() { name, DamageMultipliersField, Damages.DamageType2Str(damageType) } ); } catch (Exception e) { } material.DamageMultipliers[i] = new Damage(damageType, multiplier); } }