RendererImage.cs 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. using XRTool.Util;
  6. namespace XRTool.WorldUI
  7. {
  8. public class RendererImage : MonoBehaviour
  9. {
  10. private Renderer meshRender;
  11. public Texture2D img;
  12. public string texName = "_MainTex";
  13. public Renderer MeshRender
  14. {
  15. get
  16. {
  17. if (!meshRender)
  18. {
  19. meshRender = GetComponent<Renderer>();
  20. }
  21. return meshRender;
  22. }
  23. }
  24. private void Start()
  25. {
  26. if (MeshRender && img)
  27. {
  28. try
  29. {
  30. UnityUtil.ChangeMateTexture2D(MeshRender, img, texName);
  31. }
  32. catch (Exception ex)
  33. {
  34. UnityLog.Instance.LogError(MeshRender.material + " have no mainTexture");
  35. }
  36. }
  37. }
  38. /// <summary>
  39. /// 设置图片
  40. /// </summary>
  41. /// <param name="img"></param>
  42. public void SetImage(Texture2D img)
  43. {
  44. this.img = img;
  45. }
  46. }
  47. }