Hello,
I’m working on a game that will allow the player to modify and create new objects (enemies, weapons, levels, etc) without the use of Unity.
For that, I need to store data (weapon stats, damage, range and such, for example) externally, in a human readable format, the latter is very important because I want players to be able to create modifications using only Notepad.
I started by creating my own parser but it turned out to be incredibly rough (it does work though) and before I start polishing it I would like to know if there’s already a way to include a simple (but effective) parser in Unity?
That would save me a lot of time.
I would prefer a JS library but anything accessible from JS work as well (.net for example).
Thanks.
Yes XML is incredibly useful. The website GamePrefabs.com has a unity package on it called “Achievements System”. I came across it the other day and got my parents to buy it. It contains an XML file, where data is stored and can be edited. I have made my own code using that example. It includes very nice UI, and it can be tweaked to store any data.
If you need it, I can give you the code.
USE XML ! (sorry for screaming)
xml is the most useful format for storing such kind of data.
Building an xml parser is easy, done it myself multiple times.
And before the OP runs off to write their own XML parser, until you get everything running just fine, use the built-in .NET XML parser library or one of the free and very good open source libraries that you can get up and running with in just a few minutes.
Yes, it will add a large amount of bytes to your build but until you need to ship your game, it’s not worth worrying about. Premature optimisation and all that. Get it working first, don’t start worrying about making things faster, smaller, cheaper until you need to.
Yes, thanks for advice. I already started converting my code for XML and even managed to get .NET XML serializer to work quite fast.
Reading/Writing a whole class full of variables with a couple of simple lines of code is awesome.
Don’t forget, if you have a class or struct, you can literally load the XML in with a single line of code so long as the XML matches your class or struct. If you want to get super-fancy with your XML layout, check out YaxLib, which is what I use most of the time, that permits all sorts of crazy formatting.
That’s exactly what I’m doing right now and it’s amazing, solves many many of my previous issues.
Sounds like you have nailed the problem in the best way possible. Are you going to let us see what you are working on? 
Ofcorse, just check my signature.
I’ve got one more question. I’m building XML files with a simple XmlSerializer.Serialize() function from a specific class (a WeaponData class in this case) it’s giving me this as a result.
[B]<?xml version="1.0" encoding="Windows-1252"?>[/B]
<WeaponData[B] xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"[/B]>
<RateOfFire>0.2</RateOfFire>
<Kickback>2.5</Kickback>
<Range>100</Range>
<Muzzle>
<x>0</x>
<y>0</y>
<z>1.75</z>
</Muzzle>
<DamageMin>5</DamageMin>
<DamageMax>15</DamageMax>
<SoundPitchMin>0.75</SoundPitchMin>
<SoundPitchMax>1.25</SoundPitchMax>
</WeaponData>
The extra text at the top, is it necessary for XML to work and if not, is there a way to tell is to generate XML without that extra part?
It’s not a big problem but it just doesn’t look good, visually.
Do some googling on XML Namespaces. What is declared there could be considered the “default” namespaces. Probably not important for what you are doing, so they can be ignored, but if you wanted to get fancy when doing XPath queries into your data you can essentially filter by namespace. Also handy when doing XSLT.
For example, I could use the same element with a different namespace and specifically select one or the other.
<?xml?>
<root xmlns:foo="http://www.foo.com" xmlns:bar="http://www.bar.com">
<foo:element>Here is some foo data.</foo:element>
<bar:element>Here is some bar data.</bar:element>
</root>