ResourceManager(一)—— ArchiveManager
来源:互联网 发布:冰锐和锐澳的区别 知乎 编辑:程序博客网 时间:2024/05/21 23:31
ResourceManager这部分要联系前面的BuildAsset三篇一起看才行
文件目录:Assets/Scripts/ResourceManager/
Archive.cs
using System;using System.Collections;using System.Collections.Generic;using UnityEngine;public class Archive{ private Dictionary<string, string> mAllFiles; //name-type //构造函数 public Archive() { mAllFiles = new Dictionary<string, string> (); } public Dictionary<string, string> AllFiles { get { return mAllFiles; } } public void Add(string fileName, string type) { mAllFiles.Add (fileName, type); } public string getPath(string fileName) { if (mAllFiles.ContainsKey(fileName)) { return fileName + "." + mAllFiles [fileName]; } else { Debug.LogError ("can not find" + fileName, ResourceCommon.DEBUGTYPENAME); } return null; }}
ArchiveManager.cs
using System;using System.IO;using System.Xml;using System.Collections;using System.Collections.Generic;using UnityEngine;//继承单例//这个类主要就是读取Resource.bytes这个文件,//然后把信息保存起来public class ArchiveManager: Singleton<ArchiveManager>{ //所有Archive,每一个Archive里面又可以包含多个文件 internal Dictionary<string, Archive> mAllArchives; //构造函数 public ArchiveManager() { mAllArchives = new Dictionary<string, Archive> (); } //初始化 public void Init() { //读取Resource.bytes StreamReader sr = ResourcesManager.OpenText ("Resource"); XmlDocument doc = new XmlDocument (); doc.LoadXml (sr.ReadToEnd ()); XmlElement root = doc.DocumentElement; IEnumerator iter = root.GetEnumerator (); //遍历Resource信息 while (iter.MoveNext()) { XmlElement child_root = iter.Current as XmlElement; IEnumerator child_iter = child_root.GetEnumerator (); //没包含就加进去 if (!mAllArchives.ContainsKey (child_root.Name)) { Archive arh = new Archive (); mAllArchives.Add (child_root.Name, arh); } while (child_iter.MoveNext()) { XmlElement file = child_iter.Current as XmlElement; string name = file.GetAttribute ("name"); string type = file.GetAttribute ("type"); mAllArchives [child_root.Name].Add (name, type); } } sr.Close (); } public string GetPath(string archiveName, string fileName) { if (mAllArchives.ContainsKey(archiveName)) { return mAllArchives [archiveName].getPath (fileName); } else { Debug.LogError ("can not find" + archiveName, ResourceCommon.DEBUGTYPENAME); } return null; }}
阅读全文
0 0
- ResourceManager(一)—— ArchiveManager
- ResourceManager(二)—— AssetInfoManager
- ResourceManager(三)—— Request,ResourceAsyncOperation
- ResourceManager(四)—— ResourceUnit
- ResourceManager(五)—— ResourceCommon
- ResourceManager(六)—— ResourcesManager
- Yarn之ResourceManager详细分析笔记(一)待续
- Yarn之ResourceManager详细分析笔记(一)
- ResourceManager(七)—— 打包AssetBundle然后从AssetBundle加载资源
- ResourceManager(八)—— 在安卓机子上实现加载AssetBundle
- ResourceManager
- ResourceManager
- Unity3D 大型游戏 最后一站 源码 部分重点ResourceManager(2)
- Unity3D 大型游戏 最后一站 源码 部分重点ResourceManager(2)
- Unity3D 大型游戏 最后一站 源码 部分重点ResourceManager(2)
- 【Hadoop】Hadoop官方文档翻译—— YARN ResourceManager High Availability 2.7.3
- Hadoop官方文档翻译—— YARN ResourceManager High Availability 2.7.3
- FLEX实践—在MXML与AS中分别引用resourceManager
- 总是这么奇怪
- 科普LLVM中MSP430如何lower移位指令
- ORM与JPA及Hibernate三者之间的关系
- 数据结构 队列的实现
- 验证子串
- ResourceManager(一)—— ArchiveManager
- 万商联店铺会员管理系统v3.8破解带收银系统
- LinuxStudyNote(42)-RPM包安装、更新、卸载命令、包名和包全名的概念
- [线性规划 费用流]Codeforces Gym101190D.Delight for a cat
- Java I/O Reader及其子类源码解析
- VS2013如何添加LIb库及头文件的步骤
- python开发环境的搭建
- SpringMVC 报org.springframework.beans.factory.NoSuchBeanDefinitionException
- Codeforces438D 线段树取模