Exemplo n.º 1
0
        private static Dictionary <string, Material> GetMaterialDict(string[] atlasPaths)
        {
            Dictionary <string, Material> result = new Dictionary <string, Material>();

            foreach (string s in atlasPaths)
            {
                result.Add(s, AssetDatabase.LoadAssetAtPath(AtlasGenerator.GetMaterialPath(s), typeof(Material)) as Material);
            }
            return(result);
        }
Exemplo n.º 2
0
        public static string Process(string prefabPath)
        {
            //获得Prefab依赖的单张图片列表的目录,可能存在多个目录
            string[] textureFolderPaths = GetPrefabDependentTextureFolderPaths(prefabPath);
            //将每一个图片目录做成一个图集
            string[] atlasPaths = AtlasGenerator.Generate(textureFolderPaths);
            //将Prefab复制出来一个副本
            string copyPath = CopyPrefab(prefabPath);

            //将副本Prefab中Image组件上的资源依赖重定向到图集的Sprite
            ReplaceImageSprite(copyPath, atlasPaths);
            return(copyPath);
        }
Exemplo n.º 3
0
        private static void ChangeImageSpriteMaterial(Image image, Dictionary <string, List <Sprite> > spriteListDict, Dictionary <string, Material> materialDict)
        {
            Sprite        sprite     = image.sprite;
            string        path       = AssetDatabase.GetAssetPath(sprite);
            string        folderPath = GetFolderPath(path);
            string        tag        = (AssetImporter.GetAtPath(path) as TextureImporter).spritePackingTag;
            string        atlasPath  = AtlasGenerator.GetAtlasPath(folderPath, tag);
            List <Sprite> spriteList = spriteListDict[atlasPath];

            foreach (Sprite s in spriteList)
            {
                if (s.name == sprite.name)
                {
                    image.sprite   = s;
                    image.material = materialDict[atlasPath];
                    break;
                }
            }
        }