private static int FindShapeIndex(D2dPolygonCollider.Cell cell, Vector2 point, int max) { for (var i = 0; i < cell.Shapes.Count; i++) { var shape = cell.Shapes[i]; if (shape.Contains(point) == true) { return(i); } } return(-1); }
public static void Build(D2dPolygonCollider.Cell cell, Stack <D2dPolygonCollider.Shape> shapePool, D2dPolygonCollider parent) { pathCount = 0; D2dCache.CachedList <Vector2> .Clear(); for (var i = 0; i < activeSquares.Count; i++) { square = activeSquares[i]; if (square.Mask != 0) { squareIndex = square.Index; points.Clear(); var newPoints = Trace(parent.Straighten); if (newPoints != null && newPoints.Length > 2) { var path = GetNextPath(); path.Points = newPoints; } } } if (pathCount > 0) { SortPaths(); } for (var i = 0; i < pathCount; i++) { var path = paths[i]; var shapeIndex = FindShapeIndex(cell, path.Left, i); // Combine? if (shapeIndex >= 0) { var shape = cell.Shapes[shapeIndex]; shape.Holes.Add(path); shape.Collider.pathCount += 1; shape.Collider.SetPath(shape.Collider.pathCount - 1, path.Points); } // New? else { var shape = shapePool.Count > 0 ? shapePool.Pop() : new D2dPolygonCollider.Shape(); shape.Outside = path; shape.Holes.Clear(); shape.Collider = parent.AddCollider(); shape.Collider.SetPath(0, path.Points); cell.Shapes.Add(shape); } } }