環(huán)境
Unity 2019.4.18f1
第三方插件
unity.webp@0.3.9
https://github.com/netpyoung/unity.webp
問題
導入后C#報錯:
the name "unsafe" does not exist in the current context
查看https://github.com/netpyoung/unity.webp/blob/master/unity_project/Packages/manifest.json
發(fā)現(xiàn)插件依賴于org.nuget.system.runtime.compilerservices.unsafe@6.0.0
,應該是與我這個版本的unity的unsafe版本不一致
解決方法一
升級unity版本,不過我沒測試過哪個版本可以裆站,你可以試試2022.2
解決方法二
從NuGet下載對應版本的dll:
https://www.nuget.org/packages/System.Runtime.CompilerServices.Unsafe/6.0.0
點擊右側(cè)的Download Package或者直接下載:
https://www.nuget.org/api/v2/package/System.Runtime.CompilerServices.Unsafe/6.0.0
將下載下來的system.runtime.compilerservices.unsafe.6.0.0.unpkg
重命名為system.runtime.compilerservices.unsafe.6.0.0.zip
砸喻,解壓后,將其中的lib/{xxx}/System.Runtime.CompilerServices.Unsafe.dll
放入你的工程中梨树。
{xxx}
視你的項目project setting而定。
進一步的問題
假如你使用了微信小游戲插件,那上面這個做法會帶來另外的報錯祭玉,因微信小游戲插件也依賴System.Runtime.CompilerServices.Unsafe.dll
。解決方法是不要按上面說法把下載下來的dll放入工程中春畔,而是直接將微信小游戲插件里的dll挪出來作為公共庫脱货,即將Assets/WX-WASM-SDK/Editor/TextureEditor/Release/System.Runtime.CompilerServices.Unsafe.dll
和對應的xml文件一起挪出來放到Assets/Plugins/xxx
里。此時unity會有個新的報錯:
Assembly 'Assets/WX-WASM-SDK/Editor/TextureEditor/Release/SixLabors.ImageSharp.dll' will not be loaded due to errors:
Reference has errors 'System.Memory'.
Assembly 'Assets/WX-WASM-SDK/Editor/TextureEditor/Release/System.Memory.dll' will not be loaded due to errors:
System.Memory references strong named System.Runtime.CompilerServices.Unsafe Assembly references: 4.0.4.1 Found in project: 5.0.0.0.
Assembly Version Validation can be disabled in Player Settings "Assembly Version Validation"
按照提示律姨,在Player Settings里關閉Assembly Version Validation
即可振峻。