facebook twitter hatena line email

「Unity/UIImage/Texture」の版間の差分

提供: 初心者エンジニアの簡易メモ
移動: 案内検索
(ページの作成:「==Textureコピー== <pre> var tmpTexture = Copy((Texture2D)texture); tmpTexture.Apply(); </pre> コピーロジック <pre> public Texture2D Copy(Texture2D source) {...」)
 
(Textureの値渡し)
(同じ利用者による、間の2版が非表示)
行1: 行1:
==Textureコピー==
+
==Textureの値渡し==
 
<pre>
 
<pre>
var tmpTexture = Copy((Texture2D)texture);
+
var tmpTexture = CopyTexture((Texture2D)texture);
 
tmpTexture.Apply();
 
tmpTexture.Apply();
 
</pre>
 
</pre>
 
コピーロジック
 
コピーロジック
 
<pre>
 
<pre>
public Texture2D Copy(Texture2D source)
+
public Texture2D CopyTexture(Texture2D source)
 
{
 
{
 
     var texture = new Texture2D(source.width, source.height, TextureFormat.RGBA32, false);
 
     var texture = new Texture2D(source.width, source.height, TextureFormat.RGBA32, false);
行19: 行19:
 
</pre>
 
</pre>
 
参考:https://qiita.com/UnityFoo/items/25b8304036e0a8ca7798
 
参考:https://qiita.com/UnityFoo/items/25b8304036e0a8ca7798
 +
 +
==Texture高速化==
 +
参考:https://baba-s.hatenablog.com/entry/2022/08/29/103639

2023年3月10日 (金) 03:56時点における版

Textureの値渡し

var tmpTexture = CopyTexture((Texture2D)texture);
tmpTexture.Apply();

コピーロジック

public Texture2D CopyTexture(Texture2D source)
{
    var texture = new Texture2D(source.width, source.height, TextureFormat.RGBA32, false);
    var renderTexture = new RenderTexture(texture.width, texture.height, 32);
    Graphics.Blit(source, renderTexture);
    RenderTexture.active = renderTexture;
    texture.ReadPixels(new Rect(0, 0, renderTexture.width, renderTexture.height), 0, 0);
    RenderTexture.active = null;
    RenderTexture.DestroyImmediate(renderTexture);
    return texture;
}

参考:https://qiita.com/UnityFoo/items/25b8304036e0a8ca7798

Texture高速化

参考:https://baba-s.hatenablog.com/entry/2022/08/29/103639