Closed oelsons closed 7 months ago
I managed to reset the whole block, texture + collider:
Class: PaintableLayer
Added functions:
public void ResetTexture()
{
foreach (var c in Chunks) {
SingleTextureSource textureSource = c.GetComponent<SingleTextureSource>();
textureSource.Texture = textureSource.OriginalTexture;
}
InitChunks();
}
public void ResetColliders()
{
Paint(new PaintingParameters() {
Position = new Vector2Int(Mathf.RoundToInt(transform.position.x), Mathf.RoundToInt(transform.position.y)),
Shape = Shape.GenerateShapeRect(OriginalTexture.width * PPU, OriginalTexture.height * PPU),
DestructionMode = DestructionMode.BUILD
});
}
Got it working!
Added enum: PaintingMode.RESTORE
Class: PaintableChunk
Function: Paint
Added:
else if (pp.PaintingMode == PaintingMode.RESTORE) {
for (int i = 0; i < common.width; i++) {
for (int j = 0; j < common.height; j++) {
cs[i * common.height + j] = ((SingleTextureSource)TextureSource).OriginalTexture.GetPixel(common.x + i, common.y + j);
}
}
}
Usage:
colliderLayer.Paint(new PaintingParameters() {
Position = new Vector2Int((int)(position.x * colliderLayer.PPU) - circleSize, (int)(position.y * colliderLayer.PPU) - circleSize),
Shape = shapeCircle,
DestructionMode = DestructionMode.BUILD
});
visualLayer.Paint(new PaintingParameters() { Position = new Vector2Int((int)(position.x visualLayer.PPU) - circleSize, (int)(position.y visualLayer.PPU) - circleSize), Shape = shapeCircle, PaintingMode = PaintingMode.RESTORE });
Awesome library!
From what I understand, the
DestructionMode.BUILD
option reconstructs the colliders. But I have not managed to make the visual come back, or "repaint" the texture.Am I missing something? Thanks.