public static void ChargeTextures(PictureExportInfo pictureInfo, GroupNode1 groupnode) { //重新加载 var atlaspath = pictureInfo.exportPath + "/" + pictureInfo.atlasName; Sprite[] fileSprites = AssetDatabase.LoadAllAssetsAtPath(atlaspath).OfType <Sprite>().ToArray(); Texture2D[] fileTextures = LoadAllObjectFromDir <Texture2D>(pictureInfo.exportPath); // AssetDatabase.LoadAllAssetsAtPath(pictureInfo.exportPath).OfType<Texture2D>().ToArray(); Sprite[] fileSingleSprites = LoadAllObjectFromDir <Sprite>(pictureInfo.exportPath); // AssetDatabase.LoadAllAssetsAtPath(pictureInfo.exportPath).OfType<Sprite>().ToArray(); var pictureData = new List <ImgNode>(); groupnode.GetImgNodes(pictureData); foreach (var item in pictureData) { switch (item.type) { case ImgType.Image: item.sprite = Array.Find(fileSingleSprites, x => x.name == item.TextureName); break; case ImgType.AtlasImage: item.sprite = Array.Find(fileSprites, x => x.name == item.TextureName); break; case ImgType.Texture: item.texture = Array.Find(fileTextures, x => x.name == item.TextureName); break; default: break; } } }
public static GroupNode1[] CreatePictures(IPsdLayer[] rootLayers, Vector2 rootSize, Vector2 uiSize, bool forceSprite = false) { maxSize = uiSize; List <GroupNode1> nodes = new List <GroupNode1>(); foreach (PsdLayer rootLayer in rootLayers) { if (rootLayer.IsGroup) { var groupnode = new GroupNode1(GetRectFromLayer(rootLayer)).Analyzing(PsdExportUtility.rouleObj, rootLayer.Name) as GroupNode1;// (rootLayer,rootLayer)); RetriveLayerToSwitchModle(rootSize, rootLayer, groupnode, forceSprite); nodes.Add(groupnode); } } var pictureData = new List <ImgNode>(); foreach (var groupnode in nodes) { groupnode.GetImgNodes(pictureData); } //创建atlas var textures = pictureData.FindAll(x => x.type == ImgType.AtlasImage).ConvertAll <Texture2D>(x => x.texture); SaveToAtlas(textures.ToArray(), pictureInfo); //创建Sprites var pictures = pictureData.FindAll(x => x.type == ImgType.Image).ConvertAll <Texture2D>(x => x.texture); SaveToTextures(ImgType.Image, pictures.ToArray(), pictureInfo); //创建Sprites pictures = pictureData.FindAll(x => x.type == ImgType.Texture).ConvertAll <Texture2D>(x => x.texture); SaveToTextures(ImgType.Texture, pictures.ToArray(), pictureInfo); return(nodes.ToArray()); }