Unity3d Filestream.Write在Unity iL2CPP转换后不工作
我正在从事UWP全息透镜项目,我正在编写一些日志以进行调试和分析。但是,每当我尝试在文件上写入时,它都会覆盖日志文件,而不是追加。 该代码正在UnityEdit和其他Visual Studio窗口应用程序上运行,但在为Hololens构建时,它停止工作,并且每次都会覆盖该文件,而不是附加该文件 为了测试这个场景,我为读者和作者创建了一个简单的脚本,我看到了相同的行为,但似乎正在处理UnityEdit和VS项目Unity3d Filestream.Write在Unity iL2CPP转换后不工作,unity3d,uwp,filestream,il2cpp,Unity3d,Uwp,Filestream,Il2cpp,我正在从事UWP全息透镜项目,我正在编写一些日志以进行调试和分析。但是,每当我尝试在文件上写入时,它都会覆盖日志文件,而不是追加。 该代码正在UnityEdit和其他Visual Studio窗口应用程序上运行,但在为Hololens构建时,它停止工作,并且每次都会覆盖该文件,而不是附加该文件 为了测试这个场景,我为读者和作者创建了一个简单的脚本,我看到了相同的行为,但似乎正在处理UnityEdit和VS项目 FileStream GetWriter(string path) {
FileStream GetWriter(string
path)
{
return new FileStream(
path + "/" + fileName,
FileMode.OpenOrCreate,
FileAccess.Write,
FileShare.ReadWrite,
0x10000,
FileOptions.Asynchronous | FileOptions.SequentialScan | FileOptions.WriteThrough);
}
byte[] ReadString(string path)
{
using (var reader = new FileStream(path + "/" + fileName,
FileMode.OpenOrCreate, FileAccess.Read, FileShare.ReadWrite))
{
var buffer = new byte[(int)reader.Length];
reader.Position = 0;
var totalRead = 0;
int toRead = (int)reader.Length;
while (toRead > 0)
{
var bytesRead = reader.Read(buffer, 0, (int)reader.Length);
if (bytesRead == 0)
{
throw new InvalidOperationException("End of file reached while trying to read queue item");
}
totalRead += bytesRead;
toRead -= bytesRead;
}
string x = Encoding.ASCII.GetString(buffer);
Debug.Log("Reading String : " + x);
return buffer;
}
}
主叫。
var writer = GetWriter(path);
string name = data[UnityEngine.Random.Range(0,4)];
byte[] d = Encoding.ASCII.GetBytes(name);
writer.Position = writer.Length;
writer.write(d,0,d.Length);
Debug.Log(ReadString(path));
测试用例
在UnityEditor中:
首次运行数据=ADA
结果=ADA
第二次运行数据=波纹
结果=ADARipple
但在全息透镜中its:第一种情况为ADA,第二种情况为波纹,依此类推
任何帮助都将不胜感激
我使用的是Unity2019.4.18f1,并用其他unity版本测试了构建,但似乎存在相同的问题