private void _updateNavMesh()
    {
        //If we have no target agents to build navmeshs for then return
        if (AgentNavMeshes.Length == 0)
        {
            return;
        }

        bool hasChanges = RealtimeNavMeshSource.UpdateAllSources(ZoneArea.bounds);

        if (hasChanges)
        {
            print("_updateNavMesh(): hasChanges");

            foreach (var agentNavMesh in AgentNavMeshes)
            {
                print("_updateNavMesh(): updating agent (" + agentNavMesh.AgentId + ")");
                var defaultBuildSettings = NavMesh.GetSettingsByIndex(agentNavMesh.AgentId);
                print("defaultBuildSettings agentId: " + defaultBuildSettings.agentTypeID);


                NavMeshBuilder.UpdateNavMeshData(agentNavMesh.Data, defaultBuildSettings, RealtimeNavMeshSource.AllSources, ZoneArea.bounds);
            }
        }
    }
Example #2
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);
        var bounds = QuantizedBounds();

        NavMeshBuilder.CollectSources(bounds, navMeshLayers, NavMeshCollectGeometry.RenderMeshes, 0, new List <NavMeshBuildMarkup>(), m_Sources);

        for (int i = 0; i < m_Sources.Count; i++)
        {
            if (m_Sources[i].component.transform.gameObject.layer == 19)
            {
                NavMeshBuildSource m = new NavMeshBuildSource();
                m            = m_Sources[i];
                m.area       = 3;
                m_Sources[i] = m;
            }
        }
        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.CollectMeshes(ref m_Sources);
        NavMeshSourceTag.CollectModifierVolumes(LayerMask.GetMask("Default"), ref m_Sources);

        var defaultBuildSettings = NavMesh.GetSettingsByID(AgentID);
        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }

        /*
         * NavMeshSourceTag.Collect(ref m_Sources);
         * var defaultBuildSettings = NavMesh.GetSettingsByID(0);
         * var bounds = QuantizedBounds();
         *
         * if (asyncUpdate)
         * m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
         * else
         * NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
         */
    }
Example #4
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        //Don't do anything if the target area hasn't changed
        if (asyncUpdate && center == (m_Tracked ? m_Tracked.position : transform.position))
        {
            return;
        }

        NavMeshSourceTag.Collect(ref m_Sources);
        var defaultBuildSettings = NavMesh.GetSettingsByIndex(0);

        defaultBuildSettings.overrideVoxelSize = true;
        defaultBuildSettings.voxelSize         = 0.4f;
        defaultBuildSettings.overrideTileSize  = true;
        defaultBuildSettings.tileSize          = 16;

        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
    private void BuildNavMesh(bool Async)
    {
        Bounds navMeshBounds = new Bounds(Player.transform.position, NavMeshSize);
        List <NavMeshBuildMarkup> markups = new List <NavMeshBuildMarkup>();

        List <NavMeshModifier> modifiers;

        for (int index = 0; index < Surfaces.Length; index++)
        {
            if (Surfaces[index].collectObjects == CollectObjects.Children)
            {
                modifiers = new List <NavMeshModifier>(GetComponentsInChildren <NavMeshModifier>());
            }
            else
            {
                modifiers = NavMeshModifier.activeModifiers;
            }

            for (int i = 0; i < modifiers.Count; i++)
            {
                if (((Surfaces[index].layerMask & (1 << modifiers[i].gameObject.layer)) == 1) &&
                    modifiers[i].AffectsAgentType(Surfaces[index].agentTypeID))
                {
                    markups.Add(new NavMeshBuildMarkup()
                    {
                        root            = modifiers[i].transform,
                        overrideArea    = modifiers[i].overrideArea,
                        area            = modifiers[i].area,
                        ignoreFromBuild = modifiers[i].ignoreFromBuild
                    });
                }
            }

            if (Surfaces[index].collectObjects == CollectObjects.Children)
            {
                NavMeshBuilder.CollectSources(transform, Surfaces[index].layerMask, Surfaces[index].useGeometry, Surfaces[index].defaultArea, markups, Sources);
            }
            else
            {
                NavMeshBuilder.CollectSources(navMeshBounds, Surfaces[index].layerMask, Surfaces[index].useGeometry, Surfaces[index].defaultArea, markups, Sources);
            }

            Sources.RemoveAll(RemoveNavMeshAgentPredicate);

            if (Async)
            {
                AsyncOperation navMeshUpdateOperation = NavMeshBuilder.UpdateNavMeshDataAsync(NavMeshDatas[index], Surfaces[index].GetBuildSettings(), Sources, navMeshBounds);
                navMeshUpdateOperation.completed += HandleNavMeshUpdate;
            }
            else
            {
                NavMeshBuilder.UpdateNavMeshData(NavMeshDatas[index], Surfaces[index].GetBuildSettings(), Sources, navMeshBounds);
                OnNavMeshUpdate?.Invoke(navMeshBounds);
            }
        }
    }
Example #6
0
    // void UpdateNavMesh(bool asyncUpdate = false)
    // {
    //  // TileChunk.Collect(ref m_Sources);
    //     var m_autoTileMap = AutoTileMap_Editor.Instance;
    //     if( m_autoTileMap != null && m_autoTileMap.IsInitialized && m_autoTileMap.IsPlayMode && m_autoTileMap.m_tileChunkPoolNode != null)
    //  {
    //         m_autoTileMap.m_tileChunkPoolNode.BuildNavByMesh(ref m_Sources);
    //         var defaultBuildSettings = NavMesh.GetSettingsByID(0);
    //         var bounds = QuantizedBounds();
    //         if (asyncUpdate)
    //             m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
    //         else
    //             NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
    //     }
    // }

    public void UpdateNavMesh(List <NavMeshBuildSource> sources)
    {
        Debug.Log("UpdateNavMesh");
        NavMeshBuildSettings defaultBuildSettings = NavMesh.GetSettingsByID(0);

        defaultBuildSettings.overrideTileSize = true;
        defaultBuildSettings.tileSize         = 16;
        var bounds = QuantizedBounds();

        NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, sources, bounds);
    }
    void BakeNavMesh()
    {
        navMeshData = new NavMeshData(0);


        NavMeshSourceTag.Collect(ref sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);
        var bounds = new Bounds(center, size);

        NavMeshBuilder.UpdateNavMeshData(navMeshData, defaultBuildSettings, sources, bounds);
        navMeshInstance = NavMesh.AddNavMeshData(navMeshData);
        //NavMeshBuilder.BuildNavMeshData(defaultBuildSettings, sources, bounds, this.gameObject.transform.position, this.gameObject.transform.rotation);
    }
    private void BuildNavMesh(bool Async)
    {
        Bounds navMeshBounds = new Bounds(Player.transform.position, NavMeshSize);
        List <NavMeshBuildMarkup> markups = new List <NavMeshBuildMarkup>();

        List <NavMeshModifier> modifiers;

        if (Surface.collectObjects == CollectObjects.Children)
        {
            modifiers = new List <NavMeshModifier>(GetComponentsInChildren <NavMeshModifier>());
        }
        else
        {
            modifiers = NavMeshModifier.activeModifiers;
        }

        for (int i = 0; i < modifiers.Count; i++)
        {
            if (((Surface.layerMask & (1 << modifiers[i].gameObject.layer)) == 1) &&
                modifiers[i].AffectsAgentType(Surface.agentTypeID))
            {
                markups.Add(new NavMeshBuildMarkup()
                {
                    root            = modifiers[i].transform,
                    overrideArea    = modifiers[i].overrideArea,
                    area            = modifiers[i].area,
                    ignoreFromBuild = modifiers[i].ignoreFromBuild
                });
            }
        }

        if (Surface.collectObjects == CollectObjects.Children)
        {
            NavMeshBuilder.CollectSources(transform, Surface.layerMask, Surface.useGeometry, Surface.defaultArea, markups, Sources);
        }
        else
        {
            NavMeshBuilder.CollectSources(navMeshBounds, Surface.layerMask, Surface.useGeometry, Surface.defaultArea, markups, Sources);
        }

        Sources.RemoveAll(source => source.component != null && source.component.gameObject.GetComponent <NavMeshAgent>() != null);

        if (Async)
        {
            NavMeshBuilder.UpdateNavMeshDataAsync(NavMeshData, Surface.GetBuildSettings(), Sources, new Bounds(Player.transform.position, NavMeshSize));
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(NavMeshData, Surface.GetBuildSettings(), Sources, new Bounds(Player.transform.position, NavMeshSize));
        }
    }
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTagImproved.Collect(ref m_Sources, agentTypeID);
        var buildSettings = NavMesh.GetSettingsByID(agentTypeID);
        var bounds        = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, buildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, buildSettings, m_Sources, bounds);
        }
    }
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag1.Collect(ref m_Sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);
        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
