Exemplo n.º 1
0
        /// <summary>
        /// 获取存档屏幕截图的精灵
        /// </summary>
        /// <param name="sourceName">文件路径</param>
        /// <returns>精灵实例</returns>
        public YuriSprite GetSaveSnapshot(string sourceName)
        {
            YuriSprite sprite = new YuriSprite();

            if (File.Exists(IOUtils.ParseURItoURL(sourceName)))
            {
                Uri bg = new Uri(IOUtils.ParseURItoURL(sourceName), UriKind.RelativeOrAbsolute);
                sprite.Init(sourceName, ResourceType.SaveSnapshot, bg);
            }
            else
            {
                MessageBox.Show("[错误] 资源文件不存在:" + sourceName);
                Director.GetInstance().GetMainRender().Shutdown();
            }
            return(sprite);
        }
Exemplo n.º 2
0
        /// <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);
        }