2022-11-24 03:03:30 +01:00
|
|
|
using System;
|
2023-01-06 03:44:07 +01:00
|
|
|
using System.Linq;
|
2022-06-17 22:22:19 +02:00
|
|
|
using UnityEngine;
|
2022-11-19 17:02:31 +01:00
|
|
|
|
2022-06-17 22:22:19 +02:00
|
|
|
|
|
|
|
[System.Serializable]
|
2022-11-19 17:02:31 +01:00
|
|
|
public abstract class ItemData : ModelData<Item, Item>
|
2022-06-17 22:22:19 +02:00
|
|
|
{
|
2022-11-19 17:02:31 +01:00
|
|
|
[SerializeField]
|
2022-06-17 22:22:19 +02:00
|
|
|
public string description;
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
[SerializeField]
|
2022-06-17 22:22:19 +02:00
|
|
|
public int level;
|
|
|
|
|
2022-12-19 03:34:45 +01:00
|
|
|
[SerializeField]
|
|
|
|
public int value;
|
|
|
|
|
|
|
|
[SerializeField]
|
|
|
|
public int price;
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
[SerializeField]
|
2022-06-17 22:22:19 +02:00
|
|
|
public string imageName;
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
protected override string SPRITE_LOCALIZATION => "Sprites/Object Sprites/";
|
|
|
|
protected override string MODEL_LOCALIZATION => "Items/";
|
2022-06-17 22:22:19 +02:00
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
public ItemData(Item item) : base(item.id, item.name, item.itemModel.name)
|
2022-06-17 22:22:19 +02:00
|
|
|
{
|
|
|
|
description = item.description;
|
|
|
|
level = item.level;
|
2022-12-19 03:34:45 +01:00
|
|
|
value = item.value;
|
|
|
|
price = item.price;
|
2022-06-17 22:22:19 +02:00
|
|
|
imageName = item.image.name;
|
|
|
|
}
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
public override Item MapDataToObject(string prefarbAssetName)
|
2022-06-17 22:22:19 +02:00
|
|
|
{
|
2023-01-02 00:05:47 +01:00
|
|
|
/* Debug.Log(MODEL_LOCALIZATION + prefarbAssetName + ".asset"); */
|
2022-11-19 17:02:31 +01:00
|
|
|
|
|
|
|
return TryFindResource(prefarbAssetName);
|
2022-06-17 22:22:19 +02:00
|
|
|
|
|
|
|
///
|
|
|
|
// DONT OVERWRITE PROPERTIES BECOUSE ITS EDIT MAIN OBJECT IN ASSET/
|
|
|
|
///
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
// equippableItem.StrengthBonus = strengthBonus;
|
2022-12-29 00:58:03 +01:00
|
|
|
// equippableItem.EnduranceBonus = enduranceBonus;
|
2022-11-19 17:02:31 +01:00
|
|
|
// equippableItem.InteligenceBonus = inteligenceBonus;
|
|
|
|
// equippableItem.VitalityBonus = vitalityBonus;
|
|
|
|
// equippableItem.isStackable = isStackable;
|
|
|
|
// equippableItem.EquipmentTypeEnum = equipmentType;
|
2022-06-17 22:22:19 +02:00
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
// 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;
|
|
|
|
}
|
2022-06-17 22:22:19 +02:00
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
public override Item MapDataToObject()
|
|
|
|
{
|
|
|
|
return TryFindResource(modelName);
|
|
|
|
}
|
|
|
|
|
|
|
|
protected override Item TryFindResource(string modelName)
|
2023-01-06 14:50:12 +01:00
|
|
|
{
|
|
|
|
/* Debug.Log(MODEL_LOCALIZATION + modelName);
|
|
|
|
*/
|
|
|
|
|
|
|
|
Item resource = Resources.Load<EquippableItem>(MODEL_LOCALIZATION + modelName);
|
|
|
|
|
|
|
|
var modelNameWithoutWhitespace = String.Concat(modelName.Where(c => !Char.IsWhiteSpace(c)));
|
2022-11-24 03:03:30 +01:00
|
|
|
|
2023-01-06 03:44:07 +01:00
|
|
|
if (resource == null)
|
|
|
|
{
|
2023-01-06 14:50:12 +01:00
|
|
|
resource = Resources.Load<EquippableItem>(MODEL_LOCALIZATION + modelNameWithoutWhitespace);
|
2023-01-06 03:44:07 +01:00
|
|
|
|
|
|
|
if (resource == null)
|
2023-01-06 14:50:12 +01:00
|
|
|
{
|
|
|
|
resource = Resources.Load<Item>(MODEL_LOCALIZATION + modelName);
|
|
|
|
|
|
|
|
if (resource == null)
|
|
|
|
{
|
|
|
|
resource = Resources.Load<Item>(MODEL_LOCALIZATION + modelNameWithoutWhitespace);
|
|
|
|
}
|
|
|
|
}
|
2023-01-06 03:44:07 +01:00
|
|
|
}
|
2022-06-17 22:22:19 +02:00
|
|
|
|
2023-01-06 14:50:12 +01:00
|
|
|
if (resource == null)
|
|
|
|
throw new System.Exception($"Resource {modelName} not found!!");
|
|
|
|
|
2022-11-19 17:02:31 +01:00
|
|
|
return resource;
|
2022-06-17 22:22:19 +02:00
|
|
|
}
|
2022-11-19 17:02:31 +01:00
|
|
|
}
|