Example #11
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref m_Sources); //←NavMeshSourceTagタグをセットしたオブジェクトをすべて集めてListに格納
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);
        var bounds = QuantizedBounds();          //←メッシュ生成の範囲をセット

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);    //←実際のメッシュ生成を行っている部分。
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
    private void UpdateNavMesh(bool isAsync = false)
    {
        NavMeshSourceTag.Collect(ref sources);
        NavMeshBuildSettings settings;

        settings = NavMesh.GetSettingsByID(0);
        Bounds bounds = QuantizeBounds();

        if (isAsync)
        {
            operation = NavMeshBuilder.UpdateNavMeshDataAsync(navMesh, settings, sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(navMesh, settings, sources, bounds);
        }
    }
        void UpdateNavMesh(bool asyncUpdate = false)
        {
            CollectMeshSources();


            //NavMeshSourceTag.Collect(ref m_Sources);
            var defaultBuildSettings = NavMesh.GetSettingsByID(0);

            if (asyncUpdate)
            {
                /*m_Operation = */ NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, meshSources, dungeonBounds);
            }
            else
            {
                NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, meshSources, dungeonBounds);
            }
        }
        void Build(bool asyncUpdate)
        {
            Bounds bounds = QuantizedBounds();
            //Use agent settings
            NavMeshBuildSettings agentBuildSettings = NavMesh.GetSettingsByID(AgentID);

            agentBuildSettings.minRegionArea = MinRegionArea;

            //Bake updated nav mesh
            if (asyncUpdate)
            {
                Operation = NavMeshBuilder.UpdateNavMeshDataAsync(TheNavMeshData, agentBuildSettings, NavMeshRegionTag.Terrains, bounds);
            }
            else
            {
                NavMeshBuilder.UpdateNavMeshData(TheNavMeshData, agentBuildSettings, NavMeshRegionTag.Terrains, bounds);
            }
        }
Example #15
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        m_Sources.Clear();

        BoxCollider[] bcs = GetComponentsInChildren <BoxCollider>();



        Matrix4x4 worldToLocal = transform.worldToLocalMatrix;

        foreach (BoxCollider b in bcs)
        {
            var s = new NavMeshBuildSource();
            s.shape     = NavMeshBuildSourceShape.Box;
            s.transform = b.transform.localToWorldMatrix;
            s.size      = b.size;
            s.area      = areaId;

            var m = b.transform.localToWorldMatrix;


            m_Sources.Add(s);
        }
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);

        defaultBuildSettings.agentRadius   = 0.08f;
        defaultBuildSettings.minRegionArea = 0.5f;

        bounds = CalculateWorldBounds(m_Sources);

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
Example #16
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref m_Sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);

        defaultBuildSettings.agentClimb    = 0.5f;
        defaultBuildSettings.minRegionArea = 50000.0f;
        defaultBuildSettings.agentSlope    = 30;
        defaultBuildSettings.agentRadius   = 0.5f;
        defaultBuildSettings.voxelSize     = 0.75f;

        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            //m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }
Example #17
0
    void UpdateNavMesh(bool asyncUpdate = false)
    {
        NavMeshSourceTag.Collect(ref m_Sources);
        var defaultBuildSettings = NavMesh.GetSettingsByID(0);

        defaultBuildSettings.voxelSize   = voxelSize;
        defaultBuildSettings.tileSize    = tileSize;
        defaultBuildSettings.agentClimb  = agentClimb;
        defaultBuildSettings.agentRadius = agentRadius;
        defaultBuildSettings.agentHeight = agentHeight;



        var bounds = QuantizedBounds();

        if (asyncUpdate)
        {
            m_Operation = NavMeshBuilder.UpdateNavMeshDataAsync(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
        else
        {
            NavMeshBuilder.UpdateNavMeshData(m_NavMesh, defaultBuildSettings, m_Sources, bounds);
        }
    }