/// <summary> /// 从资源文件中获取声音资源并返回句柄 /// </summary> /// <param name="sourceName">资源名称</param> /// <param name="rtype">资源类型</param> /// <returns>该音频的托管内存流</returns> private MemoryStream GetMusicMemoryStream(string sourceName, ResourceType rtype) { if (sourceName == String.Empty) { return(null); } string DevURI, PackURI; // 处理路径 switch (rtype) { case ResourceType.BGM: DevURI = GlobalConfigContext.DevURI_SO_BGM; PackURI = GlobalConfigContext.PackURI_SO_BGM; break; case ResourceType.BGS: DevURI = GlobalConfigContext.DevURI_SO_BGS; PackURI = GlobalConfigContext.PackURI_SO_BGS; break; case ResourceType.SE: DevURI = GlobalConfigContext.DevURI_SO_SE; PackURI = GlobalConfigContext.PackURI_SO_SE; break; case ResourceType.VOCAL: DevURI = GlobalConfigContext.DevURI_SO_VOCAL; PackURI = GlobalConfigContext.PackURI_SO_VOCAL; break; default: throw new Exception("调用了音乐获取方法,但却不是获取音乐资源"); } // 总是先查看是否有为封包的数据 if (this.resourceTable.ContainsKey(DevURI) && this.resourceTable[DevURI].ContainsKey(sourceName)) { var sourceSlot = this.resourceTable[DevURI][sourceName]; var ptr = PackageUtils.GetObjectBytes(sourceSlot.BindingFile, sourceName, sourceSlot.Position, sourceSlot.Length); return(new MemoryStream(ptr)); } // 没有封包数据再搜索开发目录 else { string furi = IOUtils.JoinPath(GlobalConfigContext.DevURI_RT_SOUND, DevURI, sourceName); if (File.Exists(IOUtils.ParseURItoURL(furi))) { var ptr = File.ReadAllBytes(IOUtils.ParseURItoURL(furi)); return(new MemoryStream(ptr)); } else { MessageBox.Show("[错误] 资源文件不存在:" + sourceName); return(null); } } }
/// <summary> /// 从资源文件中获取图片资源并返回精灵对象 /// </summary> /// <param name="sourceName">资源名称</param> /// <param name="rtype">资源类型</param> /// <param name="cutRect">纹理切割矩</param> /// <returns>该资源的精灵</returns> private YuriSprite GetGraphicSprite(string sourceName, ResourceType rtype, Int32Rect?cutRect) { if (sourceName == String.Empty) { return(null); } YuriSprite sprite = new YuriSprite(); string DevURI, PackURI; // 处理路径 switch (rtype) { case ResourceType.Background: DevURI = GlobalConfigContext.DevURI_PA_BACKGROUND; PackURI = GlobalConfigContext.PackURI_PA_BACKGROUND; break; case ResourceType.Stand: DevURI = GlobalConfigContext.DevURI_PA_CHARASTAND; PackURI = GlobalConfigContext.PackURI_PA_CHARASTAND; break; case ResourceType.Pictures: DevURI = GlobalConfigContext.DevURI_PA_PICTURES; PackURI = GlobalConfigContext.PackURI_PA_PICTURES; break; default: return(null); } // 总是先查看是否有为封包的数据 if (this.resourceTable.ContainsKey(DevURI) && this.resourceTable[DevURI].ContainsKey(sourceName)) { // 检查缓冲 var ob = ResourceCachePool.Refer(rtype.ToString() + "->" + sourceName, ResourceCacheType.Eden); if (ob == null) { var sourceSlot = this.resourceTable[DevURI][sourceName]; ob = PackageUtils.GetObjectBytes(sourceSlot.BindingFile, sourceName, sourceSlot.Position, sourceSlot.Length); ResourceCachePool.Register(rtype.ToString() + "->" + sourceName, ob, ResourceCacheType.Eden); } MemoryStream ms = new MemoryStream(ob); sprite.Init(sourceName, rtype, ms, cutRect); } // 没有封包数据再搜索开发目录 else { // 检查缓冲 byte[] ob = ResourceCachePool.Refer(rtype.ToString() + "->" + sourceName, ResourceCacheType.Eden); if (ob == null) { string furi = IOUtils.JoinPath(GlobalConfigContext.DevURI_RT_PICTUREASSETS, DevURI, sourceName); if (File.Exists(IOUtils.ParseURItoURL(furi))) { Uri bg = new Uri(IOUtils.ParseURItoURL(furi), UriKind.RelativeOrAbsolute); ob = IOUtils.GetObjectBytes(bg); ResourceCachePool.Register(rtype.ToString() + "->" + sourceName, ob, ResourceCacheType.Eden); } else { MessageBox.Show("[错误] 资源文件不存在:" + sourceName); Director.GetInstance().GetMainRender().Shutdown(); return(null); } } MemoryStream ms = new MemoryStream(ob); sprite.Init(sourceName, rtype, ms, cutRect); } return(sprite); }