【Unity】汇总一些遇到的Bug

目录

1.There are inconsistent line endings in the 'XXX.cs' script. Some are Mac OS X (UNIX) and some are Windows.

2.HTTP/1.1 416 Range Not Satisfiable:http://www.test.com/tttttt.pdf

3.PlayerSettings Validation: Requested build target group (0) doesn't exist; #define symbols for scripting won't be added.

4.Unity路径自动补全。DirectoryNotFoundException: Could not find a part of the path "D:\Working\Unity\CommerialProjects\2D Game Project\‪D:\桌面\Test.txt".

5.Menu Window/Panels/1  can't be checked because it doesn't exist

6.InvalidOperationException: Code has not been generated, may be not work in phone!

7.Assertion failed on expression: 'm_ErrorCode == MDB_MAP_RESIZED || !HasAbortingErrors()'   Asset database transaction committed twice    Assertion failed on expression: 'errors == MDB_SUCCESS || errors == MDB_NOTFOUND' 

8.IOException: Sharing violation on path...

9.c# exception:System.InvalidCastException: Specified cast is not valid.

10.Toggle组点击时乱闪的问题


1.There are inconsistent line endings in the 'XXX.cs' script. Some are Mac OS X (UNIX) and some are Windows.

解决方法:

调出visual studio的高级保存选项,并将行尾设置成Windows(CR LF)

Step1,调出高级保存选项:

方法一:直接从搜索栏里面搜高级保存选项

方法二:将高级保存选项放到菜单栏:

打开菜单栏的“工具”->“自定义”选项

选择“命令”页->点击“添加命令”

选中“文件”类别,添加“高级保存选项”,并确定

 

  

 点击确认后,还可以通过上移下移调整高级保存选项在菜单栏中的位置

 Step2,打开高级保存选项,将行尾改成Windows(CR LF) 

2.HTTP/1.1 416 Range Not Satisfiable:http://www.test.com/tttttt.pdf

解决方法:

是断点续传引起的,在断点续传中设置了Request Header :“Range”,当Range报头的开始下载位置已经是末尾的时候,会引起416报错,比如下面的beginPos等于文件末尾,就会引起416

可以在检测到网络错误时,判断当报错代码是416,就删除原本下载的.temp临时文件,重新下载整个文件。

 

3.PlayerSettings Validation: Requested build target group (0) doesn't exist; #define symbols for scripting won't be added.

解决方法:

好像这个是一个unity的Bug,搜索的时候发现17年有人提出过,按理应该已经修复了?当时我触发好像是因为我把一个dll的select Platforms for plugin的exclude Platforms勾选了又取消掉了,然后就触发了这个bug...

只需要关闭整个unity hub再重启就好了

4.Unity路径自动补全。DirectoryNotFoundException: Could not find a part of the path "D:\Working\Unity\CommerialProjects\2D Game Project\‪D:\桌面\Test.txt".

 我输入的路径是桌面,unity会自动在我的绝对地址前面加上工程路径

解决方法:

应该是unity不允许写工程路径以外的文件所以出现这样的报错,只需将文件换成一个工程路径下的路径即可

5.Menu Window/Panels/1  can't be checked because it doesn't exist

解决方法:

在菜单栏打开“窗口”->“面板”->“关闭所有浮动面板"

6.InvalidOperationException: Code has not been generated, may be not work in phone!

解决方法:

是XLua导致的,build之前需要先generate code

点击菜单栏的“XLua”->“Generate Code”

7.Assertion failed on expression: 'm_ErrorCode == MDB_MAP_RESIZED || !HasAbortingErrors()'   Asset database transaction committed twice    Assertion failed on expression: 'errors == MDB_SUCCESS || errors == MDB_NOTFOUND' 

解决方法:

unity许可证过期,在unityhub中激活许可证并重新打开项目即可

8.IOException: Sharing violation on path...

解决方法:

检查用到FileStream对象的地方,用完之后要及时Dispose()

FileStream fs = new FileStream(filePath, FileMode.OpenOrCreate,FileAccess.Write);
fs.Close();
fs.Dispose();

除了直接用FileStream对象的地方,File.Create也会产生FileStream对象,也需要进行Dispose

if (!File.Exists(path))
{
    File.Create(path).Dispose();
}

9.c# exception:System.InvalidCastException: Specified cast is not valid.

解决方法:

这个应该是类型转换失败的问题,检查涉及到的类型之间是否可以相互转换

10.Toggle组点击时乱闪的问题

问题如图:

解决方法:

好像是导航出现的问题,我不清楚具体原因(如果有知道的小伙伴可以告诉我..)

将导航改成None就解决了

猜你喜欢

转载自blog.csdn.net/weixin_61427881/article/details/129805051