XRIcon.cs 869 B

12345678910111213141516171819202122232425262728293031323334353637
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. namespace XRTool.WorldUI
  6. {
  7. public class XRIcon : Image
  8. {
  9. [HideInInspector]
  10. public Texture2D icon;
  11. protected override void Awake()
  12. {
  13. AutoSetSprite();
  14. }
  15. public void AutoSetSprite()
  16. {
  17. if (icon)
  18. {
  19. Rect rect = new Rect(0, 0, icon.width, icon.height);
  20. AutoSetSprite( Sprite.Create(icon, rect, Vector2.zero));
  21. }
  22. else
  23. {
  24. sprite = null;
  25. }
  26. }
  27. public void AutoSetSprite(Texture2D icon)
  28. {
  29. this.icon = icon;
  30. AutoSetSprite();
  31. }
  32. public void AutoSetSprite(Sprite icon)
  33. {
  34. sprite = icon;
  35. }
  36. }
  37. }