예제 #1
0
        public override void ApplyBeforeConnections(Graph graph)
        {
            var layer  = this.gameObject.layer;
            var bounds = this.bounds;

            bounds.center += this.transform.position;

            var nodes = PoolListCopyable <Node> .Spawn(10);

            graph.GetNodesInBounds(nodes, bounds);
            foreach (var node in nodes)
            {
                var ray = new Ray(node.worldPosition + Vector3.up * 10f, Vector3.down);
                if (Physics.Raycast(ray, out var hit, 1000f, this.layerMask) == true)
                {
                    if (hit.collider.gameObject.layer == layer)
                    {
                        var dt = this.penaltyDelta;
                        if (dt < 0)
                        {
                            node.penalty -= (uint)(-this.penaltyDelta);
                        }
                        else
                        {
                            node.penalty += (uint)this.penaltyDelta;
                        }

                        node.tag = this.tag;
                    }
                }
            }
            PoolListCopyable <Node> .Recycle(ref nodes);
        }
예제 #2
0
        public override void ApplyAfterConnections(Graph graph)
        {
            var nodes = PoolListCopyable <Node> .Spawn(10);

            var bounds = this.bounds;

            bounds.center += this.transform.position;
            graph.GetNodesInBounds(nodes, this.bounds);
            foreach (var node in nodes)
            {
                if (this.modifyWalkability == true)
                {
                    node.walkable = this.walkable;
                }
            }
        }
        public override void ApplyAfterConnections(Graph graph)
        {
            var visited = PoolHashSet <Node> .Spawn();

            {
                var gridGraph = (GridGraph)graph;
                var result    = PoolListCopyable <Node> .Spawn(1);

                graph.GetNodesInBounds(result, new Bounds(graph.graphCenter, (Vector3)gridGraph.size * gridGraph.nodeSize), Constraint.Empty);
                {
                    foreach (var node in result)
                    {
                        var worldPos = node.worldPosition;
                        var cellPos  = this.tilemap.layoutGrid.WorldToCell(worldPos);
                        var tile     = this.tilemap.GetTile(cellPos);
                        for (int i = 0; i < this.items.Length; ++i)
                        {
                            var item = this.items[i];
                            if (item.modifyWalkability == false)
                            {
                                continue;
                            }

                            if (item.requiredTile == null || item.requiredTile == tile)
                            {
                                if (item.checkSprite == true)
                                {
                                    var idx = System.Array.IndexOf(item.spriteOneOf, this.tilemap.GetSprite(cellPos));
                                    if (idx < 0)
                                    {
                                        continue;
                                    }
                                }

                                if (visited.Contains(node) == false)
                                {
                                    visited.Add(node);
                                    node.walkable = item.walkable;
                                }
                            }
                        }
                    }
                }
                PoolListCopyable <Node> .Recycle(ref result);
            }
            PoolHashSet <Node> .Recycle(ref visited);
        }
예제 #4
0
        public override void ApplyAfterConnections(Graph graph)
        {
            var halfOffset = new Vector3(this.tilemap.cellSize.x, 0f, this.tilemap.cellSize.z) * 0.5f;

            var visited = PoolHashSet <Node> .Spawn();

            foreach (var pos in this.bounds.allPositionsWithin)
            {
                var worldPos = pos + halfOffset;
                var cellPos  = this.tilemap.layoutGrid.WorldToCell(worldPos);
                var tile     = this.tilemap.GetTile(cellPos);
                for (int i = 0; i < this.items.Length; ++i)
                {
                    var item = this.items[i];
                    if (item.modifyWalkability == false)
                    {
                        continue;
                    }

                    if (item.requiredTile == null || item.requiredTile == tile)
                    {
                        if (item.checkSprite == true)
                        {
                            var idx = System.Array.IndexOf(item.spriteOneOf, this.tilemap.GetSprite(cellPos));
                            if (idx < 0)
                            {
                                continue;
                            }
                        }

                        var result = PoolListCopyable <Node> .Spawn(1);

                        graph.GetNodesInBounds(result, new Bounds(worldPos, this.tilemap.cellSize * 0.5f));
                        foreach (var node in result)
                        {
                            if (visited.Contains(node) == false)
                            {
                                visited.Add(node);
                                node.walkable = item.walkable;
                            }
                        }
                        PoolListCopyable <Node> .Recycle(ref result);
                    }
                }
            }
            PoolHashSet <Node> .Recycle(ref visited);
        }
예제 #5
0
        public override void ApplyAfterConnections(Graph graph)
        {
            var nodes = PoolListCopyable <Node> .Spawn(10);

            var bounds = this.bounds;

            bounds.center += this.transform.position;
            graph.GetNodesInBounds(nodes, this.bounds, Constraint.Empty);
            foreach (var node in nodes)
            {
                if (this.modifyWalkability == true)
                {
                    var ray = new Ray(node.worldPosition + Vector3.up * 10f, Vector3.down);
                    if (Physics.Raycast(ray, out var hit, 1000f, this.layerMask) == true)
                    {
                        node.walkable = this.walkable;
                    }
                }
            }
        }
예제 #6
0
        public override void ApplyBeforeConnections(Graph graph)
        {
            var visited = PoolHashSet <Node> .Spawn();

            foreach (var pos in this.bounds.allPositionsWithin)
            {
                var tile = this.tilemap.GetTile(pos);
                for (int i = 0; i < this.items.Length; ++i)
                {
                    var item = this.items[i];
                    if (item.requiredTile == tile)
                    {
                        var worldPos = this.tilemap.CellToWorld(pos);
                        var result   = PoolList <Node> .Spawn(1);

                        graph.GetNodesInBounds(result, new Bounds(worldPos + new Vector3(this.tilemap.cellSize.x, 0f, this.tilemap.cellSize.z) * 0.5f, this.tilemap.cellSize));
                        foreach (var node in result)
                        {
                            if (visited.Contains(node) == false)
                            {
                                visited.Add(node);
                                var dt = item.penaltyDelta;
                                if (dt < 0)
                                {
                                    node.penalty -= (uint)(-item.penaltyDelta);
                                }
                                else
                                {
                                    node.penalty += (uint)item.penaltyDelta;
                                }

                                node.tag = item.tag;
                            }
                        }
                        PoolList <Node> .Recycle(ref result);
                    }
                }
            }
            PoolHashSet <Node> .Recycle(ref visited);
        }
예제 #7
0
        public override void ApplyBeforeConnections(Graph graph)
        {
            var halfOffset = new Vector3(this.tilemap.cellSize.x, 0f, this.tilemap.cellSize.z) * 0.5f;

            var visited = PoolHashSet <Node> .Spawn();

            foreach (var pos in this.bounds.allPositionsWithin)
            {
                var worldPos = pos + halfOffset;
                var cellPos  = this.tilemap.layoutGrid.WorldToCell(worldPos);
                var tile     = this.tilemap.GetTile(cellPos);
                for (int i = 0; i < this.items.Length; ++i)
                {
                    var item = this.items[i];
                    if (item.requiredTile == tile)
                    {
                        var result = PoolList <Node> .Spawn(1);

                        graph.GetNodesInBounds(result, new Bounds(worldPos, this.tilemap.cellSize * 0.5f));
                        foreach (var node in result)
                        {
                            if (visited.Contains(node) == false)
                            {
                                visited.Add(node);

                                node.penalty += item.penaltyDelta;
                                node.height  += item.heightDelta;
                                node.tag      = item.tag;
                            }
                        }
                        PoolList <Node> .Recycle(ref result);
                    }
                }
            }
            PoolHashSet <Node> .Recycle(ref visited);
        }