I am making a level editor and need ideas on how to save the level file.

I have been creating my own level editor for my game and i have it to the point where you can make your level, but now i need a way to save the level to a file. i am not sure on the best way to do this and i am looking for suggestion. Basically all i need it to do is save the type of object, its position and scale and any variable associated with that object. Right now i am looking to be able to run my game on desktop and webplayer, but i am looking to migrate it to mobile later too, in case that matters. Thanks in advance for any and all help.

Here is something that saves the content of 100x100 tile map. Could be anything really. The format of the file is text and is the object type (“tile” only in this example") and then however many variable for your objects. This is separated by “:”. Means you need to ensure you dont use “:” for anything else.

function SaveMap(filepathIncludingFileName : String)
{
	Debug.Log("Saving....");
    var sw : StreamWriter = new StreamWriter(filepathIncludingFileName);
    var y:int;
    for(y=0;y<100;y++)
	{
		var x=0;
		for(x=0;x<100;x++)
		{
				sw.WriteLine("Tile:"+x.ToString()+":"+y.ToString()+":"+metaMap[x,y].tileType.ToString());
		}
	}
    sw.Flush();
    sw.Close();
    Debug.Log("Save Complete");
}
 
function LoadMap(filepathIncludingFileName : String) {
	Debug.Log("Loading....");
    var sr = new File.OpenText(filepathIncludingFileName);
 
    var input = "";
    while (true) 
    {
        input = sr.ReadLine();
        if (input == null) { break; }
        var paramaters = input.Split(":"[0]);
        switch( paramaters[0])
        	{
        	case "Tile":
        		var x: int=System.Int32.Parse(paramaters[1]);
        		var y: int=System.Int32.Parse(paramaters[2]);
        		var i: int=System.Int32.Parse(paramaters[3]);
        		SetInternalMap(x,y,i);
        		break;
        	}
    }
    completeUVoperation();
    sr.Close();
    Debug.Log("Load Complete");
}