position | 要在其中绘制纹理的屏幕矩形。 |
image | 要显示的 Texture。 |
scaleMode | 当图像的宽高比不适合要绘制的宽高比时,如何缩放图像。 |
imageAspect | 用于源图像的宽高比。如果为 0(默认值),则使用图像的宽高比。 |
mipLevel | 要进行采样的 Mip 级别。如果为负值,将对纹理进行正常采样。 它会设置材质 _Mip 属性。 |
在矩形内绘制纹理的 Alpha 通道。
另请参阅:GUI.color、GUI.contentColor
编辑器窗口中的 Alpha 纹理。
// Load a texture, display the texture, display its alpha channel and // show a preview of the inverted texture
class EditorGUITextures extends EditorWindow {
var texture : Texture2D; var invertedTexture : Texture2D; var showInverted = false;
@MenuItem("Examples/Texture Previewer") static function Init() { var window = GetWindow(EditorGUITextures); window.position = Rect(0,0,400, 200); window.Show(); }
function OnGUI() { texture = EditorGUI.ObjectField(Rect(3,3,200,20), "Add a Texture:", texture, Texture); if(GUI.Button(Rect(208,3, position.width - 210, 20),"Process Inverted")) { if(invertedTexture) DestroyImmediate(invertedTexture); //Copy the new texture invertedTexture = new Texture2D(texture.width, texture.height, texture.format, (texture.mipmapCount != 0)); for (var m : int = 0; m < texture.mipmapCount; m++) invertedTexture.SetPixels(texture.GetPixels(m), m); InvertColors(); showInverted = true; } if(texture) { EditorGUI.PrefixLabel(Rect(25,45,100,15),0,GUIContent("Preview:")); EditorGUI.DrawPreviewTexture(Rect(25,60,100,100),texture); EditorGUI.PrefixLabel(Rect(150,45,100,15),0,GUIContent("Alpha:")); EditorGUI.DrawTextureAlpha(Rect(150,60,100,100),texture); EditorGUI.PrefixLabel(Rect(275,45,100,15),0,GUIContent("Inverted:")); if(showInverted) EditorGUI.DrawPreviewTexture(Rect(275,60,100,100),invertedTexture); if(GUI.Button(Rect(3,position.height - 25, position.width-6,20),"Clear texture")) { texture = EditorGUIUtility.whiteTexture; showInverted = false; } } else { EditorGUI.PrefixLabel( Rect(3,position.height - 25,position.width - 6, 20), 0, GUIContent("No texture found")); } }
function InvertColors() { for (var m : int = 0; m < invertedTexture.mipmapCount; m++) { var c : Color[] = invertedTexture.GetPixels(m); for (var i : int = 0 ;i < c.Length; i++) { c[i].r = 1 - c[i].r; c[i].g = 1 - c[i].g; c[i].b = 1 - c[i].b; } invertedTexture.SetPixels(c, m); } invertedTexture.Apply(); } function OnInspectorUpdate() { Repaint(); } }