Writing (serializing class) to TextAsset

Hello!

I know how to deserialize my class from xml TextAsset, but I am not sure how to serialize it to TextAsset.
Is writing to TextAsset possible?

Serialization code for an ordinary xml file looks like this:

static public void SerializeGameText(GameText2 my_text, TextAsset xml_file)
    {
        XmlSerializer s = new XmlSerializer(typeof(GameText2));
                     
        TextWriter w = new StreamWriter(@"c:\level.xml",false,Encoding.Unicode);
        s.Serialize(w, my_text);
        w.Close();
    }

Thanks!

It is not possible to write to a text asset. However you could use PlayerPrefs or write to a file in your data folder (if you’re not building a webplayer).

To store a string in PlayerPrefs, use PlayerPrefs.SetString:

The location of your data folder can be obtained from the Application.dataPath property: