Beispiel #1
0
    private void UpdateNavMesh(bool async)
    {
        // Navmesh settings
        NavMeshBuildSettings settings = NavMesh.GetSettingsByID(0);

        settings.minRegionArea = 0;

        // Bounds set to be enormous to ensure all areas are covered
        Bounds bounds = new Bounds(Vector3.zero, 1000 * Vector3.one);

        // Build!
        if (async)
        {
            // Build navmesh asynchronously from sources
            m_navMeshOperation = NavMeshBuilder.UpdateNavMeshDataAsync(m_navMeshData, settings, m_navMeshSources, bounds);
        }
        else
        {
            // Blocking call used only for initial empty NavMesh
            NavMeshBuilder.UpdateNavMeshData(m_navMeshData, settings, m_navMeshSources, bounds);
        }
    }
Beispiel #2
0
    public void BuildNavMesh(List <MeshFilter> meshFilters, List <GameObject> objects, float width, float height)
    {
        navSources.Clear();

        foreach (MeshFilter meshFilter in meshFilters)
        {
            Mesh mesh            = meshFilter.sharedMesh;
            NavMeshBuildSource s = new NavMeshBuildSource();
            s.shape        = NavMeshBuildSourceShape.Mesh;
            s.sourceObject = mesh;
            s.transform    = meshFilter.transform.localToWorldMatrix;
            s.area         = 0;
            navSources.Add(s);
        }

        foreach (GameObject obj in objects)
        {
            NavMeshBuildSource s = new NavMeshBuildSource();
            s.shape        = NavMeshBuildSourceShape.Mesh;
            s.sourceObject = obj.GetComponent <MeshFilter> ().sharedMesh;
            s.transform    = obj.transform.localToWorldMatrix;
//			s.size = obj.GetComponent<MeshRenderer> ().bounds.size;
//			s.area = 0;
            navSources.Add(s);
        }

        NavMeshBuildSettings buildSettings = NavMesh.GetSettingsByID(0);

        buildSettings.overrideVoxelSize = true;
        buildSettings.voxelSize         = 0.05f;
        buildSettings.agentHeight       = 0.9f;
        buildSettings.agentRadius       = 0.4f;


        Bounds bounds = CreateBounds(width, height);

        NavMeshBuilder.UpdateNavMeshData(navMesh, buildSettings, navSources, bounds);
    }
Beispiel #3
0
    IEnumerator StartCor()
    {
        while (true)
        {
            NavMeshBuildSettings settings = NavMesh.GetSettingsByID(0);
            Bounds bounds = new Bounds(transform.position + size / 2, size);

            List <NavMeshBuildSource> sources = new List <NavMeshBuildSource>();
            foreach (var mesh in meshes)
            {
                NavMeshBuildSource source = new NavMeshBuildSource();
                source.shape        = NavMeshBuildSourceShape.Mesh;
                source.sourceObject = mesh.sharedMesh;
                source.transform    = mesh.transform.localToWorldMatrix;
                source.area         = 0;

                sources.Add(source);
            }

            NavMeshBuilder.UpdateNavMeshData(data, settings, sources, bounds);
            yield return(null);
        }
    }
Beispiel #4
0
        AsyncOperation UpdateNavMesh(bool asyncOperation = false)
        {
            if (!NavMeshSourceTag.MakeUnchanged())
            {
                return(null);
            }

            NavMeshSourceTag.Collect(ref sources);
            var setting = NavMesh.GetSettingsByID(0);
            var bounds  = new Bounds(Quantizer.Quantize(transform.position, 0.1f * size), size);

            Debug.Log("Update NavMesh");

            if (asyncOperation)
            {
                return(NavMeshBuilder.UpdateNavMeshDataAsync(navMesh, setting, sources, bounds));
            }
            else
            {
                NavMeshBuilder.UpdateNavMeshData(navMesh, setting, sources, bounds);
                return(null);
            }
        }
Beispiel #5
0
    public void GenerateGrid(Vector3 minCorner, Vector3 maxCorner)
    {
        _worldBounds.min = minCorner;
        _worldBounds.max = maxCorner;

        // Find all nav mesh object sources in the scene
        NavMeshBuilder.CollectSources(_worldBounds, _obstacleMask, NavMeshCollectGeometry.PhysicsColliders, 1, _navMeshMarkups, _navMeshBuildSources);
        for (int i = 0; i < _pathFindObjects.Count; ++i)
        {
            _navMeshBuildSources.Add(_pathFindObjects[i].Source);
        }

        // Add a source to represent the 'ground' plane
        // NavMeshBuildSource groundSource = default(NavMeshBuildSource);
        // groundSource.area = 0;
        // groundSource.shape = NavMeshBuildSourceShape.Box;
        // groundSource.size = _worldBounds.size.WithY(0.1f);
        // groundSource.transform = Matrix4x4.identity * Matrix4x4.Translate(_worldBounds.center.WithY(0));
        // _navMeshBuildSources.Add(groundSource);

        // Build settings for default agent
        NavMeshBuildSettings buildSettings = NavMesh.GetSettingsByID(0);

        // Create or update the nav mesh
        if (_navMesh == null)
        {
            _navMesh = NavMeshBuilder.BuildNavMeshData(buildSettings, _navMeshBuildSources, _worldBounds, Vector3.zero, Quaternion.identity);
            NavMesh.AddNavMeshData(_navMesh);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(_navMesh, buildSettings, _navMeshBuildSources, _worldBounds);
        }

        _isBuilt = true;
    }