当前位置:网站首页>How does unity use mapbox to implement real maps in games?
How does unity use mapbox to implement real maps in games?
2022-06-30 04:53:00 【LintonL】
Original website :http://www.manew.com/thread-106602-1-1.html
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Speaking of the real map in the game , The first games that come to mind should be popular all over the world AR game 《Pokémon Go》 Well . Today's tutorial will introduce you to Mapbox Unity SDK, Can get the real world map in the game , Or generate the voxel world in the game according to the real map . These map data can be stored in the game or application in advance , It can also be generated dynamically at run time .
Set up account numbervisit Mapbox Download from the official website Mapbox Unity SDK, And then I'll download .assetpackage File import project . In the use of Mapbox Before plug in , You need to be in Mapbox Apply for API Key. establish Mapbox After account number , open API acess tokens page , Create a new one token.

And then in Unity Click menu item in the editor Mapbox - Configure Access open Mapbox Interface :

Input Access Token:

If Token take effect , The editor will appear as shown in the figure above “TokenValid” Tips .
Example scenario
Mapbox The plug-in provides a number of sample scenarios , The simplest example scenario Slippy, It is also a common function case of game projects . It shows that the map extends from a selected point , Load new terrain in real time according to the change of field of view , This is also a common function for tracking the real geographical location of an object in the game .

This example uses 3D grid , And Unity Self contained 3D The terrain is the same . In the scene Map The game object has Abstract Map Script , You can set the longitude and latitude and extension range of the starting position of the terrain in this script .

Abstract Map The script Map Visualization Fields are used to define the appearance of the map .Mapbox The plug-in already provides some different visual effects , But you can also choose to customize or recreate the terrain .

take Map Visualization Field set to PoiDemoVisualization, And change the starting position to Shanghai , The effect is as follows :

If you want to generate 《 My world 》 Voxel maps like that , Can open VoxelWorld Scene to see its settings . The effect is as follows :

Custom map
except Mapbox Sample map appearance provided , You can also customize the map information you want to display . Here are the steps to customize the map .
First, create a new folder “CityMap”, Then right-click the folder in the project view , Choose in turn Create - Mapbox - MapVisualization New programmable object MapVisualizer, This object will be used as the root node of the map , To carry all map levels .

Then create Terrain Factory, stay “CityMap” Create a new folder in the directory “CityTerrain”, Then right-click the folder in the project view , Choose in turn Create - Mapbox - Factories - Terrain Factory New programmable object CityTerrain:

Select... In the inspector CityMap object , add to CityTerrain For its first Factory.

Can be in CityTerrain Object , To change the height scale of the building .

reminder : If you don't want the map to be highlighted , You can create a new material and then Smoothness Change it to 0 , Then replace CityTerrain The material used by the object .
Create below Map Image Factory. stay “CityMap” Create a new folder in the directory “CityImagery”, Then right-click the folder in the project view , Choose in turn Create - Mapbox - Factories - Map Image Factory New programmable object CityImagery.

Choose CityImagery object , Put it Style Set to Dark.

Then select CityMap object , take CityImagery Add as its second Factory.

Create a game object after creating a new scene Map, And bind it AbstractMap Script .

Will script the MapVisualizer Property set to CityMap,Zoom Set to 16. And then to Map Object to add RangeTileProvider Script , Set its range to (1, 1, 1, 1), And will RangeTileProvider Script assigned to AbstractMap Of Tile Provider Field . as follows :

among Range Indicates that the center is the set longitude and latitude ,Mapbox Towards the center 4 Number of parcels generated in each direction , The default is 0. This is the simplest custom map , Click Run to see the appearance of the generated map as follows :

You can add more layers on top of this , To place 3D Architecture 、 Road texture, etc .
summary
About the Unity Pass through Mapbox To add a real world map to the game, let's share it here , This article only briefly introduces Mapbox Unity SDK A small part of the function of , Interested friends can download and try it out and explore it more deeply .
source :Unity Official Chinese Forum
边栏推荐
- What is SQL injection and how to avoid it?
- Differences between cookies and sessions
- Preorder traversal of Li Kou 589:n fork tree
- Create a simple battle game with photon pun
- Approaching history, introduction to the London Guard Museum
- [UAV] kinematic analysis from single propeller to four rotor UAV
- Easyrecovery data recovery software recovers my photo and video data two years ago
- One command to run rancher
- Check London attractions suitable for parents and children in winter vacation
- The difference between get and post requests
猜你喜欢

力扣2049:统计最高分的节点数目

深度学习------不同方法实现Inception-10

Redis implements SMS login function (I) traditional session login

Winter vacation parent-child tour, these new york attractions are not only fun but also knowledge

Autowired注解警告的解决办法

Universal Studios Singapore: a good place for a one-day parent-child tour in Singapore

Lambda&Stream

Foreign SSL certificate

Unity automatic pathfinding

【Paper】2015_ Active fault-tolerant control system design with trajectory re-planning against actuator
随机推荐
Encapsulating JDBC tool classes
Collective system
svg和canvas的区别
Bean creation process and lazy init delay loading mechanism
Differences between cookies and sessions
Steamvr causes abnormal scene camera
Preorder traversal of Li Kou 589:n fork tree
brew安装nvm报nvm command not found解决方案
One interview question a day - the underlying implementation of synchronize and the lock upgrade process
图的一些表示方式、邻居和度的介绍
Unity enables simple music visualization
JPA composite primary key usage
Solution to Autowired annotation warning
Brew install NVM command not found solution
为什么win10开热点后电脑没有网络?
Deep learning ----- different methods to realize inception-10
Efficiency test of adding and querying ArrayList and LinkedList
Webots learning notes
Output directory of log files after unity3d packaging
What is multimodal interaction?