DownloadTexture.cs 723 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. using System;
  2. using System.Collections;
  3. using UnityEngine;
  4. [RequireComponent(typeof(UITexture))]
  5. public class DownloadTexture : MonoBehaviour
  6. {
  7. private IEnumerator Start()
  8. {
  9. WWW www = new WWW(this.url);
  10. yield return www;
  11. this.mTex = www.texture;
  12. if (this.mTex != null)
  13. {
  14. UITexture component = base.GetComponent<UITexture>();
  15. component.mainTexture = this.mTex;
  16. if (this.pixelPerfect)
  17. {
  18. component.MakePixelPerfect();
  19. }
  20. }
  21. www.Dispose();
  22. yield break;
  23. }
  24. private void OnDestroy()
  25. {
  26. if (this.mTex != null)
  27. {
  28. UnityEngine.Object.Destroy(this.mTex);
  29. }
  30. }
  31. public string url = "http://www.yourwebsite.com/logo.png";
  32. public bool pixelPerfect = true;
  33. private Texture2D mTex;
  34. }