GetTexture2D.cs 858 B

123456789101112131415161718192021222324252627282930313233
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.Networking;
  5. using UnityEngine.UI;
  6. public class GetTexture2D : MonoBehaviour
  7. {
  8. public static string urlbase = "DeMa";
  9. public string m_url = "";
  10. void Start()
  11. {
  12. string filePath = System.IO.Path.Combine(Application.streamingAssetsPath+"/"+ urlbase, m_url);
  13. SetWebGLText.Instance.GetTexture(filePath+".png", (Texture2D t2d)=> {
  14. try
  15. {
  16. if (GetComponent<RawImage>())
  17. GetComponent<RawImage>().texture = t2d;
  18. }
  19. catch
  20. {
  21. }
  22. });
  23. }
  24. private void OnDestroy() {
  25. if (GetComponent<RawImage>())
  26. GetComponent<RawImage>().texture = null;
  27. }
  28. }