I’ve been toying with the idea of designing a graphical roguelike. This would require having various items, enemies, etc. Not a ton of data, but easily thousands of individual items all told. What is considered the best way to setup all this data and loading it on startup?
I have been looking at XML. Is this pretty much the deFacto way to do this sort of thing? Or are there other options out there?
It really depends on the scope of your needs. ScriptableObjects are a good way to do this purely inside of Unity, no parsing required, but XML is the way I’d go if you want something that’s portable and can be edited and used without having Unity installed. It’s almost trivial to write your own XML database editor in Visual Studio for graphically going through and updating items, save it to an XML file, and then import and parse the data into Unity- but if you don’t need any of that and can just update things in the inspector or using a custom editor script (even more trivial than making a program in visual studio), then there’s no point in going out of your way.
Because ScriptableObjects are so simple to create and use, you may wish to consider keeping it simple and using simple text files to generate them. Plain text is dead-easy to consume and they’re simple to edit by hand compared to XML or JSON … no editor tool required. Conversion to ScriptableObjects gives you the best of both worlds.
I’ve written variations on my current game project multiple times over the years and keeping my setup data in this simple format means I can reuse it easily. Sure XML and JSON are standards but they’re a pain to hand-edit – you almost have to write editors to manage them (that could make sense if your data is very complex but even then, an editor can just as easily, maybe more easily, emit plain text, too).
My point is, don’t unnecessarily over-complicate it. Think of that data as a design-time asset and package as a ScriptableObject for runtime.
My file looks like this (about 1000 lines removed but you get the point) –
// double-slashes are comment lines
// double-asterisks are section breaks
// blank lines are ignored
** DESCRIPTION
This map is based on the classic Western European theater shipped with Alan Calhammer's original Diplomacy boardgame in 1955. It supports 2 to 7 players.
** UNITS
// power, player-count, unit-region list
ENG 7 A-LVP F-EDI F-LON
FRA 7 A-PAR A-MAR F-BRE
GER 7 A-MUN A-BER F-KIE
AUS 7 A-VIE A-BUD F-TRI
TUR 7 A-ANK F-SMY F-CON
RUS 7 A-MOS A-WAR F-SEV F-STP:SC
ITA 7 A-VEN A-ROM F-NAP
** POWERS
// code, name, RGB
ENG England 255 255 255
FRA France 0 252 255
ITA Italy 0 255 0
GER Germany 255 156 0
AUS Austria 255 0 0
TUR Turkey 255 255 0
RUS Russia 150 0 255
** REGIONS
// the order here is CRITICAL -- these must exactly
// match the RGB color index in the Region Mask graphic
// code, industrial_flag, name
BEGIN NEUTRAL
SWE 1 Sweden
NOR 1 Norway