【发布时间】:2020-03-29 00:23:46
【问题描述】:
我有一个类,它有多个变量,这些变量都是通过 JSON 文本文件正确创建的,除了一个属于 Effects 类的枚举列表
下面的类总是将 effectedBy 列表中的枚举默认为元素 0
[System.Serializable]
public class InteractableObject : Item, IEffectReceiver
{
protected List<Stats> stats = new List<Stats>();
protected HashSet<Effects> currentEffects;
public List<Effects.EffectType> effectedBy = new List<Effects.EffectType>();
public GameObject destroyedPrefab;
private bool destructible = true;
private bool destroyed = false;
这是包含我要设置的枚举的类
[System.Serializable]
public class Effects
{
public bool usingEffect = false;
public int effectOverTimeChance = 0;
public EffectType effectType;
public Stats.StatType effectedStat = Stats.StatType.health;
public int minAmount;
public int maxAmount;
public enum EffectType
{
bleed,
electric,
fire,
heal,
physical,
poison
}
这是我的 JSON 文本,除了最后一个条目上的一个 enum effectedBy 之外,这一切都很好
{
"meleeWeapons": [
{
"id": 0,
"prefabID": "claw",
"title": "claw",
"description": "razor sharp claws",
"slotType": 4,
"effects": [
{
"effectType": 4,
"minAmount": 2,
"maxAmount": 4
}
]
},
{
"id": 1,
"title": "hammer",
"description": "heavy and intimidating",
"slotType": 4
}
],
"interactableObjects": [
{
"id": 2,
"prefabID": "BasicCrate",
"title": "crate",
"effectedBy": [
{
"effectType": 4
}
]
}
]
}
我可以通过将 effectedBy 更改为效果列表并将效果本身赋予我需要的枚举值来解决此问题,但如果可以的话,我宁愿将其保留为效果类型列表。 有人对此有任何见解吗?
【问题讨论】: