internal static void CollectGridSources(List <NavMeshBuildSource> sources, NavMeshBuilder2dWrapper builder)
        {
            var grid = GameObject.FindObjectOfType <Grid>();

            foreach (var modifier in grid.GetComponentsInChildren <NavMeshModifier>())
            {
                if (((0x1 << modifier.gameObject.layer) & builder.layerMask) == 0)
                {
                    continue;
                }
                if (!modifier.AffectsAgentType(builder.agentID))
                {
                    continue;
                }
                int area = builder.defaultArea;
                //if it is walkable
                if (builder.defaultArea != 1 && !modifier.ignoreFromBuild)
                {
                    var tilemap = modifier.GetComponent <Tilemap>();
                    if (tilemap != null)
                    {
                        if (builder.compressBounds)
                        {
                            tilemap.CompressBounds();
                        }

                        Debug.Log($"Walkable Bounds [{tilemap.name}]: {tilemap.localBounds}");
                        var box = BoxBoundSource(NavMeshSurface2d.GetWorldBounds(tilemap.transform.localToWorldMatrix, tilemap.localBounds));
                        box.area = builder.defaultArea;
                        sources.Add(box);
                    }
                }

                if (modifier.overrideArea)
                {
                    area = modifier.area;
                }
                if (!modifier.ignoreFromBuild)
                {
                    if (builder.CollectGeometry == NavMeshCollectGeometry.PhysicsColliders)
                    {
                        CollectSources(sources, modifier, area, builder);
                    }
                    else
                    {
                        var tilemap = modifier.GetComponent <Tilemap>();
                        if (tilemap != null)
                        {
                            CollectTileSources(sources, tilemap, area, builder);
                        }
                        var sprite = modifier.GetComponent <SpriteRenderer>();
                        if (sprite != null)
                        {
                            CollectSources(sources, sprite, area, builder);
                        }
                    }
                }
            }
            Debug.Log("Sources " + sources.Count);
        }
Пример #2
0
        internal static void CollectGridSources(List <NavMeshBuildSource> sources, int defaultArea, int layerMask, bool overrideByGrid, GameObject useMeshPrefab, bool compressBounds, Vector3 overrideVector)
        {
            var builder = new NavMeshBuilder2dWrapper();

            builder.defaultArea    = defaultArea;
            builder.layerMask      = layerMask;
            builder.useMeshPrefab  = useMeshPrefab;
            builder.overrideByGrid = overrideByGrid;
            builder.compressBounds = compressBounds;
            builder.overrideVector = overrideVector;
            var grid = GameObject.FindObjectOfType <Grid>();

            foreach (var tilemap in grid.GetComponentsInChildren <Tilemap>())
            {
                if (((0x1 << tilemap.gameObject.layer) & layerMask) == 0)
                {
                    continue;
                }
                int area     = defaultArea;
                var modifier = tilemap.GetComponent <NavMeshModifier>();
                //if it is walkable
                if (defaultArea != 1 && (modifier == null || (modifier != null && !modifier.ignoreFromBuild)))
                {
                    if (compressBounds)
                    {
                        tilemap.CompressBounds();
                    }

                    Debug.Log($"Walkable Bounds [{tilemap.name}]: {tilemap.localBounds}");
                    var box = BoxBoundSource(NavMeshSurface2d.GetWorldBounds(tilemap.transform.localToWorldMatrix, tilemap.localBounds));
                    box.area = defaultArea;
                    sources.Add(box);
                }

                if (modifier != null && modifier.overrideArea)
                {
                    area = modifier.area;
                }
                if (modifier != null && !modifier.ignoreFromBuild)
                {
                    CollectTileSources(sources, tilemap, area, builder);
                }
            }
            Debug.Log("Sources " + sources.Count);
        }