赞
踩
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.U2D;
public class SpriteAtlasUtility : MonoBehaviour
{
public static SpriteAtlasUtility Instance;
private Dictionary<string , Sprite> spriteDic;
private Dictionary<string , SpriteAtlas> atlasDic;
private void Awake() {
Instance = this;
spriteDic = new Dictionary<string , Sprite>();
atlasDic = new Dictionary<string , SpriteAtlas>();
}
public Sprite GetAtlasSprite(string atlasName,string spriteName) {
if (spriteDic.TryGetValue(spriteName,out Sprite sprite)) {
return sprite;
}
sprite = GetSpriteAtlas(atlasName)?.GetSprite(spriteName);
spriteDic [spriteName] = sprite;
return sprite;
}
public Sprite GetAtlasSprite(string spriteName) {
if (spriteDic.TryGetValue(spriteName,out Sprite sprite)) {
return sprite;
}
return sprite;
}
private SpriteAtlas GetSpriteAtlas(string atlasName) {
SpriteAtlas atlas;
if (!atlasDic.ContainsKey(atlasName)) {
//TODO:AB或者Resources加载图集
atlas = null;
}
else {
atlas = atlasDic [atlasName];
}
return atlas;
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。