void CalculateSpriteBased(Sprite sprite, BorderMode borderMode) { var lastSprite = _lastUsedSprite; _lastUsedSprite = sprite; var spriteErrors = Diagnostics.CheckSprite(sprite); if (spriteErrors != Errors.NoError) { if (lastSprite != sprite) { WarnSpriteErrors(spriteErrors); } CalculateSolidFill(); return; } if (!sprite) { CalculateSolidFill(); return; } FillCommonParameters(); var spriteRect = Mathr.Move(Mathr.ToVector(sprite.rect), sprite.textureRect.position - sprite.rect.position - sprite.textureRectOffset); var textureRect = Mathr.ToVector(sprite.textureRect); var textureBorder = Mathr.BorderOf(spriteRect, textureRect); var textureSize = Vector2.zero; if (sprite.texture != null) { textureSize = new Vector2(sprite.texture.width, sprite.texture.height); } var fullMaskRect = LocalMaskRect(Vector4.zero); _parameters.maskRectUV = Mathr.Div(textureRect, textureSize); if (borderMode == BorderMode.Simple) { var textureRectInFullRect = Mathr.Div(textureBorder, Mathr.Size(spriteRect)); _parameters.maskRect = Mathr.ApplyBorder(fullMaskRect, Mathr.Mul(textureRectInFullRect, Mathr.Size(fullMaskRect))); } else { _parameters.maskRect = Mathr.ApplyBorder(fullMaskRect, textureBorder * GraphicToCanvasScale(sprite)); var fullMaskRectUV = Mathr.Div(spriteRect, textureSize); var adjustedBorder = AdjustBorders(sprite.border * GraphicToCanvasScale(sprite), fullMaskRect); _parameters.maskBorder = LocalMaskRect(adjustedBorder); _parameters.maskBorderUV = Mathr.ApplyBorder(fullMaskRectUV, Mathr.Div(sprite.border, textureSize)); } _parameters.texture = sprite.texture; _parameters.borderMode = borderMode; if (borderMode == BorderMode.Tiled) { _parameters.tileRepeat = MaskRepeat(sprite, _parameters.maskBorder); } }
void CalculateSpriteBased(Sprite sprite, BorderMode borderMode) { var lastSprite = _lastUsedSprite; _lastUsedSprite = sprite; var spriteErrors = Diagnostics.CheckSprite(sprite); if (spriteErrors != Errors.NoError) { if (lastSprite != sprite) { WarnSpriteErrors(spriteErrors); } CalculateSolidFill(); return; } if (!sprite) { CalculateSolidFill(); return; } FillCommonParameters(); var inner = DataUtility.GetInnerUV(sprite); var outer = DataUtility.GetOuterUV(sprite); var padding = DataUtility.GetPadding(sprite); var fullMaskRect = LocalMaskRect(Vector4.zero); _parameters.maskRectUV = outer; if (borderMode == BorderMode.Simple) { var normalizedPadding = Mathr.Div(padding, sprite.rect.size); _parameters.maskRect = Mathr.ApplyBorder(fullMaskRect, Mathr.Mul(normalizedPadding, Mathr.Size(fullMaskRect))); } else { _parameters.maskRect = Mathr.ApplyBorder(fullMaskRect, padding * SpriteToCanvasScale(sprite)); var adjustedBorder = AdjustBorders(sprite.border * SpriteToCanvasScale(sprite), fullMaskRect); _parameters.maskBorder = LocalMaskRect(adjustedBorder); _parameters.maskBorderUV = inner; } _parameters.texture = sprite.texture; _parameters.borderMode = borderMode; if (borderMode == BorderMode.Tiled) { _parameters.tileRepeat = MaskRepeat(sprite, _parameters.maskBorder); } }