Hey everybody,
I am building an dynamic item system in unity.I’ll quickly explain what im tying to do.
Your items can have different parameters like, rarity, weapontype etc… Before you can create any items, you have to setup your parameters in the editor. Here I want people to be able to make for example a parameter called rarity and here they can assing a enum. (You can’t dynamicly store classes in C# so here’s a problem). or adding a parameter called itemname being a string, where they can input there text. They select the type via an enum, so they can shoose one of the suported types for each parameter. Now my question is how can I overcome the enum problem? What shoud be a different way to do it?
Regards,
Zoteygamer
It sounds like you might be best off storing your data in something that supports dynamic types, dictionaries, and arbitrary creation of new fields and values. I strongly suspect that you want to be able to save this out to a file at some point, too.
When described this way, it matches the description of JSON pretty precisely. Unity has a built in JSONSerializer, but it has some limitations. Normally in Unity people just want to grab the JSON and map it directly onto an object, but you want to be able to add arbitrary fields, so you’d be better off accessing the JSON data directly. If you can grab the LitJSON plugin, I think that may be the class you want to use here.
Well, actually I wrote a json framework right before this to use with unity. So I was thinking I could use a generic type and let the user select the type and then pass the right type into the generic, wich would just work fine. But not when I want to use an enum because you can’t store an enum in a variable, or can you?
In each case thanks for the answer.