MapNav Advanced

(Leslie Young) #1

In the docs I explain how you can derived from MapNavNode when you need to create nodes that hold custom data but there is also another way and a way which you might want to use if you are working with bigger maps.

I found for example that a map of 128x128 tiles can result in scene files of over 2Mb and there is a small delay when you save. This is because of the MapNavNode deriving from ScriptableObject.

This change will require that all your custom node data (properties/ fields) be defined in the MapNavNode class since any class derived from it will fail to serialise its data.

For the first change, open the MapNavNode.cs and change it from
public class MapNavNode : ScriptableObject

to simply
public class MapNavNode

If you derived any node class from MapNavNode you need to move the fields and properties into MapNavNode now and delete that script. It will fail.

You will see some errors in the CreateGrid() functions of the various Map classes like MapNavSquare and MapNavHexa.

Go to those lines that throw errors and you should see they look like this
grid[idx] = ScriptableObject.CreateInstance<T>();
or this
grid[idx] = (MapNavNode)ScriptableObject.CreateInstance(nodeType);

Simply change both cases to
grid[idx] = new MapNavNode();

That is all there is to it. You will now have smaller scenes and it should save faster when you save a scene in the editor.

(Leslie Young) #3

Here is a new Sample. Import it after having imported MapNav2.

This sample shows how to move a Unit by one tile when a key is pressed.

mapnav_sample7.unitypackage (56.1 KB)

Button move 1 tile node up