XRIcon3D.cs 1.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. using DG.Tweening;
  2. using System;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using XRTool.Util;
  6. namespace XRTool.WorldUI
  7. {
  8. public class XRIcon3D : XRImage3D
  9. {
  10. private Renderer icon;
  11. [HideInInspector]
  12. public Texture2D img;
  13. protected override void Start()
  14. {
  15. base.Start();
  16. SetIcon();
  17. }
  18. public Renderer Icon
  19. {
  20. get
  21. {
  22. if (!icon)
  23. {
  24. icon = UnityUtil.GetBreadthChild<Renderer>(transform, "Icon");
  25. }
  26. return icon;
  27. }
  28. }
  29. public void SetIcon()
  30. {
  31. if (Icon && img && Icon.enabled)
  32. {
  33. try
  34. {
  35. UnityUtil.ChangeMateTexture2D(Icon, img);
  36. }
  37. catch (Exception ex)
  38. {
  39. UnityLog.LogError(icon.material + " have no mainTexture");
  40. }
  41. }
  42. }
  43. }
  44. }