RawImage是Unity UGUI中的一個元件,用於顯示原始圖片。與Image元件不同,RawImage可以直接顯示原始圖片的畫素資料,而不需要經過額外的處理。
RawImage元件通過將原始圖片的畫素資料直接傳遞給顯示卡進行渲染,從而實現顯示原始圖片的功能。它可以顯示各種格式的圖片,包括常見的PNG、JPG等格式。
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
public RawImage rawImage;
public Texture texture;
void Start()
{
rawImage.texture = texture;
}
}
操作步驟:
注意事項:
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
public RawImage rawImage;
public Texture texture;
public Color color;
void Start()
{
rawImage.texture = texture;
rawImage.color = color;
}
}
操作步驟:
注意事項:
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
public RawImage rawImage;
public Texture texture;
void Start()
{
rawImage.texture = texture;
rawImage.SetNativeSize();
}
}
操作步驟:
注意事項:
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
public RawImage rawImage;
public Texture texture1;
public Texture texture2;
void Start()
{
rawImage.texture = texture1;
}
public void ChangeTexture()
{
rawImage.texture = texture2;
}
}
操作步驟:
注意事項:
using UnityEngine;
using UnityEngine.UI;
public class Example : MonoBehaviour
{
public RawImage rawImage;
public Texture texture;
public Material material;
void Start()
{
rawImage.texture = texture;
rawImage.material = material;
}
}
操作步驟:
注意事項: