Hi Jean,
I would like to know, how you use XML in your own projects. You create a XML file and fill it with the needed data. After that do you implement this XML file in the unity app and parse it every time it is running? Or do you load the XML one time a change was made and convert it in another format for further use at runtime? I have the feeling parsing a big XML all runtime isn't the best way. But I have no clue.
Or do you use a XML for an at runtime populated database?
Hi,
Very good questions
There is two cases for xml usage, you'll extrapolate on use case, but lets take level management and User Progress
Level Management: you have an Xml file that is part of your assets, it helps define the level content, where objects are, their setup.
-- Level Management
- This xm is generated during editing.
- you load it as is only at the very beginning of the game and keep it in a xml proxy
- everytime you need to build a level, you query that xml proxy with xpath, ask for the level data, save that in a memory reference ( in xml actions you can always save in memory)
- Use this memory reference in all related fsm to build up that level
- NEVER save xpath searched as string for using in game, string conversion is very performent sensitive, always use memory reference when in game.
-- User Progress
- That xml doesn't exist during editing, you create it from scratch the first time the user plays your game
- you save it and load it from the PlayerPrefs. Here you will need to parse it from and to string. So only save in player prefs when not in the game loop, like during the finished menu, pause menu.
- add new nodes related to a particular level and its user progress, when your user comes back, read that particular level node, and update player position, and level data ( some stars may be already picked up, don't show them, some items may be picked up, set them up accordingly)
To give you some numbers so that you understand the power behind this. I have helped game developers with this methods, and their xml level data was over 36Mb of xml in one single file, spanning across 100.000 lines of xml, all in plain english, defining each level ( 6 chapters if I recall properly, 16 levels per chapter). It loads on iPhone at the very beginning of the game, you just simply don't notice it, it takes less than half a second to load up in memory and become available for INSTANT queries using xpath throughout the game.
that same game is using xml for user progress, keeping track of all features, score, per level, total score, all the stars, bonuses, etc etc, and that data leaves in the playerPref under ONE key only! and totally spittable in the console or sent over the network to a server or mailed for debugging on actual existing players, agian because xml is plain english, you have a huge advantage for analysis over messed up multi key setup for playerprefs or database with obscur tables and difficult to retrieve overview of everything.
Bottom line: Xml rocks
cons, .Net framework messed up big time so xml is not available on windows mobile... so be careful if you plan on porting to windows, which is unlikely but still a possibility. If that's the case, make sure to raise your voice for this total non sense to microsoft, they need to put it back.
as for sample, I am currently working on a mii character setup system, which will be using Xml for saving the user data, you will be able to load up other faces from other people as well, so the whole thing will be running as I explained above, follow me on Twitter for news:
https://twitter.com/JeanAtPlayMaker/status/928546642420289537I'll make that sample available on the ecosystem soon ( it will be iterative, this is fairly advanced project that will take some time to complete)
Bye,
Jean