// TODO: make it FillCircle () public void CutCircle(Vector2 center, float radius, IEnumerable <Collider2D> affectedColliders = null) { if (affectedColliders == null) { affectedColliders = Physics2D.OverlapCircleAll(center, radius); } var affectedSpriteRenderers = new HashSet <SpriteRenderer> (); foreach (var affectedCollider in affectedColliders) { SpriteRenderer spriteRenderer; if (colliderSpriteMap.TryGetValue(affectedCollider, out spriteRenderer)) { affectedSpriteRenderers.Add(spriteRenderer); } } foreach (var spriteRenderer in affectedSpriteRenderers) { if (RasterHelper.CutCircle(spriteRenderer, center, radius)) { UpdateSpriteColliders(spriteRenderer); } } }
// TODO: make it FillCircle () public static bool CutCircle(SpriteRenderer spriteRenderer, Vector2 center, float radius) { var tf = spriteRenderer.transform; center = tf.InverseTransformPoint(center); var localScaleVector = tf.InverseTransformPoint(tf.position + Vector3.right); var worldToLocalScale = localScaleVector.magnitude; radius *= worldToLocalScale; var sprite = spriteRenderer.sprite; int pixelX, pixelY; RasterHelper.SpriteCoordsToPixelCoords(sprite, center, out pixelX, out pixelY); float pixelsPerUnit = RasterHelper.GetPixelsPerUnit(sprite); int pixelRadius = Mathf.RoundToInt(radius * pixelsPerUnit); return(RasterHelper.CutCircle(sprite.texture, pixelX, pixelY, pixelRadius)); }