Exemplo n.º 1
0
        private void RebuildCell(ref D2dPolygonColliderCell cell, int cellX, int cellY)
        {
            var xMin = CellSize * cellX;
            var yMin = CellSize * cellY;
            var xMax = Mathf.Min(CellSize + xMin, destructible.AlphaWidth);
            var yMax = Mathf.Min(CellSize + yMin, destructible.AlphaHeight);

            D2dColliderBuilder.AlphaData   = destructible.AlphaData;
            D2dColliderBuilder.AlphaWidth  = destructible.AlphaWidth;
            D2dColliderBuilder.AlphaHeight = destructible.AlphaHeight;
            D2dColliderBuilder.MinX        = xMin;
            D2dColliderBuilder.MinY        = yMin;
            D2dColliderBuilder.MaxX        = xMax;
            D2dColliderBuilder.MaxY        = yMax;

            D2dColliderBuilder.CalculatePolyCells();

            if (cell == null)
            {
                cell = D2dPolygonColliderCell.Get();
            }

            D2dColliderBuilder.BuildPoly(cell, tempColliders, child, Weld, Detail);

            cell.UpdateColliderSettings(IsTrigger, Material);
        }
        private void RebuildCell(D2dPolygonColliderCell cell, int x, int y)
        {
            var xMin = CellSize * x;
            var yMin = CellSize * y;
            var xMax = Mathf.Min(CellSize + xMin, destructible.AlphaWidth);
            var yMax = Mathf.Min(CellSize + yMin, destructible.AlphaHeight);

            D2dColliderBuilder.CalculatePoly(destructible.AlphaData, destructible.AlphaWidth, xMin, xMax, yMin, yMax);

            D2dColliderBuilder.BuildPoly(cell, unusedColliders, child, Detail);

            cell.UpdateColliderSettings(IsTrigger, Material);
        }
Exemplo n.º 3
0
        protected override void OnAlphaDataModified(D2dRect rect)
        {
            base.OnAlphaDataModified(rect);

            if (CellSize <= 0)
            {
                Mark(); Sweep(); return;
            }

            if (destructible.AlphaWidth != expectedWidth || destructible.AlphaHeight != expectedHeight || cells == null || cells.Length != cellWidth * cellHeight || CellSize != expectedCellSize)
            {
                Rebuild(); return;
            }

            var cellXMin = rect.MinX / CellSize;
            var cellYMin = rect.MinY / CellSize;
            var cellXMax = (rect.MaxX + 1) / CellSize;
            var cellYMax = (rect.MaxY + 1) / CellSize;

            cellXMin = Mathf.Clamp(cellXMin, 0, cellWidth - 1);
            cellXMax = Mathf.Clamp(cellXMax, 0, cellWidth - 1);
            cellYMin = Mathf.Clamp(cellYMin, 0, cellHeight - 1);
            cellYMax = Mathf.Clamp(cellYMax, 0, cellHeight - 1);

            for (var cellY = cellYMin; cellY <= cellYMax; cellY++)
            {
                var offset = cellY * cellWidth;

                for (var cellX = cellXMin; cellX <= cellXMax; cellX++)
                {
                    var index = cellX + offset;
                    var cell  = cells[index];

                    if (cell != null)
                    {
                        cell.Clear(tempColliders);

                        cells[index] = D2dPolygonColliderCell.Add(cell);
                    }

                    RebuildCell(ref cells[index], cellX, cellY);
                }
            }

            Sweep();
        }
Exemplo n.º 4
0
        public static void BuildPoly(D2dPolygonColliderCell cell, Stack <PolygonCollider2D> tempColliders, GameObject child, float weld, float detail)
        {
            // Find the start points of paths
            for (var i = 0; i < pointCount; i++)
            {
                var point = points[i];

                // Build polygon from point
                if (point.Used == false)
                {
                    Trace(point);
                    WeldLines(weld);
                    OptimizeEdges(detail);

                    cell.AddPolygon(tempColliders, child, ExtractPoints(1));
                }
            }
        }
Exemplo n.º 5
0
        private void Mark()
        {
            tempColliders.Clear();

            if (cells != null)
            {
                for (var i = cells.Length - 1; i >= 0; i--)
                {
                    var cell = cells[i];

                    if (cell != null)
                    {
                        cell.Clear(tempColliders);

                        cells[i] = D2dPolygonColliderCell.Add(cell);
                    }
                }
            }
        }
        public static void BuildPoly(D2dPolygonColliderCell cell, List <PolygonCollider2D> unusedColliders, GameObject child, float detail)
        {
            cell.Clear(unusedColliders);

            // Find the start points of paths
            for (var i = 0; i < pointCount; i++)
            {
                var point = points[i];

                if (point.Used == false)
                {
                    Trace(point);
                    WeldLines();
                    OptimizeEdges(detail);

                    cell.AddPolygon(unusedColliders, child, ExtractPoints(1));
                }
            }

            // Remove unused polygons
            cell.Trim();
        }
 private void Mark(D2dPolygonColliderCell cell)
 {
     cell.Clear(unusedColliders);
 }
Exemplo n.º 8
0
        public static D2dPolygonColliderCell Add(D2dPolygonColliderCell cell)
        {
            pool.Push(cell);

            return(null);
        }