public static void LoadImagesFromResources(string path, ref List <SpriteInfo> newSprites)
 {
     string[] imagesFiles = FileUtils.GetAllFilesEmbeddedAtFolder(path, ".png");
     TextureAtlasUtils.ParseBorderDescriptors(KlyteResourceLoader.LoadResourceStringLines($"{path}.{BORDER_FILENAME}"), out Dictionary <string, Tuple <RectOffset, bool> > borderDescriptor);
     foreach (string file in imagesFiles)
     {
         Texture2D tex = KlyteResourceLoader.LoadTexture($"{path}.{file}");
         if (tex != null)
         {
             newSprites.AddRange(TextureAtlasUtils.CreateSpriteInfo(borderDescriptor, file, tex));
         }
     }
 }
        public static void ParseImageIntoDefaultTextureAtlas(Type enumType, string resourceName, int width, int height, ref List <SpriteInfo> sprites)
        {
            Array     spriteValues = Enum.GetValues(enumType);
            Texture2D image        = KlyteResourceLoader.LoadTexture(resourceName);

            for (int i = 0; i < spriteValues.Length && i * width < image.width; i++)
            {
                var textureQuad = new Texture2D(width, height, TextureFormat.RGBA32, false);
                textureQuad.SetPixels(image.GetPixels(i * width, 0, width, height));
                sprites.Add(new SpriteInfo()
                {
                    texture = textureQuad,
                    name    = KlyteResourceLoader.GetDefaultSpriteNameFor(spriteValues.GetValue(i) as Enum)
                });
            }
        }
        public static List <SpriteInfo> CreateSpriteInfo(Dictionary <string, Tuple <RectOffset, bool> > borderDescriptors, string filename, Texture2D tex)
        {
            string textureName = Path.GetFileNameWithoutExtension(filename);
            string generatedSpriteName;

            if (textureName.StartsWith("%"))
            {
                generatedSpriteName = textureName.Substring(1);
            }
            else
            {
                generatedSpriteName = KlyteResourceLoader.GetDefaultSpriteNameFor(textureName);
            }
            borderDescriptors.TryGetValue(generatedSpriteName, out Tuple <RectOffset, bool> border);
            var res = new SpriteInfo
            {
                texture = tex,
                name    = generatedSpriteName,
                border  = border?.First ?? new RectOffset()
            };

            if (border?.Second ?? false)
            {
                return(new List <SpriteInfo>()
                {
                    res,
                    new SpriteInfo
                    {
                        texture = tex,
                        name = generatedSpriteName + NoBorderSuffix,
                        border = new RectOffset()
                    }
                });
            }
            else
            {
                return(new List <SpriteInfo>()
                {
                    res
                });
            }
        }
Ejemplo n.º 4
0
 public static void InitCircledButton(UIComponent parent, out UIButton button, CommonsSpriteNames sprite, MouseEventHandler onClicked, string tooltipLocale, float size = 40) => InitCircledButton(parent, out button, KlyteResourceLoader.GetDefaultSpriteNameFor(sprite), onClicked, tooltipLocale == null ? null : Locale.Get(tooltipLocale), size);