繁体   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