void FromJsonToObjects(string json) { string[] objects = json.Split(objSeperators, System.StringSplitOptions.RemoveEmptyEntries); for (int i = 0; i < objects.Length; i++) { string[] objectParts = objects[i].Split('|'); string Type = objectParts[0]; string Name = objectParts[1]; string Description = objectParts[2]; string ImgUrl = objectParts[3]; string Object = objectParts[4]; print("Type: " + Type); print("Name: " + Name); print("Description: " + Description); print("ImgUrl: " + ImgUrl); print("objecet: " + Object); Sprite spriteFromUrl = GetSprite(ImgUrl, value => spriteFromUrl = value); switch (Type) { case "Gun": GunStats gunStats = JsonUtility.FromJson <GunStats>(Object); GunSettings gun = ScriptableObject.CreateInstance <GunSettings>(); gun.Fill(gunStats, Name, Description); gun.Sprite = spriteFromUrl; Data.Instance.AddGun(gun); break; case "Vest": VestStats vestStats = JsonUtility.FromJson <VestStats>(Object); VestSettings vest = ScriptableObject.CreateInstance <VestSettings>(); vest.Sprite = spriteFromUrl; vest.Fill(Name, Description, vestStats); Data.Instance.AddVest(vest); break; case "Knife": KnifeStats knifeStats = JsonUtility.FromJson <KnifeStats>(Object); KnifeSettings knife = ScriptableObject.CreateInstance <KnifeSettings>(); knife.Fill(knifeStats, Name, Description); knife.Sprite = spriteFromUrl; Data.Instance.AddKnife(knife); break; case "Grenade": GrenadeStats grenadeStats = JsonUtility.FromJson <GrenadeStats>(Object); GrenadeSettings grenade = ScriptableObject.CreateInstance <GrenadeSettings>(); grenade.Fill(grenadeStats, Name, Description); grenade.Sprite = spriteFromUrl; Data.Instance.AddGrenade(grenade); break; default: Debug.Log("Unrecognised item type"); break; } } itemsLoaded = true; }
public void Fill(string name, string description, VestStats vestStats) { Name = name; Description = description; this.vestStats = vestStats; }