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:

  1. How can I store a representation of a class object (Ability.cs) in a file that I can later load at runtime?
  2. If the answer to the above is XML, what resources are there to load xml at runtime without making a big switch statement parser?
  3. 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?

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.