skip to Main Content

The Viewport Mode Feature

The asset allows to render the map inside a Viewport game object (provided in the asset as a Prefab).

This mode adds the following enhancements vs the normal 2D/flat mode:

  • Allows cropping the map inside the rectangle defined by the viewport gameobject area when panning or zoomin in.

  • Renders the Earth surface over a 3D mesh with real elevation based on heightmap.

  • Can add world space gameobjects over the 3D surface and below the cloud layer. It can hide automatically game objects positioned on top of the map, and control their scale and

  • Can add a fog of war layer that can obscure the gameobjects positioned on the map as well as the map itself.

  • Enables the cloud layer which is rendered on top of fog of war and the game objects, with drop shadows over the map.

We recommend using the viewport feature to take advantage of all the above features for your game, as it makes it more visual appealing. However, mind that the viewport uses a RenderTexture of 2048×1024 pixels in size and also it uses additional memory and CPU to compute the 3D surface mesh in real-time. Not all mobile devices may support this feature. Try the provided demos on your devices to test if they can work with it.

To use the viewport feature:

  1. Drag the new Viewport prefab to the scene (from Resources/Prefabs folder).

  2. Assign the new viewport gameobject in the scene to the viewport property of the WorldMap in the inspector (you can also do that using code, check the demo.cs script for example)

  3. That’s all! The map will show up inside the viewport.

To deactivate the viewport:

  1. Select the viewport field in the inspector of WorldMap component and click delete (basically, remove the reference to the viewport game object).

  2. Delete the viewport game object from the scene.

UI Mode and Viewport

When a viewport is in the scene, a UI Panel property will show up in the WMSK inspector. By assigning an UI Panel to this property, WMSK will sync its position, rotation and scale to match the UI Panel position and size at any moment.

How does Viewport mode work?

When you use the viewport mode, the following setup will be contained in your scene (yes, there are 2 cameras):

In viewport mode, there are 2 key gameobjects in the scene. The viewport and the normal 2D/Flat map.
The 2D/Flat map is positioned out of the Main Camera frustum so it’s not visible. A hidden camera created by WMSK named “MapperCam” captures the image from the normal map and renders it to a RenderTexture which is used by the Viewport gameobject’s material.

So in viewport mode, when you zoom in/out, it’s the hidden “MapperCam” which moves towards or away from the normal 2D map. Same when you drag the mouse over the viewport, those gestures are captured by WMSK and converted into translations to the hidden camera which moves horizontally with respect the normal map.

Now, there are two ways of adding objects to the maps.

– 3D objects, like units that should reflect “height” or 3D aspect, can be added calling WMSK_MoveTo(position). When you call this method as it’s, the gameobject receives a GameObjectAnimator component that takes care of synchronizing its world space position and scale to match the current view on the viewport. When you drag or zoom, those units really move around in world space.

They are not parented to the viewport but placed on top of the viewport in world space.

– 2D objects, like country names, lines, circles or country textures/meshes, are added on top of the normal 2D map gameobject. They are captured by the MapperCam camera and are simply blended with the background map texture and result in the material texture used by the viewport. That’s how country names adapt to the 3D shape or mountains shown on the viewport, because they’re just part of the texture. The following methods add objects to the normal map:

AddLine (with arcElevation parameter=0), AddCircle, AddCircleOnSphereAddMarker2DSpriteAddMarker2DTextMarker3DObjectToggleCountrySurface or ToggleProvinceSurface and similar methods. Those objects do not receive a GameObjectAnimator, they stay on their positions.

So, if you want to add static sprites (or control their positions with your own code and not GameObjectAnimator) you can use the AddMarker2DSprite method. This method accepts an “enableEvents” parameter that enables any script attached to your sprite to receive the OnMarkerClick event. WMSK will automatically add a
MarkerClickHandler script to your sprite gameobject so clicking and dragging is possible in an automatic way:

MarkerClickHandler handler = map.AddMarker2DSprite(mySpriteGameObject, position, scale, enableEvents: true, autoScale: true);

handler.allowDrag = true; (by default = true; allows dragging the sprite with the mouse)

handler.captureClickEvents = true;

(by default = true; prevents clicks going through the sprite to the map).

The MarkerClickHandler also exposes a few events that you can use to detect when a drag starts or a click is performed over the marker for example.

Back To Top