Looking for advice on storing instantiation parameters

Hello, I’m trying to figure out how I should best store information (using C#) to use during instantiation of a prefab or a weapon or item. Originally I thought XML, but am not sure if that is the best option (I know the basics of XML, only).

The information for each item I’m looking to store is similar to this:

  • Name: “Butter Knife”
  • WeaponType: “Dagger”
  • DamageType: “Stabbing”
  • Named: false
  • BaseDamage: 5
  • CritChance: 15

Etc. I’ve figured out how to pull this information into an instantiation call, so I just need to figure out how to get this out of a file.

My goal is to be able to write functions along the lines of ‘generate random dagger’ or ‘generate random stabbing type weapon’, so I’m also looking for a way to get handles on this information. I assume no matter where I store the information, I will need to put it all into some kind of index.

I don’t want to hard code this, but keep it in another file for ease of access and editing. Could anyone point me in the right direction or give me some ideas? I’ll be honest, my searches are mostly coming up with information on inventory systems overall, so I’m not finding much.

Thanks for your time!

Normal C# StreamReader and F.ReadLine() work just fine. You can hand-edit weapons.txt (it goes in the top folder, next to Assets and Library, then just read it in Start.

You can put things 1/line – in other words, you just know each weapon has 8 lines with name, min, max, speed … . That’s simple to code.

If you want to make it easier for the person entering data, you can have the reader parse it. Say you want a line to be “Normal Damage: 3-8”. You can use w.FindFirstOf(':'), w.Substring and w.Trim to pull out those two numbers. Can even check the stuff before the “:” then print something like “ERR: expected Normal Damage, got Armour Slice”.

If you are really cool, you can write a normal C# VisualStudio program to write the file (use the exact same C# code from Unity to read it, then enter data in textBoxes and dropDowns. That way anyone can enter/edit weapon data. They won’t need to know the special format, and you can store it 1 number/line to make reading easier.