Unity 切割图集并获取图集
程序员文章站
2022-03-26 15:55:07
...
原文地址,多些大佬:unity切割图集并且读取图集
public class SpriteManager : MonoBehaviour
{
private static GameObject spriteManager;
private static SpriteManager instance = null;
public static SpriteManager getInstance()
{
if(instance == null)
{
instance = spriteManager.GetComponent<SpriteManager>();
}
return instance;
}
private static Dictionary<string, UnityEngine.Object[]> mAtlasDic;//图集的集合
void Awake()
{
SpriteManager.spriteManager = gameObject;
init();
}
public void init()
{
mAtlasDic = new Dictionary<string, UnityEngine.Object[]>();
}
public Sprite LoadAtlasSprite(string path, string _spriteName)
{
Sprite _sprite = FindSpriteFormBuffer(path, _spriteName);
if(_sprite == null)
{
UnityEngine.Object[] _atlas = Resources.LoadAll(path);
mAtlasDic.Add(path, _atlas);
_sprite = SpriteFormAtlas(_atlas, _spriteName);
}
return _sprite;
}
public void DeleteAtlas(string path)
{
if (mAtlasDic.ContainsKey(path))
{
mAtlasDic.Remove(path);
}
}
private Sprite FindSpriteFormBuffer(string path, string _spriteName)
{
if (mAtlasDic.ContainsKey(path))
{
UnityEngine.Object[] _atlas = mAtlasDic[path];
Sprite _sprite = SpriteFormAtlas(_atlas, _spriteName);
return _sprite;
}
return null;
}
private Sprite SpriteFormAtlas(UnityEngine.Object[] _atlas, string _spriteName)
{
for (int i = 0; i < _atlas.Length; i++)
{
if (_atlas[i].GetType() == typeof(UnityEngine.Sprite))
{
if (_atlas[i].name == _spriteName)
{
return (Sprite)_atlas[i];
}
}
}
return null;
}
}
推荐阅读
-
Python通过OpenCV的findContours获取轮廓并切割实例
-
Unity 3D UGUI游戏界面 图集Atlas
-
Unity 使用TexturePacker打包图集的操作方法
-
unity里获取text中文字宽度并截断省略的操作
-
Unity Android 之 获取 Wifi 的状态,设置 Wifi 的开关状态,并监听 Wifi 的状态变化方法整理
-
php获取页面并切割页面div内容
-
Python通过OpenCV的findContours获取轮廓并切割实例
-
Unity Android 之 获取各个音量的最大值、最小值、以及当前音量值,并设置音量值,监听音量变化的方法整理
-
Unity Android 之 获取蓝牙Bluetooth 的状态,设置的蓝牙Bluetooth 的开关状态,并监听蓝牙Bluetooth 的状态变化方法整理
-
php获取页面并切割页面div内容