- Home /
How do I store game content as a resource
I'm wondering how I can store information in a file that I can load at runtime.
Some details : I'm creating an RPG, which is very content heavy with numerous items, abiltiies, animations, etc. and I'm coming from an XNA background where everything was stored in xml - which made storing full objects super easy.
I understand the concept of (and use) Prefabs for game objects, such as Enemy/Monster objects and Items, however I haven't been able to wrap my head around how to store things like abilities and animations.
An ability/skill/spell, whatever you want to call it will have a list of values and traits which make it unique, but it doesn't make sense to create a prefab object to hold those values. The idea would be to have an AbilityScript that would load X ability at runtime from a file. I'm curious how that storage and loading would work.
I was thinking of just continuing to use XML, but I'm not sure if Unity has a similar importer to XNA. XNA's content pipeline and ContentManager class made it very easy to load resources at runtime.
So in summary:
How can I store a representation of a class object (Ability.cs) in a file that I can later load at runtime?
If the answer to the above is XML, what resources are there to load xml at runtime without making a big switch statement parser?
Whatever format is chosen (xml?), are the contents stored as plain text when I release a build? How do I prevent tampering with the resource files?
I made a database for this , the data base stored values for each class instance. the class would be loaded from file by ID. and the values would set them selves via constructors.
Answer by Dave-Carlile · Nov 04, 2013 at 04:44 PM
This doesn't answer all of your questions, but you can store something as a resource by creating a Resources
folder under Assets. You then use Resources.Load to load it at run time.
These resources can include text files (xml). However you would need to parse the xml. Another good (better imo) format is JSON. You should be able to easily find C# JSON parsers that will work in Unity.
You can also create your own custom resource editors. This will allow you to create custom resources and edit properties on them, while Unity does the serialization for you. The documentation isn't the best, but it should point you in the right direction for what tutorials to search for.
Do you know how Unity compiles those resources? Does it do any compression or anything that would / could prevent tampering. Ex: changing the xml data of an ability to increase their damage output by 1000.
Honestly I'm not sure what the format is. I believe it's just a proprietary binary serialization of the resources, likely with some directory information as well. But that's mostly a complete guess. I don't think mucking with the files would be overly simple, but probaby doable for the motivated.
Your answer
Follow this Question
Related Questions
Loading XML asset after build 0 Answers
build android apk that contain Resource XML 0 Answers
path of xml file 1 Answer
Convert XML Deserializer from folder to resources 2 Answers
Reading level specific file in build (from another level) 0 Answers