以下の内容はhttps://baba-s.hatenablog.com/entry/2023/10/05/101333より取得しました。


【Unity】ランタイムで Texture の Read Write をオンにする例

概要

Texture の Read Write はランタイムでは変更できないが、
ランタイムで Texture を複製すれば、Read Write が Texture を使えるようになる

ソースコード

// 戻り値の Texture は不要になったら Destroy すること
private static Texture2D DuplicateTexture( Texture source )
{
    var width         = source.width;
    var height        = source.height;
    var renderTexture = RenderTexture.GetTemporary( width, height );
    var destination   = new Texture2D( width, height );

    Graphics.Blit( source, renderTexture );

    RenderTexture.active = renderTexture;

    destination.ReadPixels
    (
        source: new Rect( 0, 0, width, height ),
        destX: 0,
        destY: 0
    );

    destination.Apply();

    RenderTexture.active = null;
    RenderTexture.ReleaseTemporary( renderTexture );

    return destination;
}

参考サイト様




以上の内容はhttps://baba-s.hatenablog.com/entry/2023/10/05/101333より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14