public Atlas GetAtlas(Gwen.Renderer.Tao renderer, string filePath) { // 先在缓存里找 Atlas ret; if (m_lut.TryGetValue(filePath, out ret)) { return(ret); } // 加载贴图,如果这个过程失败,那么认为 atlas 加载失败 Gwen.Texture t; t = new Gwen.Texture(renderer); if (t == null) { return(null); } t.Load(filePath + ResProtocol.ResImageFilePostfix); if (t.Failed) { return(null); } // 加载描述文件,如果这个过程失败,仍返回有效的 atlas string descFilePath = filePath + ResProtocol.ResDescFilePostfix; JObject desc = null; if (File.Exists(descFilePath)) { desc = ucore.JsonUtil.ReadTextIntoJObject(filePath + ResProtocol.ResDescFilePostfix); } // 拼装成有效的 atlas ret = new Atlas(); ret.FilePath = filePath; ret.Texture = t; ret.Desc = desc; return(ret); }
public TextureRenderInfo GetTextureRenderInfo(Gwen.Renderer.Tao renderer, string url) { TextureRenderInfo tri; if (m_lut.TryGetValue(url, out tri)) { return(tri); } // 如果是单张贴图,直接处理后返回 if (ResProtocol.IsSingleTexture(url)) { tri = GwenTextureUtil.BuildSingleTexture(renderer, url); m_lut[url] = tri; return(tri); } string atlasName; string tileName; if (!ResProtocol.ParseURL(url, out atlasName, out tileName)) { return(null); } string filePath = ResourceManager.Instance.GetAtlasFilePath(atlasName); Atlas atlas = AtlasManager.Instance.GetAtlas(renderer, filePath); if (atlas == null) { return(null); } ImageResource res = ResourceManager.Instance.GetResource(url); if (res == null) { return(null); } Texture9GridBorderInfo uv9Grid = null; Rectangle border9Grid = atlas.GetTileBorderInfo(tileName); if (border9Grid != ucore.Const.ZERO_RECT) { uv9Grid = new Texture9GridBorderInfo(); uv9Grid.border = border9Grid; uv9Grid.size = res.Size; if (border9Grid.Left != 0 && border9Grid.Right != 0) { uv9Grid.uLeft = ((float)res.Position.X + (float)border9Grid.Left) / (float)atlas.Texture.Width; uv9Grid.uRight = ((float)res.Position.X + (float)border9Grid.Right) / (float)atlas.Texture.Width; } if (border9Grid.Top != 0 && border9Grid.Bottom != 0) { uv9Grid.vTop = ((float)res.Position.Y + (float)border9Grid.Top) / (float)atlas.Texture.Height; uv9Grid.vBottom = ((float)res.Position.Y + (float)border9Grid.Bottom) / (float)atlas.Texture.Height; } } tri = new TextureRenderInfo(); tri.u1 = (float)res.Position.X / (float)atlas.Texture.Width; tri.v1 = (float)res.Position.Y / (float)atlas.Texture.Height; tri.u2 = ((float)res.Position.X + (float)res.Size.Width) / (float)atlas.Texture.Width; tri.v2 = ((float)res.Position.Y + (float)res.Size.Height) / (float)atlas.Texture.Height; tri.texture = atlas.Texture; tri.uv9Grid = uv9Grid; m_lut[url] = tri; return(tri); }