Check out demo scene 503
When you enable the viewport mode, you can make your game objects be part of the viewport itself so it will take control of its position, orientation, scale and visibility. When you scroll the viewport across the map, Game Objects positioned this way will automatically disappear when they get off the viewport screen region.
This is different from adding a Game Object to the map itself (using Markers API) because your Game Objects will preserve its 3D appearance whereas adding them with the Markers API will make them appear flat in the viewport (as part of the texture).
WMSK includes a set of APIs designed to make it very easy to add your Game Objects to the viewport.
When the asset is imported in your project, a few extensions are automatically added to the GameObject class. These extensions are defined in the script WMSKGameObjectExtensions.cs.
To add or move a game object named “GO” across the map you can use:
GO.WMSK_MoveTo(float x, float y, float duration, DURATION_TYPE durationType);
This will make the gameobject part of the game map and will move it from current position to the map coordinates (x,y) with duration in seconds. Usually, you will call this method to create/add your graphic elements to the map the first time with a 0 as duration.
As per the map coordinates, both x and y ranges from -0.5 to 0.5, being 0,0, the center of the World Map.
The parameter “durationType” specified how to apply the given duration. It can be:
-
“Step”: each movement step will take the same duration in seconds.
-
“Route”: the complete movement will take the given duration in seconds.
-
“MapLap”: the duration is specified in terms of seconds taken to cross the entire map. This is useful to achieve a consistent movement speed if you pass a custom list of points that are not continuous.
Check out demo scene Map Population’s code used to move the tank around for an example.
GO.WMSK_MoveTo(Vector2 destination, float duration, DURATION_TYPE durationType);
Same than previous function except it accepts a Vector2 parameter.
GO.WMSK_MoveTo(Vector2 destination, float duration, DURATION_TYPE durationType, bool scaleOnZoom, float altitude);
This method will add the gameobject GO to the destination in duration seconds and also position it at height meters from the ground according to the heightOffsetMode which can accept the following values:
-
Absolute_Height: position the unit at an absolute height position. Useful for marking heights.
-
Absolute_Clamping: position the unit at an absolute height position BUT never below ground level. Useful for aerial units.
-
Relative_To_Ground: simply adds height to the ground altitude at that point. Useful for land units or land-marking.
ScaleOnZoom will make the gameobject scale change as the camera zooms in/out. If you want to preserve the gameobject size on screen regardless of the current map zoom, pass false to this parameter.
GO.WMSK_Teleport(Vector2 destination);
Useful to instantly move the unit to a different location when the unit is already added to the map.
GO.WMSK_MakeChild();
This is a convenient shortcut to “WMSK_MoveTo(Vector2.zero, 0, false)”. What it does is parent the given gameobject to the map, placing it on the center of the map and preserving its localscale. This is useful if you want to have a common invisible placeholder in the hierarchy for several game objects on the map, so you can for example remove all of them at once just deleting the parent placeholder. Check DemoInfiniteScroll demo scene for an example (the ship trail uses this approach).
GO.WMSK_GetMap2DPosition();
This method will return a Vector2 object with the map coordinates of the game object in the range (-0.5, 0.5).
GO.WMSK_FindRoute(Vector2 destination);
This method will return a list of Vector2 map coordinates corresponding to the optimal route of the GO from current position to destination, having into account its terrain capabilities. The terrain capability “Air” takes into account custom costs but let the unit fly over the ocean.
GO.WMSK_LookAt(Vector2 destination);
Makes this unit rotate and point towards destination.
GO.WMSK_Fire(GameObject bullet, Vector3 anchor, Vector2 mapDestination, float duration, float shootArc);
This method will fire the bullet GameObject starting at “anchor” and aimed to mapDestination for a duration and also following an arc with altitute of “shootArc”.
The anchor is the relative position to the center of the firing unit. Anchor is defined in local scale coordinates, assuming a reference size of 1x1x1.
See demo scene 510 for an example.