SHARE
TWEET

Untitled

a guest Oct 22nd, 2019 67 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using UnityEngine.U2D;
  3. using UnityEngine.UI;
  4.  
  5. public class SpriteAtlasHelper : MonoBehaviour
  6. {
  7.  
  8. #pragma warning disable CS0649
  9.     [SerializeField]
  10.     private SpriteAtlas _spriteAtlas;
  11. #pragma warning restore CS0649
  12.  
  13.     private SpriteRenderer _spriteRenderer;
  14.  
  15.     private Image _image;
  16.  
  17.     private void Awake()
  18.     {
  19.  
  20.         _spriteRenderer = gameObject.GetComponent<SpriteRenderer>();
  21.  
  22.         _image = gameObject.GetComponent<Image>();
  23.  
  24.     }
  25.  
  26.     private void OnEnable()
  27.     {
  28.  
  29.         if (_spriteRenderer && _spriteRenderer.sprite)
  30.         {
  31.  
  32.             _spriteRenderer.sprite = _spriteAtlas.GetSprite(_spriteRenderer.sprite.name) ?? _spriteRenderer.sprite;
  33.  
  34.         }
  35.  
  36.         if (_image && _image.sprite)
  37.         {
  38.  
  39.             _image.sprite = _spriteAtlas.GetSprite(_image.sprite.name) ?? _image.sprite;
  40.  
  41.         }
  42.  
  43.     }
  44.  
  45. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top