Scriptum/Assets/Scripts/REFACTORING/Models/Chest/ChestData.cs

65 lines
1.9 KiB
C#

using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
[System.Serializable]
public class ChestData : ModelData<Chest, GameObject>
{
[SerializeField]
public string description;
[SerializeField]
public ChestTypeEnum type;
[SerializeField]
public List<IndexValuePair<EquippableItemData>> content = new List<IndexValuePair<EquippableItemData>>();
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> item in chest.Content)
{
content.Add(
new IndexValuePair<EquippableItemData>(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<EquippableItemData> item in content)
{
chest.Content.Add(
new IndexValuePair<Item>(item.Key, item.Value.MapDataToObject())
);
}
return chest;
}
public override Chest MapDataToObject(string prefarbAssetName) { throw new System.NotImplementedException(); }
protected override GameObject TryFindResource(string modelName)
{
var resource = Resources.Load<GameObject>(MODEL_LOCALIZATION + modelName);
if (!resource)
throw new System.Exception($"Resource {modelName} not found!!");
return resource;
}
}