Skip to content

Instantly share code, notes, and snippets.

@babon
Created July 28, 2020 05:42
Show Gist options
  • Save babon/694decb36a2c0b4a005c6a6a5f47afbd to your computer and use it in GitHub Desktop.
Save babon/694decb36a2c0b4a005c6a6a5f47afbd to your computer and use it in GitHub Desktop.

Revisions

  1. babon created this gist Jul 28, 2020.
    25 changes: 25 additions & 0 deletions ExtensionlessTexture2DToPNG.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    [ContextMenuItem("Yo", "Yo")]
    public Texture2D tex;
    public void Yo()
    {
    Texture2D DeCompress(Texture2D source)
    {
    RenderTexture renderTex = RenderTexture.GetTemporary(
    source.width,
    source.height,
    0,
    RenderTextureFormat.Default,
    RenderTextureReadWrite.Linear);

    Graphics.Blit(source, renderTex);
    RenderTexture previous = RenderTexture.active;
    RenderTexture.active = renderTex;
    Texture2D readableText = new Texture2D(source.width, source.height);
    readableText.ReadPixels(new Rect(0, 0, renderTex.width, renderTex.height), 0, 0);
    readableText.Apply();
    RenderTexture.active = previous;
    RenderTexture.ReleaseTemporary(renderTex);
    return readableText;
    }
    System.IO.File.WriteAllBytes("C:/UnityProjects/arc/Assets/Models/Primitives/shadow4.png", DeCompress(tex).EncodeToPNG());
    }