Scriptum/Assets/Scripts/REFACTORING/Models/Item/EquippableItem/EquippableItemData.cs

113 lines
3.2 KiB
C#

using System;
using System.Linq;
using UnityEngine;
[System.Serializable]
public class EquippableItemData : ItemData
{
[SerializeField]
public int strengthBonus;
[SerializeField]
public int enduranceBonus;
[SerializeField]
public int inteligenceBonus;
[SerializeField]
public int vitalityBonus;
[SerializeField]
public int speedBonus;
[SerializeField]
public bool isStackable;
[SerializeField]
public EquipmentTypeEnum equipmentType;
public EquippableItemData(EquippableItem equippableItem) : base(equippableItem)
{
strengthBonus = equippableItem.StrengthBonus;
enduranceBonus = equippableItem.EnduranceBonus;
inteligenceBonus = equippableItem.InteligenceBonus;
vitalityBonus = equippableItem.VitalityBonus;
speedBonus = equippableItem.SpeedBonus;
isStackable = equippableItem.isStackable;
equipmentType = equippableItem.EquipmentType;
}
public EquippableItemData(Item item) : base(item)
{
strengthBonus = 0;
enduranceBonus = 0;
inteligenceBonus = 0;
vitalityBonus = 0;
speedBonus = 0;
isStackable = true;
equipmentType = EquipmentTypeEnum.Other;
}
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;
}
}