unity坑-编译错误

问题:

  项目里面有一个 StreamReader来读取一个文件,使用OpenText() 方法。

  但是UNITY却提示 StreamReader类不包含OpenText()方法,并且也没有找到扩展方法。

原因:

  这就很奇怪了,StreamReader是System.IO下的类,里面的的确确是有这个方法的,但是为什么Unity却提示找不到方法呢?

  经过各种百度,最终找到问题的原因,因为当前Unity的平台使用的是WebPlayer平台,而webplayer平台是无法操作这些的,

  也就是对文件IO进行了限制,无法使用这些方法,因此Unity会报错。

解决方法:

  解决方法也很简单,只需要要切换到其他平台即可。

附上报错代码:报错为代码的第10行。

 1     public XCPlist(string fPath)
 2         {
 3             filePath = Path.Combine( fPath, "info.plist" );
 4             if( !System.IO.File.Exists( filePath ) ) {
 5                 Debug.LogError( filePath +"路径下文件不存在" );
 6                 return;
 7             }
 8 
 9             FileInfo projectFileInfo = new FileInfo( filePath );
10             StreamReader sr = projectFileInfo.OpenText();
11             while (sr.Peek() >= 0) 
12             {
13                 contents.Add(sr.ReadLine());
14             }
15             sr.Close();
16 
17         }

 

posted @ 2018-04-02 10:07  gameDesigner  阅读(545)  评论(0编辑  收藏  举报