你好我在为Unity3D编写编辑器时遇到了麻烦,我遇到了一个问题,我从一个带有常规字符串的.txt文件中读取行,然后在每个常规字符串下面的文件扩展名(代表扩展的类别) )。当我尝试在分配给下一行的字符串上运行子字符串时,会出现问题。当我尝试使用任何子字符串时,文件显示为打开失败,但没有它,打开就好了。
public override void OnRequestPermissionsResult(int requestCode,
string[] permissions, [GeneratedEnum] Permission[] grantResults)
{
switch (requestCode) {
case MY_PERMISSIONS_REQUEST_Camera: {
// If request is cancelled, the result arrays are empty.
if (grantResults.Length > 0 && grantResults[0] == Permission.Granted) {
// permission was granted, yay! Do the
// camera-related task you need to do.
} else {
// permission denied, boo! Disable the
// functionality that depends on this permission.
}
return;
}
// other 'case' lines to check for other
// permissions this app might request
}
}
}
答案 0 :(得分:1)
首先读取所有文件数据,然后执行所有逻辑(Substring e.t.c.)
public bool PopulateList()
{
var success = true;
var path = "Assets/Scripts/Editor/Extensions.txt";
if (File.Exists(path))
{
try
{
var fileContent = File.ReadAllLines(path);
foreach (var line in fileContent)
{
// Define what lines do you need and get needed extensions
}
}
catch (Exception ex)
{
Log(ex); // it`s better to know the reason at least
success = false;
}
}
return succes;
}
答案 1 :(得分:0)
尝试在不打开文件的情况下执行此操作:
StreamReader myStreamReader = new StreamReader(sourceFile.FullName);