Jump to content

Recommended Posts

Posted (edited)

This script will add a NavMesh component to each terrain in the Terrain Loader, and build the navmesh. There is still a little tweaking to do in the settling the layers, for the navmesh baking,  The baking does take some time, so for large worlds, this will take some time.

This script belongs in a Editors directory.

using Gaia;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using UnityEngine.AI;

public class SpawnNavMesh : MonoBehaviour
{
    [MenuItem("Tools/Add NavMesh to All Terrains")]
    public static void AddNavMeshtoTerrain()
    {
        Action<Terrain> action = 
            (terrain) => AddNavMesh(terrain);
        GaiaUtils.CallFunctionOnDynamicLoadedTerrains(action, true );
    }

    private static void AddNavMesh(Terrain terrain)
    {
        GameObject go = GameObject.Find(terrain.name);

        NavMeshSurface surface =
            go.GetComponent<NavMeshSurface>();
        if ( surface == null )
        {
            surface = go.AddComponent<NavMeshSurface>();
        }
        surface.BuildNavMesh();

    }


}

DKnight

Edited by DKnight
  • Like 4
Posted
12 hours ago, DKnight said:

This script will add a NavMesh component to each terrain in the Terrain Loader, and build the navmesh. There is still a little tweaking to do in the settling the layers, for the navmesh baking,  The baking does take some time, so for large worlds, this will take some time.

Nice stuff, would recommend doing:

GameObject go = terrain.gameObject

Instead of the GameObject.Find() this can be an expensive request and since you already have the terrain you can grab the gameobject right from it since it's a monobehaviour.

Posted

nice suggestion, i will modify mine.

thank you

 

  • STORM is here!

    STORM supercharges Unity to render massive open AAA worlds—on mobile and desktop—up to 10 times faster.

    STORM is your go-to tool for game makers and studios who are serious about performance and profitability.

  • Tell a friend

    Love Canopy - Procedural Worlds? Tell a friend!
×
×
  • Create New...