我正在研究如何使用GIS
格式的KML
数据在Unity中生成环境。我碰到了SharpKML
插件,它似乎非常适合我的需求。
但是,我遇到一个奇怪的错误,因为Unity会引发错误
“ CS0246:找不到类型或名称空间名称“ SharpKml”(您是否缺少using指令或程序集引用?)”
该引用已添加到VS,并且我有using SharpKML.Dom
和using SharpKML.Engine
条目可以在VS中毫无问题地编译。
但是Unity仍然会引发错误。
我已经通过NuGet
进行了安装,还下载了SharpKML
的源代码,并在我的机器上重建了dll
,并且没有更改直接引用。 VS似乎还断断续续地删除了引用。
您是否曾经遇到过这个问题,或者不知道是什么原因造成的?
运行框架2019.1.4f1
的Unity版本为2017
,VS版本为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);
}
}
}
}
答案 0 :(得分:0)
每次按“运行”时,Unity都会重写项目文件。您不能简单地使用nuget或从外部项目添加引用。您应该下载所有SharpKML dll文件,并将它们手动放置在Assets文件夹中。请参阅此以获取更多信息:https://answers.unity.com/questions/458300/how-to-use-a-external-dll.html
答案 1 :(得分:0)
您需要使用Plugin
中的Unity3D
文件夹。下载您的Package
或DLL
并放在其中。
This link会有所帮助