Class RawImage
Displays a Texture2D for the UI System.
Inheritance
Inherited Members
Namespace: UnityEngine.UI
Assembly: UnityEngine.UI.dll
Syntax
[RequireComponent(typeof(CanvasRenderer))]
[AddComponentMenu("UI/Raw Image", 12)]
public class RawImage : MaskableGraphic, ICanvasElement, IClippable, IMaskable, IMaterialModifier
Remarks
If you don't have or don't wish to create an atlas, you can simply use this script to draw a texture. Keep in mind though that this will create an extra draw call with each RawImage present, so it's best to use it only for backgrounds or temporary visible graphics.
Constructors
RawImage()
Declaration
protected RawImage()
Properties
mainTexture
Returns the texture used to draw this Graphic.
Declaration
public override Texture mainTexture { get; }
Property Value
Type | Description |
---|---|
Texture |
Overrides
texture
The RawImage's texture to be used.
Declaration
public Texture texture { get; set; }
Property Value
Type | Description |
---|---|
Texture |
Remarks
Use this to alter or return the Texture the RawImage displays. The Raw Image can display any Texture whereas an Image component can only show a Sprite Texture. Note : Keep in mind that using a RawImage creates an extra draw call with each RawImage present, so it's best to use it only for backgrounds or temporary visible graphics.Note: Keep in mind that using a RawImage creates an extra draw call with each RawImage present, so it's best to use it only for backgrounds or temporary visible graphics.
Examples
//Create a new RawImage by going to Create>UI>Raw Image in the hierarchy.
//Attach this script to the RawImage GameObject.
using UnityEngine;
using UnityEngine.UI;
public class RawImageTexture : MonoBehaviour
{
RawImage m_RawImage;
//Select a Texture in the Inspector to change to
public Texture m_Texture;
void Start()
{
//Fetch the RawImage component from the GameObject
m_RawImage = GetComponent<RawImage>();
//Change the Texture to be the one you define in the Inspector
m_RawImage.texture = m_Texture;
}
}
uvRect
UV rectangle used by the texture.
Declaration
public Rect uvRect { get; set; }
Property Value
Type | Description |
---|---|
Rect |
Methods
OnDidApplyAnimationProperties()
Declaration
protected override void OnDidApplyAnimationProperties()
Overrides
OnPopulateMesh(VertexHelper)
Callback function when a UI element needs to generate vertices. Fills the vertex buffer data.
Declaration
protected override void OnPopulateMesh(VertexHelper vh)
Parameters
Type | Name | Description |
---|---|---|
VertexHelper | vh | VertexHelper utility. |
Overrides
Remarks
Used by Text, UI.Image, and RawImage for example to generate vertices specific to their use case.
SetNativeSize()
Adjust the scale of the Graphic to make it pixel-perfect.
Declaration
public override void SetNativeSize()
Overrides
Remarks
This means setting the RawImage's RectTransform.sizeDelta to be equal to the Texture dimensions.