我目前正在使用GameObject.Find()
来检索Mapbox Unity SDK生成的对象。代码在编辑器中工作正常,但是当我构建项目时它返回null。违规代码如下:
GameObject go = GameObject.Find ("16/32699/21126");
if(go != null) {
//do the thing
} else {
Debug.Log("the tile doesn't exist");
}
我尝试在WebGL和Native OSX中构建,两者都有相同的结果。
在编辑器中,我在场景层次结构中寻找的对象的确切名称是16/32699/21126
。我很欣赏使用正斜杠是你如何在统一中搜索子项,但它似乎在编辑器中工作正常。
是场景层次结构的屏幕截图。
行为脚本附加到Map
对象。
你知道是什么导致这种情况,或者是否有另一种搜索我追求的对象的方式?
答案 0 :(得分:0)
您可以通过地图可视化效果直接访问图块。 示例代码。
UnwrappedTileId unwrappedTileId = Conversions.LatitudeLongitudeToTileId(latLon.x, latLon.y, (int)_mapManager.Zoom); //either use lat,lon or other way to get unwraptileid
var tile = _mapManager.MapVisualizer.ActiveTiles[unwrappedTileId];//_mapManager is your abstract map
//active tiles is the dictionary created by mapbox sdk to track which tiles are active
if(null!= tile)
{
myModel.transform.SetParent(tile.transform, true);
}
else
{
Debug.Log("Map tile is null");
}