96 lines
2.7 KiB
C#
96 lines
2.7 KiB
C#
using System;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
|
|
|
|
[System.Serializable]
|
|
public abstract class ItemData : ModelData<Item, Item>
|
|
{
|
|
[SerializeField]
|
|
public string description;
|
|
|
|
[SerializeField]
|
|
public int level;
|
|
|
|
[SerializeField]
|
|
public int value;
|
|
|
|
[SerializeField]
|
|
public int price;
|
|
|
|
[SerializeField]
|
|
public string imageName;
|
|
|
|
protected override string SPRITE_LOCALIZATION => "Sprites/Object Sprites/";
|
|
protected override string MODEL_LOCALIZATION => "Items/";
|
|
|
|
public ItemData(Item item) : base(item.id, item.name, item.itemModel.name)
|
|
{
|
|
description = item.description;
|
|
level = item.level;
|
|
value = item.value;
|
|
price = item.price;
|
|
imageName = item.image.name;
|
|
}
|
|
|
|
public override Item MapDataToObject(string prefarbAssetName)
|
|
{
|
|
/* Debug.Log(MODEL_LOCALIZATION + prefarbAssetName + ".asset"); */
|
|
|
|
return TryFindResource(prefarbAssetName);
|
|
|
|
///
|
|
// DONT OVERWRITE PROPERTIES BECOUSE ITS EDIT MAIN OBJECT IN ASSET/
|
|
///
|
|
|
|
// equippableItem.StrengthBonus = strengthBonus;
|
|
// equippableItem.EnduranceBonus = enduranceBonus;
|
|
// equippableItem.InteligenceBonus = inteligenceBonus;
|
|
// equippableItem.VitalityBonus = vitalityBonus;
|
|
// equippableItem.isStackable = isStackable;
|
|
// equippableItem.EquipmentTypeEnum = equipmentType;
|
|
|
|
// Item item = base.MapDataToItem(prefarbAssetName);
|
|
// equippableItem.Name = item.Name;
|
|
// equippableItem.Description = item.Description;
|
|
// equippableItem.Level = item.Level;
|
|
// equippableItem.ItemModel = item.ItemModel;
|
|
// equippableItem.Image = item.Image;
|
|
}
|
|
|
|
public override Item MapDataToObject()
|
|
{
|
|
return TryFindResource(modelName);
|
|
}
|
|
|
|
protected override Item TryFindResource(string modelName)
|
|
{
|
|
/* Debug.Log(MODEL_LOCALIZATION + modelName);
|
|
*/
|
|
|
|
Item resource = Resources.Load<EquippableItem>(MODEL_LOCALIZATION + modelName);
|
|
|
|
var modelNameWithoutWhitespace = String.Concat(modelName.Where(c => !Char.IsWhiteSpace(c)));
|
|
|
|
if (resource == null)
|
|
{
|
|
resource = Resources.Load<EquippableItem>(MODEL_LOCALIZATION + modelNameWithoutWhitespace);
|
|
|
|
if (resource == null)
|
|
{
|
|
resource = Resources.Load<Item>(MODEL_LOCALIZATION + modelName);
|
|
|
|
if (resource == null)
|
|
{
|
|
resource = Resources.Load<Item>(MODEL_LOCALIZATION + modelNameWithoutWhitespace);
|
|
}
|
|
}
|
|
}
|
|
|
|
if (resource == null)
|
|
throw new System.Exception($"Resource {modelName} not found!!");
|
|
|
|
return resource;
|
|
}
|
|
}
|