UGUI图集管理
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图集管理的更多相关文章
- Unity中2D和UGUI图集的理解与使用
图集 什么是图集? 在使用3D技术开发2D游戏或制作UI时(即使用GPU绘制),都会使用到图集,而使用CPU渲染的2D游戏和UI则不存在图集这个概念(比如Flash的原生显示列表),那么什么是图集呢? ...
- [Unity UGUI图集系统]浅谈UGUI图集使用
**写在前面,下面是自己做Demo的时候一些记录吧,参考了很多网上分享的资源 一.打图集 1.准备好素材(建议最好是根据图集名称按文件夹分开) 2.创建一个SpriteAtlas 3.将素材添加到图集 ...
- UGUI图集
Editor->Project Settings 下面有sprite packer的模式.Disabled表示不启用它,Enabled For Builds 表示只有打包的时候才会启用它,Alw ...
- 开篇&TexturePacker打出图集给UGUI使用
开篇: 前段时间,网上流出了一套手游源码,本想着把服务器端搭一下,给自己认识小伙伴们调试着把这套源码学习一下.于是就买一个阿里云服务器,可是花了几天时间,就是run不起来了啊.还好网上已经有人搭出来了 ...
- 【转】UGUI VS NGUI
原文:http://gad.qq.com/college/articledetail/7191053 注[1]:该比较是基于15年-16年期间使用NGUI(3.8.0版本)与UGUI(4.6.9版本) ...
- [Unity UGUI序列帧]简单实现序列帧的播放
在使用序列帧之前需要准备好序列帧的图集,打图集的操作参考 [Unity UGUI图集系统]浅谈UGUI图集使用 准备好序列帧图集,序列帧的播放原理就是获取到图集中的所有图片,然后按照设置的速度按个赋值 ...
- 【Unity游戏开发】SpriteAtlas与AssetBundle最佳食用方案
一.简介 在Unity步入2019.4以后,新版的SpriteAtlas日趋完善,已经完全可以在商业项目中使用了.但是纵观网络平台上,许多关于SpriteAtlas的文章还停留在2018的初版时期,其 ...
- 【转】发布一个基于NGUI编写的UI框架
发布一个基于NGUI编写的UI框架 1.加载,显示,隐藏,关闭页面,根据标示获得相应界面实例 2.提供界面显示隐藏动画接口 3.单独界面层级,Collider,背景管理 4.根据存储的导航信息完成界面 ...
- 《Unity3D/2D游戏开发从0到1(第二版本)》 书稿完结总结
前几天,个人著作<Unity3D/2D游戏开发从0到1(第二版)>经过七八个月的技术准备以及近3个月的日夜编写,在十一长假后终于完稿.今天抽出一点时间来,给广大热心小伙伴们汇报一下书籍概况 ...
随机推荐
- 转载:Java编程风格与命名规范整理
转载自:传送门 不想复制,点进去看喽23333333
- 【LeetCode-面试算法经典-Java实现】【056-Merge Intervals(区间合并)】
[056-Merge Intervals(区间合并)] [LeetCode-面试算法经典-Java实现][全部题目文件夹索引] 原题 Given a collection of intervals, ...
- This Activity already has an action bar supplied by the window decor
问题描写叙述:继承自AppCompatActivity,使用Toolbar替代ActionBar的时候.出现错误 错误信息: 2.Caused by: java.lang.IllegalStateEx ...
- Codeforces Round #FF (Div. 2):B. DZY Loves Strings
B. DZY Loves Strings time limit per test 1 second memory limit per test 256 megabytes input standard ...
- POJ 2796 / UVA 1619 Feel Good 扫描法
Feel Good Description Bill is developing a new mathematical theory for human emotions. His recent ...
- Ubuntu(64位)编译Android源码常见错误解决办法
2013年07月10日 14:47:27 阅读数:1239 错误: /usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file ...
- bzoj5288: [Hnoi2018]游戏
我还是太年轻了... 考场上就是直接枚举预处理当前位置左右延伸到的最远距离,好像是水了20.. 然后噶爷爷居然随机一下就AC了????mengbier #include<cstdio> # ...
- Python—JSON数据解析
1.安装pip pip是python的包管理工具,使用它能非常方便地安装和卸载各种python工具包 第一步:直接用浏览器访问地址:https://raw.github.com/pypa/pip/ma ...
- ML学习笔记- 神经网络
神经网络 有的模型可以有多种算法.而有的算法可能可用于多种模型.在神经网络中,对外部环境提供的模式样本进行学习训练,并能存储这种模式,则称为感知器;对外部环境有适应能力,能自动提取外部环境变化特征,则 ...
- css3背景渐变以及图片混合渲染模式(二)
http://avnpc.com/pages/photoshop-layer-blending-algorithm http://www.html5cn.org/forum.php?mod=viewt ...