using UnityEngine;
using System.Collections;
using System.Collections.Generic;
//纹理图集加载管理
public class PPTextureManage : MonoBehaviour {
private static GameObject m_pMainObject;
private static PPTextureManage m_pContainer = null;
public static PPTextureManage getInstance(){
if(m_pContainer == null){
m_pContainer = m_pMainObject.GetComponent<PPTextureManage> ();
}
return m_pContainer;
}
private Dictionary<string, Object[]> m_pAtlasDic;//图集的集合
void Awake(){
initData ();
}
private void initData(){
PPTextureManage.m_pMainObject = gameObject;
m_pAtlasDic = new Dictionary<string, Object[]> ();
}
// Use this for initialization
void Start () {
}
//加载图集上的一个精灵
public Sprite LoadAtlasSprite(string _spriteAtlasPath,string _spriteName){
Sprite _sprite = FindSpriteFormBuffer (_spriteAtlasPath,_spriteName);
if (_sprite == null) {
Object[] _atlas = Resources.LoadAll (_spriteAtlasPath);
m_pAtlasDic.Add (_spriteAtlasPath,_atlas);
_sprite = SpriteFormAtlas (_atlas,_spriteName);
}
return _sprite;
}
//删除图集缓存
public void DeleteAtlas(string _spriteAtlasPath){
if (m_pAtlasDic.ContainsKey (_spriteAtlasPath)) {
m_pAtlasDic.Remove (_spriteAtlasPath);
}
}
//从缓存中查找图集,并找出sprite
private Sprite FindSpriteFormBuffer(string _spriteAtlasPath,string _spriteName){
if (m_pAtlasDic.ContainsKey (_spriteAtlasPath)) {
Object[] _atlas = m_pAtlasDic[_spriteAtlasPath];
Sprite _sprite = SpriteFormAtlas(_atlas,_spriteName);
return _sprite;
}
return null;
}
//从图集中,并找出sprite
private Sprite SpriteFormAtlas(Object[] _atlas,string _spriteName){
for (int i = ; i < _atlas.Length; i++) {
if (_atlas [i].GetType () == typeof(UnityEngine.Sprite)) {
if(_atlas [i].name == _spriteName){
return (Sprite)_atlas [i];
}
}
}
Debug.LogWarning ("图片名:"+_spriteName+";在图集中找不到");
return null;
}
}

UGUI图集管理的更多相关文章

  1. Unity中2D和UGUI图集的理解与使用

    图集 什么是图集? 在使用3D技术开发2D游戏或制作UI时(即使用GPU绘制),都会使用到图集,而使用CPU渲染的2D游戏和UI则不存在图集这个概念(比如Flash的原生显示列表),那么什么是图集呢? ...

  2. [Unity UGUI图集系统]浅谈UGUI图集使用

    **写在前面,下面是自己做Demo的时候一些记录吧,参考了很多网上分享的资源 一.打图集 1.准备好素材(建议最好是根据图集名称按文件夹分开) 2.创建一个SpriteAtlas 3.将素材添加到图集 ...

  3. UGUI图集

    Editor->Project Settings 下面有sprite packer的模式.Disabled表示不启用它,Enabled For Builds 表示只有打包的时候才会启用它,Alw ...

  4. 开篇&TexturePacker打出图集给UGUI使用

    开篇: 前段时间,网上流出了一套手游源码,本想着把服务器端搭一下,给自己认识小伙伴们调试着把这套源码学习一下.于是就买一个阿里云服务器,可是花了几天时间,就是run不起来了啊.还好网上已经有人搭出来了 ...

  5. 【转】UGUI VS NGUI

    原文:http://gad.qq.com/college/articledetail/7191053 注[1]:该比较是基于15年-16年期间使用NGUI(3.8.0版本)与UGUI(4.6.9版本) ...

  6. [Unity UGUI序列帧]简单实现序列帧的播放

    在使用序列帧之前需要准备好序列帧的图集,打图集的操作参考 [Unity UGUI图集系统]浅谈UGUI图集使用 准备好序列帧图集,序列帧的播放原理就是获取到图集中的所有图片,然后按照设置的速度按个赋值 ...

  7. 【Unity游戏开发】SpriteAtlas与AssetBundle最佳食用方案

    一.简介 在Unity步入2019.4以后,新版的SpriteAtlas日趋完善,已经完全可以在商业项目中使用了.但是纵观网络平台上,许多关于SpriteAtlas的文章还停留在2018的初版时期,其 ...

  8. 【转】发布一个基于NGUI编写的UI框架

    发布一个基于NGUI编写的UI框架 1.加载,显示,隐藏,关闭页面,根据标示获得相应界面实例 2.提供界面显示隐藏动画接口 3.单独界面层级,Collider,背景管理 4.根据存储的导航信息完成界面 ...

  9. 《Unity3D/2D游戏开发从0到1(第二版本)》 书稿完结总结

    前几天,个人著作<Unity3D/2D游戏开发从0到1(第二版)>经过七八个月的技术准备以及近3个月的日夜编写,在十一长假后终于完稿.今天抽出一点时间来,给广大热心小伙伴们汇报一下书籍概况 ...

随机推荐

  1. EhCache缓存页面、局部页面和对象缓存

    页面缓存:SimplePageCachingFilter web.xml <!-- 页面缓存配置,配合ehcache.xml中name为“SimplePageCachingFilter”(默认值 ...

  2. Python编程:从入门到实践 - matplotlib篇 - Random Walk

    随机漫步 # random_walk.py 随机漫步 from random import choice class RandomWalk(): """一个生成随机漫步数 ...

  3. js中“使用”el表达式

    在说相关内容前,一定要先熟悉jsp运行原理: http://blog.csdn.net/lmsnju/article/details/4813488 http://hi.baidu.com/mingf ...

  4. Redis,Memcache的区别和具体应用场景

    1. Memcached简介 Memcached是以LiveJurnal旗下Danga Interactive公司的Bard Fitzpatric为首开发的高性能分布式内存缓存服务器.其本质上就是一个 ...

  5. ISAM Indexed Sequential Access Method 索引顺序存取方法

    ISAM Indexed Sequential Access Method 索引顺序存取方法 学习了:https://baike.baidu.com/item/ISAM/3013855 是IBM发展起 ...

  6. ios基础-分辨率适配

    (一)分辨率定义 分辨率,是指单位长度内包括的像素点的数量,它的单位通常为像素/英寸(ppi).描写叙述分辨率的单位有:(dpi点每英寸).lpi(线每英寸)和ppi(像素每英寸). (二)ios分辨 ...

  7. CSDN高校俱乐部第二届战神杯第二题题解

    两个人玩一个数字游戏,给定两个正整数A,B,两个人轮流从一个数中减去另外一个数的正数倍.要保证结果非负, 首先得到0的人获胜. 比如:30 8经过一步操作能够变为22 8 或者14 8 或者 6 8. ...

  8. 【iOS开发-68】APP下载案例:利用tableView自带的cell布局+缓存池cell复用时注意button状态的检查

    (1)效果 (2)源码与资源下载 http://pan.baidu.com/s/1pJLo2PP (3)总结 --核心是利用UITableView里面自带的cell来制作样式同样的cell. 与之对应 ...

  9. 运行shell命令

    首先将shell命令命名为.sh文件 将上面的代码保存为test.sh.并 cd 到对应文件夹: chmod +x ./test.sh #使脚本具有运行权限 ./test.sh #运行脚本 假设报错/ ...

  10. Python笔记(八)

    #-*-coding:utf-8-*- # Python内置函数 print abs(-45) # 绝对值函数 print divmod(7,2) # 返回一个包含商和余数的元组 # input(&q ...