1234567891011121314151617181920212223242526272829303132333435 |
- using UnityEngine;
- using UnityEngine.UI;
- namespace XRTool.WorldUI
- {
- public class XRIcon : Image
- {
- [HideInInspector]
- public Texture2D icon;
- protected override void Awake()
- {
- AutoSetSprite();
- }
- public void AutoSetSprite()
- {
- if (icon)
- {
- Rect rect = new Rect(0, 0, icon.width, icon.height);
- AutoSetSprite( Sprite.Create(icon, rect, Vector2.zero));
- }
- else
- {
- sprite = null;
- }
- }
- public void AutoSetSprite(Texture2D icon)
- {
- this.icon = icon;
- AutoSetSprite();
- }
- public void AutoSetSprite(Sprite icon)
- {
- sprite = icon;
- }
- }
- }
|