You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
73 lines
2.0 KiB
73 lines
2.0 KiB
using System.Collections; |
|
using System.Collections.Generic; |
|
using UnityEngine; |
|
using UnityEngine.U2D; |
|
|
|
public class SpriteManager : Singleton<SpriteManager> |
|
{ |
|
public AssetBundleManager assetBundle = new AssetBundleManager(); |
|
public AssetBundleManager assetBundleTexture = new AssetBundleManager(); |
|
|
|
#if false |
|
public Sprite SpriteGet(string atlas, string sprite) |
|
{ |
|
SpriteAtlas spriteAtlas = assetBundle.GetSpriteAtlas(atlas); |
|
|
|
//Debug.LogWarning($"{atlas}, {sprite}"); |
|
|
|
if (spriteAtlas != null) |
|
return spriteAtlas.GetSprite(sprite); |
|
|
|
return null; |
|
} |
|
public Sprite TextureGet(string sprite) |
|
{ |
|
return assetBundleTexture.GetTexture(sprite); |
|
} |
|
#else |
|
Dictionary<string, SpriteAtlas> dicAtlas = new Dictionary<string, SpriteAtlas>(); |
|
public Sprite SpriteGet(string nameAtlas, string nameSprite) |
|
{ |
|
if (nameSprite == string.Empty) |
|
return null; |
|
|
|
if (dicAtlas.ContainsKey(nameAtlas)) |
|
{ |
|
return dicAtlas[nameAtlas].GetSprite(nameSprite); |
|
} |
|
else |
|
{ |
|
SpriteAtlas spriteAtlas = Resources.Load($"Atlas/{nameAtlas}") as SpriteAtlas; |
|
if (spriteAtlas != null) |
|
{ |
|
dicAtlas.Add(nameAtlas, spriteAtlas); |
|
return spriteAtlas.GetSprite(nameSprite); |
|
} |
|
} |
|
|
|
return null; |
|
} |
|
Dictionary<string, Sprite> dicTexture = new Dictionary<string, Sprite>(); |
|
public Sprite SpriteGet(string nameSprite) |
|
{ |
|
if (nameSprite == string.Empty) |
|
return null; |
|
|
|
if (dicTexture.ContainsKey(nameSprite)) |
|
{ |
|
return dicTexture[nameSprite]; |
|
} |
|
else |
|
{ |
|
Sprite texture = Resources.Load<Sprite>($"Texture/{nameSprite}"); |
|
if (texture != null) |
|
{ |
|
dicTexture.Add(nameSprite, texture); |
|
return texture; |
|
} |
|
} |
|
|
|
return null; |
|
} |
|
#endif |
|
}
|
|
|