using System.Collections.Generic; using UnityEditor; using UnityEngine; [System.Serializable] public class ChestData : ModelData { [SerializeField] public string description; [SerializeField] public ChestTypeEnum type; [SerializeField] public List> content = new List>(); protected override string SPRITE_LOCALIZATION => "Sprites/Object Sprites/"; protected override string MODEL_LOCALIZATION => "Chests/"; public ChestData(Chest chest) : base(chest.id, chest.name, chest.chestModel.name) { description = chest.description; foreach(IndexValuePair item in chest.Content) { content.Add( new IndexValuePair(item.Key, new EquippableItemData(item.Value)) ); } } // dont use parameter - chest is not scriptable object, dont have its model in Assets public override Chest MapDataToObject() { // 1. Find object GameObject chestGameObject = TryFindResource(modelName); var chest = new Chest(name, description, chestGameObject, type); // 2. Set chest content from passed data chest.Content.Clear(); foreach (IndexValuePair item in content) { var castedObject = item.Value.MapDataToObject() as EquippableItem; if(castedObject == null) chest.Content.Add( new IndexValuePair(item.Key, new EquippableItem(item.Value.MapDataToObject())) ); else chest.Content.Add( new IndexValuePair(item.Key, castedObject) ); } return chest; } public override Chest MapDataToObject(string prefarbAssetName) { throw new System.NotImplementedException(); } protected override GameObject TryFindResource(string modelName) { var resource = Resources.Load(MODEL_LOCALIZATION + modelName); if (!resource) throw new System.Exception($"Resource {modelName} not found!!"); return resource; } }