Mapbox Unity SDK
Mapbox Unity SDK 3.0 integrates real-world mapping and location-based features into Unity projects. The SDK provides tools for building location-aware games and interactive map applications, including demo scenes for quick prototyping, customizable map visualization, and straightforward location configuration through latitude/longitude parameters or device GPS integration.
com.mapbox.sdk 
Install via UPM
Add to Unity Package Manager using this URL
https://www.pkglnk.dev/mapbox-sdk.git README Markdown
Copy this to your project's README.md
## Installation
Add **Mapbox Unity SDK** to your Unity project via Package Manager:
1. Open **Window > Package Manager**
2. Click **+** > **Add package from git URL**
3. Enter:
```
https://www.pkglnk.dev/mapbox-sdk.git
```
[](https://www.pkglnk.dev/pkg/mapbox-sdk)Dependencies (2)
README
##Mapbox Unity SDK 3.0 Quickstart guide
Installing the Package
Get the Mapbox Unity SDK v3.0
- Clone the Mapbox Unity SDK v3.0 branch to local.
Open Unity Package Manager (UPM)
- Open your Unity project and navigate to the Unity Package Manager.
Add the Package from Disk
- Click the
Add package from diskbutton in the top-left corner of the UPM window. - Locate and select the
package.jsonfile within the Mapbox folder.
- Click the
Verify Installation
- The Mapbox Unity SDK package should now appear in the Unity Package Manager window.
Playing the Demo Scenes
Access the Demo Scenes
- The SDK includes two demo scenes:
Location Based GameWorld Map Viewer
- The SDK includes two demo scenes:
Import the Demo Scenes
- In the Package Manager, select the Mapbox Unity SDK package.
- Go to the "Samples" tab.
- Hit the Import button to create a
Samplesfolder at the root of your project. - Unity will copy the demo scene files into this folder.
Configure Your Access Token
- The demo scenes will not work until you set your access token.
- Open the Token Configuration window under the Mapbox section in Unity's top menu.
- Enter your access token.
Token Storage
- Unity will save the access token in a file located at:
Resources/Mapbox/MapboxConfiguration.txt
- Unity will save the access token in a file located at:
Run the Demo Scenes
- After configuring your access token, open the demo scenes and play them.
Integrating the Location-Based Game Demo Scene into Your Project
The integration process depends heavily on your project setup and how you intend to use the map. Below are steps to help you get started with a location-based game setup:
Import the Location-Based Game Sample
- Navigate to
Samples/Mapbox Unity SDK/3.0.0/Location Based Game.
- Navigate to
Use the
LocationBasedMapPrefab- Add the
LocationBasedMapprefab to any scene, and it should work. - Optionally, copy the following to another location in your project for easier customization:
LocationBasedMapprefabMapVisualsfolderScriptsfolder
- After copying, you can safely delete the
Samplesfolder if it’s no longer needed.
- Add the
Working with Location
The Mapbox Unity SDK provides two primary methods for working with location:
1. Latitude and Longitude Field in the Map Script
- The Mapbox Map Behaviour script includes a field for latitude and longitude.
- If the
Initialize On Startcheckbox is enabled:- The specified latitude and longitude will serve as the starting location of the map.
- This method is simple and effective, particularly during development in the Unity editor.
Limitations:
- This approach does not use the device's location.
- If you build the project with these settings, the map will display the predefined location specified in the script.
Usage in the Location-Based Game Demo Scene:
- You can move the
CharTargetgame object within the scene. The Astronaut character will walk toward this object in Unity space.
2. Using the LocationModule System
For a more advanced and dynamic solution, you can use the LocationModule system. This method is used by default in the Location-Based Game demo scene.
Overview:
- The LocationModule system abstracts location handling:
- In builds: Uses the device's location.
- In the editor: Uses predefined location values.
- Predefined values can be configured in the LocationModule game object located under the map prefab.
Steps to Use the LocationModule System:
Step 1. Disable Initialize On Start
- Uncheck the
Initialize On Startcheckbox in the map script.
Step 2. Add Snap Map To Location Provider
- Attach the
Snap Map To Location Providerscript to your map. - Set it up as shown in the provided documentation or image reference.
Step 3. Enable Player Movement with Device Location
- Attach the
Snap Transform To Location Providerscript to theCharTargetgame object. - Configure the script to update the position of the
CharTargetobject with the device's location in real-time. - The player avatar will automatically follow the
CharTargetobject as it moves.
By following these steps, your map will dynamically update based on the device's location, and the player avatar will respond to real-world movements.
Building Your Map Application for Android
To build your map application for the Android platform, you'll need specific settings files included in the Mapbox Unity SDK package. Follow these steps:
Step 1: Copy Required Files
- Go to the
Mapbox Unity SDK/Runtime/AndroidBuildSettingsfolder, you'll find a few folders named after Unity Editor Version. - Find the one matching (or closest lower) with the version you are using
- Copy the
Pluginsfolder inside to your project. Place it under theAssetsfolder.
Step 1b: Merging Custom Android Settings (if applicable)
- If your project already contains custom Android settings, merge them with the copied files to ensure compatibility.
Step 2: Verify Player Settings
- Open Project Settings and navigate to the Player section.
- Under the Publish Settings section (at the bottom), verify that the custom setting files we just copied are applied.
Step 3: Build Your Application
- After completing the above steps, build your application for the Android platform.
No comments yet. Be the first!