XML and Unity 3

Hi,

I use a XML file to store the player’s data this way:

void SavePlayerData() 
   { 
		StreamWriter writer; 
		FileInfo info = new FileInfo(fileName); 
		if(!info.Exists)
		{ 
			writer = info.CreateText(); 
		} 
		else 
		{ 
			info.Delete(); 
			writer = info.CreateText(); 
		} 
		writer.Write(dataBuffer); 
		writer.Close(); 
   }

but after upgrading to Unity 3.0 I get an error message complaining about ‘System.IO.FileInfo’ that doesn’t contain a definition for ‘Delete’
error CS1061: Type System.IO.FileInfo' does not contain a definition for Delete’ and no extension method Delete' of type System.IO.FileInfo’ could be found (are you missing a using directive or an assembly reference?)

Testing with Unity 2.6 the same script works fine. Does anyone know what may cause the problem or a better solution to store the player’s data for the web?

Thanks

Nevermind, moved on to PlayerPrefs

I am also having this problem, after upgrading to Unity 3.0 Pro I am getting:

error CS1061: Type System.IO.FileInfo' does not contain a definition for Delete’ and no extension method Delete' of type System.IO.FileInfo’ could be found (are you missing a using directive or an assembly reference?)

and also:

error CS1061: Type System.IO.FileInfo' does not contain a definition for OpenText’ and no extension method OpenText' of type System.IO.FileInfo’ could be found (are you missing a using directive or an assembly reference?)

And the reason is because my project was able to compile either as a standalone PC app or as a Web Player app. As a standalone it saved data locally and as a web app it saved to a database using WWW.

Now with Untiy 3.0, It will not compile a Web Player version with System.IO code, even though I only call that function if it is to run by a web player. Is there any way to have both in one build?

According to one source (http://forum.unity3d.com/threads/30077-Unity-C-preprocessor?p=195832#post195832) there should be preprocessor directives for you to include platform specific code into your build as of version 3. Not sure where the documentation for it though.

EDIT: found it: http://unity3d.com/support/documentation/Manual/Platform Dependent Compilation.html

(but I’m having trouble loading the data from that page. If you are too, here’s the google-cache entry: cache:w3hP55QZqVoJ:unity3d.com/support/documentation/Manual/Platform%20Dependent%20Compilation.html Unity platform dependent compilation - Google Search

And it copy-pasted here:

Thanks FizixMan, that will take care of my issue.

Hi,
seen this but i dont have the slightest idea how it will help me to publish to webplayer setting.
i want this >> http://www.unifycommunity.com/wiki/index.php?title=Save_and_Load_from_XML to work in webplayer setting…

that can not work.
Webplayers can’t write files or access the local system in any way

If you want to save XML as a webplayer you must use WWW, add it as data to the WWWForm and pass that along to a webeservice and have the webservice store and offer it

You might be able to save the XML String in a Player pref, depending on the Size of the string
(not sure what the size limit for player prefs is from the top of my head)

Have a look at the documentation.

sorry coz I just steps into unity3d world about a month but are you saying its possible but just in other way?
ok i found this

are you talking about this?
any guide on how to do this?

Hi all,

I am confused here. I’m getting the same error as Voideo following an upgrade to 3.0 from 2.6. When I build as a “PC and Windows standalone” there are no problems. However, when I build as “Webplayer” I get:

error CS1061: Type System.IO.FileInfo' does not contain a definition for Delete’ and no extension method Delete' of type System.IO.FileInfo’ could be found (are you missing a using directive or an assembly reference?)

It is referencing the line “t.Delete()” in the CreateXML() procedure from _GameSaveLoad.cs which I borrowed from http://www.unifycommunity.com/wiki/index.php?title=Save_and_Load_from_XML which Zumwalt wrote a couple years ago.

I understand that I need to use a preprocessor directive. However, I cannot find any documentation on HOW to implement this within my code. Can anybody give me specific advice on what I need to do?

Thank you!

http://msdn.microsoft.com/en-us/library/ed8yd1ha(v=vs.71).aspx
That link has some Preprocessor directives, if you click on the directives you will see examples.

mostly just #if() and #endif and #else for what you need.

Webplayers cannot access the File System, and so File system related classes are all stripped and non-functional (to avoid bloating the build with unusable classes).

Thanks, Ntero. I realize that I need preprocessor directive statements like:

But what do I need to actually directed it to do in the case of Unity Webplayer? That is what I’m confused about.

Ah ok
You’d probably want to wrape #if !UNITY_WEBPLAYER, and don’t perform file i/o in the web player. As to alternatives you’ll likely need to track something either in memory or on a server.