A friend of mine was asking about how you can save the scene hierarchy and object/script properties  in Unity, he had written most of the code instantiating prefabs and was already busy setting variables via interactions in his scripts. I explained that although I do have a generic reflection based method, that can save/restore the hierarchy, gameobjects, transforms, materials & script variables ( used on the space application ), it would be too verbose and unfitting for this task, plus if his script and prefab scripts were not written the right way this approach may not work.

With simpler configuration apps a much simpler class based object oriented approach is all that is required and most cases it is better to start with that system in mind than to retro fit. It is also much better if bringing in xml /json from other sources to reflect the xml/json structure with a c# class which you can then attach methods to manipulate the data, rather than hand parse each node (after learning the hard way), something that might be appropriate with collada objects perhaps.

Update: The methods below how to correctly set xml attributes in c# to coerce your values from the xml to your class see the latest post:-

Unity3d XML Object/Class/Type Serialisation Attributes

Below is an older very simple one script demonstration of instantiation and recording values to and from XML in Unity, apologies for any errors or messy logic I think I only had an hour to write it one afternoon, but hopefully it will convey the basics, but I would use the above attributes in c# see the link above over the method below for helping the xml parser to know what values go where and what to ignore etc:-

 

 

6419 Total Views 5 Views Today