您现在的位置是:首页 >技术教程 >Create a map in Unity网站首页技术教程

Create a map in Unity

阿依土鳖王子 2023-05-22 12:00:02
简介Create a map in Unity

Beginner

No code

Prerequisite

Familiarity with Unity.

This tutorial will walk you through how to create a visualization of 3D buildings on top of a 3D terrain map for use in a Unity application. You will:

  • Set up a Mapbox project in Unity.
  • Learn about the Mapbox-specific terminology, tools, and services you’ll use to build your visualization.
  • Add a map to your scene.
  • Customize your map for your specific needs.
  • Learn how to add buildings and other vector data.

This tutorial is for versions 1.4.0 and beyond. If you are using version 1.3.0 or earlier, read the mesh generation tutorials instead.

Getting started

Before getting started, you’ll need to:

  1. Install the Mapbox Maps SDK for Unity. For full installation instructions, visit https://www.mapbox.com/unity-sdk.
  2. Create an empty Unity project.
  3. Configure your Mapbox access token in your Unity project. For token configuration instructions, visit Maps SDK | Unity | Mapbox.

Set up your project

Your new, empty scene will need a Map object to display a map. We provide a Map prefab already that you can drag and drop into your scene.

您的新空场景将需要一个 Map 对象来显示地图。 我们已经提供了一个地图预制件,您可以将其拖放到您的场景中。

This Map object comes with an Abstract Map script, where you can adjust map settings like location, map style, elevation, and more.

To see what the default Map looks like, hit Play.

此地图对象附带一个抽象地图脚本,您可以在其中调整地图设置,例如位置、地图样式、海拔等。

要查看默认地图的外观,请点击播放。

You have a map! Note that you may need to change the camera’s position to see the map properly in the Game panel, but you can see it in the Scene panel.

你有一张地图! 请注意,您可能需要更改相机的位置才能在“游戏”面板中正确查看地图,但您可以在“场景”面板中看到它。

Customize your map

Now you’ll learn how to style two kinds of maps: one with rich satellite imagery and elevation data, and one with vector data to show buildings. You will learn how to use various settings in Abstract Map to change a map’s location, map style, elevation, and vector layers.

现在您将学习如何设置两种地图的样式:一种具有丰富的卫星图像和高程数据,另一种具有矢量数据以显示建筑物。 您将学习如何使用抽象地图中的各种设置来更改地图的位置、地图样式、海拔和矢量图层。

Create a map of Mt. Hood, Oregon

Select your Map object and look at the Inspector window. Under the Abstract Map general settings, either change the location to 45.374218, -121.688341 or search “Mt Hood”. Set the zoom level to 13. Open the “Others” settings and toggle Snap Map to Zero.

选择您的地图对象并查看检查器窗口。 在抽象地图常规设置下,将位置更改为 45.374218、-121.688341 或搜索“Mt Hood”。 将缩放级别设置为 13。打开“其他”设置并将贴图切换为零。

Now open the image settings and change the Data Source to “Mapbox Satellite”. Finally, open the terrain settings and change the Elevation Layer Type to “Terrain with Elevation”.

现在打开图像设置并将数据源更改为“Mapbox Satellite”。 最后,打开地形设置并将高程图层类型更改为“带高程的地形”。

Save your scene and hit play. Switch to your Scene panel and you’ll see something like this:

保存场景并点击播放。 切换到你的场景面板,你会看到这样的东西:

Now you'll make a map of downtown Manhattan!

现在您将制作曼哈顿市中心的地图!

Create a map of downtown Manhattan

To make this map of Manhattan, you can either start over in a new scene, or change the settings in your existing scene. It’s up to you!

First set the location to 40.706843, -74.011370 or search “New York Stock Exchange”, and set the zoom level to 17. Next, go to the image settings and change the Data Source to “Mapbox Dark”. In the terrain settings, change the Elevation Layer Type to “Flat Terrain”.

要制作这张曼哈顿地图,您可以在新场景中重新开始,也可以更改现有场景中的设置。 由你决定!

首先将位置设置为 40.706843,-74.011370 或搜索“New York Stock Exchange”,并将缩放级别设置为 17。接下来,转到图像设置并将数据源更改为“Mapbox Dark”。 在地形设置中,将高程图层类型更改为“平坦地形”。

Now open up the vector settings. Change the Data Source to “Mapbox Streets”. Create a new visualizer by clicking the “Add Visualizer” button. It will now show up in the vector layer visualizers list as “Untitled”. Click it and hit the Enter key to rename it to “Buildings”.

现在打开矢量设置。 将数据源更改为“Mapbox Streets”。 单击“添加可视化工具”按钮创建一个新的可视化工具。 它现在将在矢量图层可视化列表中显示为“无标题”。 单击它并按 Enter 键将其重命名为“Buildings”。

Click your “Buildings” visualizer and find the Extrusion Type setting. Change it to “Property Height”. Next, look for the Material Options setting. Next to Roof Material and Wall Material is a small circular icon. Click it, and select ”BuildingMaterial” for both.

单击“建筑物”可视化工具并找到“拉伸类型”设置。 将其更改为“属性高度”。 接下来,查找材料选项设置。 屋顶材料和墙体材料旁边是一个小圆形图标。 单击它,然后为两者选择“BuildingMaterial”。

Hit play to see Manhattan with buildings!

点击播放,看看曼哈顿的建筑物!

Next steps

To learn more about what you can do with Mapbox Maps SDK for Unity, read the SDK documentation.

风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。