Ideefixze / DTerrain

Destructible terrain in Unity
MIT License
417 stars 55 forks source link

Repaint a texture mode #8

Closed oelsons closed 7 months ago

oelsons commented 7 months ago

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.

oelsons commented 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
    });
}
oelsons commented 7 months ago

Got it working!

visualLayer.Paint(new PaintingParameters() { Position = new Vector2Int((int)(position.x visualLayer.PPU) - circleSize, (int)(position.y visualLayer.PPU) - circleSize), Shape = shapeCircle, PaintingMode = PaintingMode.RESTORE });