Я толкаю документацию, но я также хочу охватить каждого, чтобы вы все, если есть известное решение моей проблемы или потери JSON в разные классы.[
{
"id": "sword",
"viewModelId": "sword_01",
"itemType": "Weapon",
"damage": "1d10"
},
{
"id": "shield",
"viewModelId": "shield_02",
"itemType": "Armour", // Fixed, thank you Yong
"armour": "3"
}
]
< /code>
У меня есть класс, охватывающий концепцию элементов < /p>
[System.Serializable]
public class Item
{
public string id;
public string viewModelId;
}
< /code>
и один из каждого из itemtypes < /p>
[System.Serializable]
public class Weapon : Item
{
public string damage;
}
< /code>
[System.Serializable]
public class Armour : Item
{
public int armour;
}
< /code>
Figuring this out is important to me because down the line I will want potions, and scrolls, and tools, and treasure, and so on and so forth. I'd like to not handle this with one big Item Class, but instead Subclasses I can add ItemType specific variables and methods into.
I am also open to alternative approaches, like breaking up each ItemType. That is a file for Weapons, a file for Armor, a file for etc.
Thanks
Подробнее здесь: https://stackoverflow.com/questions/797 ... nt-classes