Scriptum/Assets/Scripts/REFACTORING/Models/Mission/RequiredSubject/KillRequiredSubjectData.cs
2023-01-03 22:44:24 +01:00

78 lines
2.7 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using UnityEngine;
[Serializable]
/*[TypeConverter(typeof(KillRequiredSubjectDataTypeConverter))]
*/public class KillRequiredSubjectData : RequiredSubjectData
{
protected override string MODEL_LOCALIZATION => "Enemies/";
[SerializeField]
public int CurrentAmount = 0;
public KillRequiredSubjectData(int requiredAmount, string requiredObjectName) : base(requiredAmount, requiredObjectName) { }
public KillRequiredSubjectData(int requiredAmount, string requiredObjectName, int currentAmount) : base(requiredAmount, requiredObjectName)
{
CurrentAmount = currentAmount;
}
public KillRequiredSubjectData(int requiredAmount, int currentAmount) : base(requiredAmount) { CurrentAmount = currentAmount; }
public KillRequiredSubjectData(KillRequiredSubject requiredSubject) : base(requiredSubject) { CurrentAmount = requiredSubject.CurrentAmount; }
public override RequiredSubject MapDataToObject(string prefarbAssetName)
{
var newKillRequirement = new KillRequiredSubject(RequiredAmount, CurrentAmount);
newKillRequirement.RequiredObject = newKillRequirement.FindObjectInResource(prefarbAssetName);
return newKillRequirement;
}
public override RequiredSubject MapDataToObject()
{
return new KillRequiredSubject(RequiredAmount, RequiredObjectName, CurrentAmount);
}
}
/*[TypeConverter(typeof(KillRequiredSubjectDataTypeConverter))]
public class KillRequiredSubjectDataTypeConverter : TypeConverter
{
public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
{
return sourceType == typeof(RequiredSubjectData<RequiredSubject>) || base.CanConvertFrom(context, sourceType);
}
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
{
var castedFrom = value as RequiredSubjectData<RequiredSubject>;
return castedFrom != null
? new KillRequiredSubjectData(castedFrom.RequiredAmount, castedFrom.RequiredObjectName)
: base.ConvertFrom(context, culture, value)
;
}
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
{
var castedTo = value as KillRequiredSubjectData;
return destinationType == typeof(RequiredSubjectData<RequiredSubject>) && castedTo != null
? new RequiredSubjectData<RequiredSubject>(castedTo.RequiredAmount, castedTo.RequiredObjectName)
: base.ConvertTo(context, culture, value, destinationType)
;
}
}*/