unity webgl 使用webp

環(huán)境

Unity 2019.4.18f1

第三方插件

unity.webp@0.3.9
https://github.com/netpyoung/unity.webp

問題

導(dǎo)入后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,應(yīng)該是與我這個版本的unity的unsafe版本不一致

解決方法一

升級unity版本,不過我沒測試過哪個版本可以,你可以試試2022.2

解決方法二

從NuGet下載對應(yīng)版本的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和對應(yīng)的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里關(guān)閉Assembly Version Validation即可。

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容