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 override void Select() { base.Select(); string Name = GetTitle().text; KnifeSettings settings = Data.Instance.GetKnifeSettings(Name); Manager.DescriptionLbl.text = settings.Description; }
public override void Fill(ScriptableObject obj) { KnifeSettings settings = obj as KnifeSettings; GetTitle().text = settings.Name; GetPrice().text = settings.knifeStats.Price.ToString(); Image img = GetImage(); img.sprite = settings.Sprite; Manager.DescriptionLbl.text = settings.Description; }
public void AddKnife(KnifeSettings settings) { AddToArray(ref Knives, settings); }