XRIcon.cs 809 B

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