void Start() { instance = this; var fileParts = LoadPartsFromFile(); if (fileParts == null) { Debug.Log("Using default parts"); weaponParts = new List <WeaponPart>(); for (int i = 0; i < defaultWeaponParts.Count; i++) { weaponParts.Add(WeaponParts.GetPart(defaultWeaponParts[i].partShortCode)); weaponParts[i].level = defaultWeaponParts[i].level; weaponParts[i].quality = Qualities.GetQuality(defaultWeaponParts[i].quality); } } else { weaponParts = fileParts.ToList(); } var fileWeapons = LoadWeaponsFromFile(); if (fileWeapons == null) { Debug.Log("Using default weapons"); weapons = defaultWeapons; } else { weapons = fileWeapons.ToList(); } }
public WeaponPart[] LoadPartsFromFile() { var partData = LoadFromFile <WeaponPartData[]>("parts"); if (partData == null) { return(null); } var parts = new WeaponPart[partData.Length]; for (int i = 0; i < partData.Length; i++) { parts[i] = WeaponParts.GetPart(partData[i].partShortCode); parts[i].level = partData[i].level; parts[i].quality = Qualities.GetQuality(partData[i].quality); } return(parts); }
void LoadPart(ref WeaponPartSlot slot, WeaponPartData wpd) { if (wpd.partShortCode == "") { return; } var loadedPart = WeaponParts.GetPart(wpd.partShortCode); loadedPart.level = wpd.level; loadedPart.quality = Qualities.GetQuality(wpd.quality); slot.SetPart(loadedPart); for (int i = 0; i < wpd.dataParts.Length; i++) { var childSlot = loadedPart.slots[i]; var childData = wpd.dataParts[i]; LoadPart(ref childSlot, childData); } }