簡體   English   中英

Unity引發錯誤“ CS0246:找不到類型或名稱空間名稱'SharpKml'

[英]Unity throws an error “CS0246: The type or namespace name ‘SharpKml’ could not be found

我正在研究如何使用KML格式的GIS數據在Unity中生成環境。 我遇到了SharpKML插件,它似乎非常適合我的需求。

但是,我遇到一個奇怪的錯誤,因為Unity會引發錯誤

“ CS0246:找不到類型或名稱空間名稱“ SharpKml”(您是否缺少using指令或程序集引用?)”

該參考已添加到VS,並且我using SharpKML.Domusing SharpKML.Engine條目,這些條目在VS中編譯沒有問題。

但是Unity仍然會拋出錯誤。

我已經通過NuGet進行了安裝,並且還下載了SharpKML源代碼,並在我的計算機上重建了dll ,並且直接進行了引用,沒有任何更改。 VS似乎也間歇性地刪除了引用。

您之前是否曾遇到過此問題,或者不知道是什么原因引起的?

Unity版本為2019.1.4f1 ,VS版本為2017運行框架4.7.03062

我在不同網絡上的另一台計算機上重新創建了該項目,並遇到了相同的問題。

using UnityEngine;
using System.IO;
using System.Linq;
using SharpKml.Dom;
using SharpKml.Engine;

public class RenderKML : MonoBehaviour
{
    public string KLMPath;

    // Start is called before the first frame update
    void Start()
    {
        string kmlPth = "Assets\\kml";
        GetKMLFiles(kmlPth);
    }

    private void GetKMLFiles(string pth)
    {
        if (pth != null)
        {
            DirectoryInfo dir = new DirectoryInfo(pth);
            FileInfo[] info = dir.GetFiles("*.kml");
            foreach (FileInfo f in info)
            {
                print(f.FullName);
                GetKMLData(f);
            }

        }
    }

    private void GetKMLData(FileInfo fI)
    {
       // This will read a Kml file into memory.
        Stream fs = new FileStream(fI.FullName, FileMode.Open);
        KmlFile file = KmlFile.Load(fs);

        Kml kml = file.Root as Kml;
        if (kml != null)
        {
            foreach (var placemark in kml.Flatten().OfType<Placemark>())
            {
                print(placemark.Name);
            }
        }
    }
}

每次按“運行”時,Unity都會重寫項目文件。 您不能簡單地使用nuget或從外部項目添加引用。 您應該下載所有SharpKML dll文件,並將它們手動放置在Assets文件夾中。 請參閱此以獲取更多信息: https : //answers.unity.com/questions/458300/how-to-use-a-external-dll.html

您需要使用Unity3DPlugin文件夾。 下載您的PackageDLL並將其放在此處。

該鏈接可能會有所幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM