Version: 2017.2
public byte[] GetRawTextureData ();

戻り値

byte[] byte 配列としての Raw テクスチャデータ

説明

テクスチャから Raw データを取得します。

この関数で Raw データのテクスチャのバイト配列を取得しておくことで、Texture2D.LoadRawTextureData でテクスチャの読み込みができるようになります。こうすることにより、どんな形式のテクスチャ (圧縮形式を含む) でもシリアライズして読み込みができ、後にテクスチャに戻して読み込みすることもできます。

この関数は、Unity のシステムメモリコピーをテクスチャデータで返します。そのため、テクスチャは「読み込み可能」となっている必要があります。

Also note that the system memory copy might not match what is in the GPU texture data at the moment. For example, after calling SetPixels the system memory copy is already modified, but the GPU copy will only match after calling Apply(). Some cases of Graphics.CopyTexture might be copying only the GPU texture side (e.g. copying from a RenderTexture into a Texture2D), and this will not be reflected in GetRawTextureData contents.

using UnityEngine;

class CopyTexture : MonoBehaviour { // the source texture. Texture2D tex;

void Start() { // Create a copy of the texture by reading and applying the raw texture data. Texture2D texCopy = new Texture2D(tex.width, tex.height, tex.format, tex.mipmapCount > 1); texCopy.LoadRawTextureData(tex.GetRawTextureData()); texCopy.Apply(); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961