Jump to content
  • Advertisement
kenshen112

C# Questions regarding Items, Unity C#

Recommended Posts

So, i'm working on an Item system and I have a quick question in regards to Items.

I typically use a set of Json files to hold my data which is fine except for Items which can different variables as they do different things. The issue is that i'm using JSON.net which when deserializing a file will crash if the file doesn't match the structure it's trying to serialize. This means that if I want to define an item that affects speed I have to define several variables in that object that it's not even going to use making the whole thing a big mess.

My question is, is there a better file type to handle that data? or is there a better way to parse the JSON?

Share this post


Link to post
Share on other sites
Advertisement
Posted (edited)

If you have different classes for each different set of variables, you can just tell JSON.net to deserialize a different class.  What I do is put JSON files for each different class in a separate folder, loop over all files in each folder and have JSON.net deserialize using the type which is appropriate for every file in that folder.

Edited by Nypyren

Share this post


Link to post
Share on other sites

Along those lines, I'm trying to make a basic consumables class. So I have things like HPbuffer speed buffer strength buffer etc it's quite the list 

If I wanted to make a haste consumable then I have to list health else wise JSON.Net will have an issue that's what I'm trying to avoid

Share this post


Link to post
Share on other sites
Posted (edited)

What about writing your own JSON implementation? I did this mostly for performance reasons and portability from C++ to C# but it just took me only 3 files and a small ammount of lines to achieve the goal.

The other alternative is using ScriptableObject and create a single file "Database" of items that you instanciate at runtime from the file directly

Edited by Shaarigan

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!