1.图文混排中的资源,主要是图片。

2.所谓的资源管理,可以分为资源对象池和资源加载这两部分。这里是为图文混排单独做一套资源管理,当然也可以改为调用项目中的资源管理。

RichTextResourceManager.cs

 using UnityEngine;
using System.Collections.Generic;
using UnityEngine.UI;
using System;
#if UNITY_EDITOR
using UnityEditor;
#endif public enum RichTextResourceType
{
Image,
} public class RichTextResourceManager : CSharpSingletion<RichTextResourceManager> { private Dictionary<RichTextResourceType, List<GameObject>> typeGoDic = new Dictionary<RichTextResourceType, List<GameObject>>();
private DefaultControls.Resources resources = new DefaultControls.Resources(); public void SetPoolObject(RichTextResourceType type, GameObject go)
{
if (!typeGoDic.ContainsKey(type))
{
List<GameObject> goList = new List<GameObject>();
goList.Add(go);
typeGoDic.Add(type, goList);
}
else
{
typeGoDic[type].Add(go);
}
go.SetActive(false);
} public GameObject GetPoolObject(RichTextResourceType type)
{
GameObject go = null;
if (typeGoDic.ContainsKey(type))
{
if (typeGoDic[type].Count > )
{
go = typeGoDic[type][];
if (go)
{
go.SetActive(true);
typeGoDic[type].Remove(go);
return go;
}
}
}
go = CreatePoolObject(type);
return go;
} private GameObject CreatePoolObject(RichTextResourceType type)
{
GameObject go = null;
if (type == RichTextResourceType.Image)
{
go = CreateImage();
}
return go;
} public void LoadSprite(string path, Action<Sprite> callback)
{
#if UNITY_EDITOR
Sprite sprite = AssetDatabase.LoadAssetAtPath<Sprite>("Assets/" + path + ".png");
if ((sprite != null) && (callback != null))
{
callback(sprite);
}
#endif
} public void LoadSprite(string path, Action<Sprite[]> callback)
{
#if UNITY_EDITOR
Sprite[] sprites = AssetDatabase.LoadAllAssetsAtPath("Assets/" + path + ".png") as Sprite[];
if ((sprites != null) && (callback != null))
{
callback(sprites);
}
#endif
} public void SetSprite(string path, Image image)
{
LoadSprite(path, (Sprite sprite) => { image.sprite = sprite; });
} private GameObject CreateImage()
{
GameObject go = DefaultControls.CreateImage(resources);
go.layer = LayerMask.NameToLayer("UI");
Image image = go.GetComponent<Image>();
image.raycastTarget = false;
return go;
}
}

最新文章

  1. (转载)JAVA动态编译--字节代码的操纵
  2. 【Python五篇慢慢弹(5)】类的继承案例解析,python相关知识延伸
  3. Linux第01天
  4. 平行四边形TikZ作图
  5. java string类型的初始化
  6. Git 文件比较
  7. CentOS下用pyenv 和 virtualenv 搭建单机多版本python 虚拟开发环境
  8. oracle11g OEM无法连接到数据库实例解决办法
  9. HTML5吧!少年
  10. View事件分发机制
  11. mysql在linux上重启
  12. jquery弹出层拖拽
  13. face recognition[Euclidean-distance-based loss][Center Face]
  14. AHOI(十二省联考)2019 退役记
  15. 关于ionic2打包android时gradle下载不了的解决方法(附:简单优化启动速度彩蛋)
  16. Abp添加菜单
  17. turbine源码分析
  18. JS 判断鼠标滚轮的上下滚动
  19. extern,头文件和ifndif宏
  20. HDU - 6438(贪心+思维)

热门文章

  1. Oracle存储过程和自定义函数笔记
  2. 多层级sql查询
  3. position实现分层和遮罩层功能
  4. 黄聪:wordpress教程
  5. Java第04次实验提纲(面向对象2-继承、多态、抽象类与接口)
  6. Android开发之选项菜单(optinosMenu)
  7. Java学习——加法器
  8. tcpdump命令(转载)
  9. python输出缓冲区的问题
  10. 关于购物车程序的Python实现