12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.UI;
- [RequireComponent(typeof(Image))]
- public class ImageLoadComponent : MonoBehaviour {
- public string iconName;
- private Image loadImage;
- // Use this for initialization
- void Awake () {
- loadImage = LoadImage();
- }
- private void OnEnable()
- {
- if (loadImage == null || loadImage.sprite == null)
- {
- loadImage = LoadImage();
- }
- }
- public Image LoadImage()
- {
- Image image = GetComponent<Image>();
- if (image)
- {
- if (!string.IsNullOrEmpty(iconName))
- UGUITool.SetImageSprite(image, iconName);
- }
- else
- {
- Debug.LogError(" Dont have Image!!!");
- }
- return image;
- }
- private void OnDestroy()
- {
- if (!string.IsNullOrEmpty(iconName))
- AssetsPoolManager.DestroyByPool(iconName);
- }
- }
|