我正在嘗試使用 Postman 提供的代碼將 API 連接到我的 Unity 專案。該代碼使用 RestSharp。我重新生成了嵌入包和本地包專案檔案。 鏈接到 Unity/Preferences/External Tools/Generate .csproj 檔案:然后使用 Visual Studio Code 上的 NuGet 包管理器擴展安裝 RestSharp 版本 107.3.0。然后使用 dotnet restore 因為 NuGet 告訴我這樣做。現在我的“Assembly-CSharp.csproj”檔案有:
<PackageReference Include="RestSharp" Version="107.3.0"/>
但是,每當我嘗試添加時:
using RestSharp;
一行到我的 APITest.cs 腳本,Unity 說:
APITest.cs(4,7): error CS0246: The type or namespace name 'RestSharp' could not be found (are you missing a using directive or an assembly reference?)
如何將 RestSharp 與 Unity 結合使用?
uj5u.com熱心網友回復:
您無法通過 NuGet 將專案添加到 Unity。對 Unity中的檔案所做的任何更改.csproj都將在下次 Unity 自動生成時被覆寫。Unity 實際上并沒有.csproj像“正常” C# 安裝那樣使用這些檔案——它只是生成它們,以便 IDE 更容易理解代碼。
有幾種不同的方法可以將包添加到 Unity 專案:
- 使用內置的Unity 包管理器獲取官方 Unity 包
- 通過Unity Asset Store匯入
- NuGetForUnity(根據@derHugo 的評論)
- 開放式管理系統
Assets有時也可以將 C# 檔案直接添加到您的專案中。
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/444836.html
