U3D中的信息保存到外部的文件中
c#代码:
using System.Collections;
using System.IO;
public class FileIO
{
public static bool WriteStringToFile(string filePath, string data, bool append)
{
try
{
StreamWriter sw = new StreamWriter(filePath, append);
sw.Write(data);
sw.Close();
return true;
}
catch (System.Exception err)
{
return false;
}
}
// Reads each line of a text file to a separate string which is stored
// in an ArrayList and returned.
public static ArrayList ReadFileToStrings(string filePath)
{
ArrayList list = new ArrayList();
string line;
// Read a file
try
{
StreamReader sr = new StreamReader(filePath);
line = sr.ReadLine();
if (line != null)
list.Add(string.Copy(line));
while (line != null)
{
line = sr.ReadLine();
if (line != null)
list.Add(string.Copy(line));
}
sr.Close();
return list;
}
catch (System.Exception err)
{
return list;
}
}
}
js代码:
import System.IO;
static function WriteStringToFile (filePath : String, data : String, append : boolean) : boolean {
try {
var sw = new StreamWriter(filePath, append);
sw.Write(data);
sw.Close();
return true;
}
catch (err) {
return false;
}
}
// Reads each line of a text file to a separate string which is stored
// in an array and returned.
function ReadFileToStrings (filePath : String) : Array {
var list = new Array();
// Read a file
try {
var sr = new StreamReader(filePath);
var line = sr.ReadLine();
while (line != null) {
list.Add(line);
line = sr.ReadLine();
}
sr.Close();
return list;
}
catch (err) {
return list;
}
}
引用位置:
http://forum.unity3d.com/viewtopic.php?t=15196&postdays=0&postorder=asc&start=0