GetTexture2D.cs 522 B

12345678910111213141516171819202122
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using UnityEngine.UI;
  6. [ExecuteInEditMode]
  7. public class GetTexture2D : MonoBehaviour
  8. {
  9. public string m_url = "";
  10. // Start is called before the first frame update
  11. void Start()
  12. {
  13. // 启动协程进行图片下载
  14. SetWebGLText.Instance.GetTexture(m_url, (Texture2D t2d)=> {
  15. // 将纹理设置到RawImage组件中显示
  16. GetComponent<RawImage>().texture = t2d;
  17. });
  18. }
  19. }