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. [tyvj-1071]LCIS 动态规划

    LCIS模板 #include <cstdio> #include <cstring> #include <iostream> using namespace st ...

  2. 基于 SpringMVC——web.xml基本配置

    <!--声明应用范围内的初始化参数--> <context-param> <param-name>contextConfigLocation</param-n ...

  3. maven项目发布后访问jsp页面报错

    type Exception report message java.lang.NullPointerException description The server encountered an i ...

  4. 小程序中 wx.navigateTo 页面跳转没有反应?

    页面js文件中加入 show: function () {wx.navigateTo({url: ‘/pages/show/show’})} 这个函数 目的在于要做跳转到新的页面,但是你可能会遇到一个 ...

  5. BA-楼宇自控系统设计论文(转载)潘翌庆 元晨

    楼宇自控系统设计 潘翌庆 元晨 一.概述 楼宇自控系统(Building Automation System-BAS)是智能建筑中不可缺少的重要组成部分,在智能建筑中占有举足轻重的地位.它对建筑物内部 ...

  6. C#创建PDF文档

    说明:本实例用到了第三方组件ICSharpCode.SharpZipLib.dll.itextsharp.dll,该组件可到网上下载. 代码: using System; using System.C ...

  7. MySQL List分区(三)

    具体介绍请看   MySQL分区一 样例:该样例为本人个人学习总结分享

  8. 【BZOJ 2821】作诗

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2821 [算法] 如果不强制在线,显然莫队是可以解决此题的,那么,强制在线怎么办呢? ...

  9. jquery 登录,删除提示信息框

    <a onclick="return confirm('确认要退出登录吗?')">退出</a> //删除,修改,添加时提示信息框 (del,edit,add ...

  10. .NET MVC Dropzone 上传图片

    在nuget控制台输入:Install-Package dropzone @{ Layout = null; } <!DOCTYPE html> <html> <head ...