Esempio n. 1
0
        //-------∽-★-∽------∽-★-∽--------∽-★-∽资源相关∽-★-∽--------∽-★-∽------∽-★-∽--------//

        /// <summary>
        /// 获取assets下的图片sprite
        /// </summary>
        /// <param name="link"></param>
        /// <returns></returns>
        public static Sprite GetSprite(string link)
        {
            string atlasName = LinkTextureData.GetAtlasName(link);

            atlasName = AtlasBatchSetting.GetBatchedAtlasName(atlasName);   //获取打包的图集
            string spriteName = LinkTextureData.GetTextureName(link);
            string path       = GetAtlasPath(atlasName);

            if (_cachedSpritesDict.ContainsKey(path) == false)
            {
                _cachedSpritesDict.Add(path, AssetDatabase.LoadAllAssetsAtPath(path));
            }

            Object[] sprites = _cachedSpritesDict[path];
            if (sprites.Length == 0)
            {
                throw new Exception("未找到图集: " + path);
            }

            foreach (Object obj in sprites)
            {
                if (obj.name == spriteName)
                {
                    return(obj as Sprite);
                }
            }
            throw new Exception("未找到Sprite: " + path + " " + spriteName);
        }
        public static Vector4 GetAtlasSpritePadding(string link)
        {
            string atlasName  = LinkTextureData.GetAtlasName(link);
            string spriteName = LinkTextureData.GetTextureName(link);

            return(GetAtlasSpritePadding(atlasName, spriteName));
        }
Esempio n. 3
0
 static Vector4[] GetSpritePaddings()
 {
     Vector4[] result = new Vector4[_uniqueTextureDataList.Count];
     for (int i = 0; i < _uniqueTextureDataList.Count; i++)
     {
         LinkTextureData textureData = _uniqueTextureDataList[i];
         result[i] = textureData.spritePadding;
     }
     return(result);
 }
Esempio n. 4
0
 static Vector4[] GetSpriteBorders()
 {
     Vector4[] result = new Vector4[_uniqueTextureDataList.Count];
     for (int i = 0; i < _uniqueTextureDataList.Count; i++)
     {
         LinkTextureData textureData = _uniqueTextureDataList[i];
         result[i] = new Vector4(textureData.left, textureData.bottom, textureData.right, textureData.top);
     }
     return(result);
 }
Esempio n. 5
0
        //图片是否在公共图集
        static bool IsShared(string link)
        {
            if (_atlasName == SHARED || _atlasName == SHARED1)
            {
                return(false);
            }
            string atlasName = LinkTextureData.GetAtlasName(link);

            return(atlasName == SHARED || atlasName == SHARED1);
        }
Esempio n. 6
0
        static void ProcessImageData(JsonData data)
        {
            foreach (string key in data.Keys)
            {
                if (data[key].IsObject == false)
                {
                    continue;
                }

                JsonData stateData = data[key];
                if (stateData.Keys.Contains("link") == true)
                {
                    string link = (string)stateData["link"];    //图片名称 "Shard.xxx"

                    if (IsLanguageExclude(link) == true)
                    {
                        continue;
                    }

                    if (IsShared(link) == true)
                    {
                        //在公共图集不打包
                        continue;
                    }

                    string name = LinkTextureData.GetTextureName(link);
                    if (_linkSet.Contains(name) == true)    //为何用name不用link来记录? ->atlas里的名称用的是name,如果用link可能会导致同一张图重复了
                    //每个图片只需要有一个TextureData
                    {
                        continue;
                    }
                    _linkSet.Add(name);

                    LinkTextureData textureData = new LinkTextureData();
                    textureData.link   = link;
                    textureData.name   = name;// TextureData.GetTextureName(link);
                    textureData.width  = (int)stateData["width"];
                    textureData.height = (int)stateData["height"];

                    //九宫格
                    if (stateData.Keys.Contains("top"))
                    {
                        textureData.top = (int)stateData["top"];
                    }
                    if (stateData.Keys.Contains("right"))
                    {
                        textureData.right = (int)stateData["right"];
                    }
                    if (stateData.Keys.Contains("bottom"))
                    {
                        textureData.bottom = (int)stateData["bottom"];
                    }
                    if (stateData.Keys.Contains("left"))
                    {
                        textureData.left = (int)stateData["left"];
                    }

                    //填充模式
                    if (stateData.Keys.Contains("param"))
                    {
                        textureData.fillParam = (string)stateData["param"];
                    }

                    _uniqueTextureDataList.Add(textureData);
                }
            }
        }