Texture2D 二維紋理


Texture2D 二維紋理
紋理處理類。使用這個動態創建紋理或修改現有紋理資源。

變量
mipmapCount  這個紋理有多少mipmap等級(只讀)
format       紋理中像素的數據格式(只讀)

函數

SetPixel 在坐標(x,y)設置一個像素的顏色
SetPixel (x : int, y : int, color : Color)

GetPixel 獲取坐標(x,y)處像素顏色
GetPixel (x : int, y : int)

GetPixelBilinear 返回在正規化紋理坐標(u,v)處的過濾的像素顏色。
GetPixelBilinear (u : float, v : float)
注:坐標U和V 是從0.0到1.0的值,就像是網格模型上的UV坐標

SetPixels 設置一塊像素顏色
SetPixels (x : int, y : int, blockWidth : int, blockHeight : int, colors : Color[], miplevel : int = 0)
注:從x,y點開始的blockWidth(塊的寬)乘以blockHeight(塊的高)的區域

LoadImage 根據字節數組載入圖片
LoadImage (data : byte[])
public class example : MonoBehaviour {
    public TextAsset imageTextAsset;
    void Start() {
        Texture2D tex = new Texture2D(4, 4);
        tex.LoadImage(imageTextAsset.bytes);
        renderer.material.mainTexture = tex;
    }
}

GetPixels 獲取一塊像素顏色
GetPixels (x : int, y : int, blockWidth : int, blockHeight : int, miplevel : int = 0) : Color[]

Apply 實際應用前面的SetPixel和Setpixels的更改
Texture2D texture = new Texture2D(128, 128);
texture.Apply();

Resize 調整紋理大小 若要調整紋理,這個紋理需要導入設置為Is Readable(可讀)
Resize (width : int, height : int) : bool

PackTextures 打包多個紋理到紋理集合中,返回Rect[]類型,矩形的數組包含每個輸入的紋理的UV坐標集合
PackTextures (textures : Texture2D[], padding : int, maximumAtlasSize : int = 2048) : Rect[]
textures 紋理數組被打包到集合中
padding  打包紋理的像素間距
maximumAtlasSize  調整紋理的最大尺寸

ReadPixels 讀取屏幕像素信息並存儲為紋理數據
ReadPixels (source : Rect, destX : int, destY : int, recalculateMipMaps : bool = true) : void
如果 recalculateMipMaps 設置為真,這個貼圖的mipmaps就會更新
如果 recalculateMipMaps設置為假,你需要調用Apply重新計算它們
 Inherited members繼承成員

width    以像素為單位的貼圖寬度 (只讀)
height    以像素為單位的貼圖的高度(只讀)
filterMode    貼圖的過濾模式
anisoLevel 貼圖的各向異性過濾等級。此變量的值的范圍從 1 - 9 ,其中 1 等於沒有過濾而9 等於完全過濾。值越大,貼圖在淺角度看時顯得更清
晰。較低的值表示貼圖在淺角度顯得更模糊。
wrapMode 循環模式(重復或強制拉伸)在貼圖邊界以設置貼圖的重復模式的方式避免不真實的情況,使用強制貼圖邊界拉伸 TextureWrapMode.Clamp 
或者貼圖重復平鋪 TextureWrapMode.Repeat
mipMapBias 多級紋理偏移量

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM