I’ve tried TextAsset.bytes,but there is a bug in it, some binary files are ok,some files will be truncated.Is there another way to import a binary file?
In C# you can do something like this.
// Open the file containing the data that you want to deserialize.
FileStream fs = new FileStream(PathFile(name), FileMode.Open);
try
{
BinaryFormatter formatter = new BinaryFormatter();
object o = (object)formatter.Deserialize(fs);
byte[] ba = (byte[])o;
}
catch (SerializationException e)
{
Debug.Log("Failed to deserialize. Reason: " + e.Message);
throw;
}
finally
{
fs.Close();
Debug.Log("Closed file " + name);
}
thanks for replying!
I know I can do this in stand alone exe.But I want to publish my game via web too. So I have to import the binary file into the project.For now,I change my binary file into base64 format and use TextAsset.bytes to open it.Maybe it’s not the best solution.
You could wait for Unity 3, where this is fixed.
–Eric