UITextureAtlas CreateMyAtlas(string AtlasName, Material BaseMat, string[] sPritesNames) { var size = 1024; Texture2D atlasTex = new Texture2D(size, size, TextureFormat.ARGB32, false); Texture2D[] textures = new Texture2D[sPritesNames.Length]; Rect[] rects = new Rect[sPritesNames.Length]; for(int i = 0; i < sPritesNames.Length; i++) { textures[i] = ResourceLoader.loadTexture(0, 0, sPritesNames[i] + ".png"); } rects = atlasTex.PackTextures(textures, 2, size); UITextureAtlas atlas = ScriptableObject.CreateInstance<UITextureAtlas>(); Material material = Material.Instantiate(BaseMat); material.mainTexture = atlasTex; atlas.material = material; atlas.name = AtlasName; for (int i = 0; i < sPritesNames.Length; i++) { var spriteInfo = new UITextureAtlas.SpriteInfo() { name = sPritesNames[i], texture = atlasTex, region = rects[i] }; atlas.AddSprite(spriteInfo); } return atlas; }
public static UITextureAtlas GetInfoTooltip(this AssetManager assetManager, string infoTooltipName, string infoTooltipPath) { var infoTooltipAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); infoTooltipAtlas.padding = 0; infoTooltipAtlas.name = infoTooltipName; var shader = Shader.Find("UI/Default UI Shader"); if (shader != null) { infoTooltipAtlas.material = new Material(shader); } var texture = assetManager.GetTexture(infoTooltipPath); infoTooltipAtlas.material.mainTexture = texture; const int ittW = 535; const int ittH = 150; var sprite = new UITextureAtlas.SpriteInfo { name = string.Format(infoTooltipName.ToUpper()), region = new Rect(0f, 0f, 1f, 1f), texture = new Texture2D(ittW, ittH, TextureFormat.ARGB32, false) }; infoTooltipAtlas.AddSprite(sprite); return(infoTooltipAtlas); }
public static UITextureAtlas CreateTextureAtlas( string textureFile, string atlasName, Material baseMaterial, int spriteWidth, int spriteHeight, string[] spriteNames) { Logger.Debug("Processing, textureFile: " + textureFile + ", atlasName: " + atlasName + ", width: " + (object)spriteWidth + ", height: " + (object)spriteHeight + ", baseMaterial" + (object)baseMaterial); int width = spriteWidth * spriteNames.Length; int height = spriteHeight; Texture2D texture = UIUtils.createTexture(textureFile, width, height); UITextureAtlas instance = (UITextureAtlas)ScriptableObject.CreateInstance <UITextureAtlas>(); Material material = (Material)Object.Instantiate <Material>((M0)baseMaterial); material.set_mainTexture((Texture)texture); instance.set_material(material); ((Object)instance).set_name(atlasName); for (int index = 0; index < spriteNames.Length; ++index) { float num = 1f / (float)spriteNames.Length; UITextureAtlas.SpriteInfo spriteInfo1 = new UITextureAtlas.SpriteInfo(); spriteInfo1.set_name(spriteNames[index]); spriteInfo1.set_texture(texture); spriteInfo1.set_region(new Rect((float)index * num, 0.0f, num, 1f)); UITextureAtlas.SpriteInfo spriteInfo2 = spriteInfo1; instance.AddSprite(spriteInfo2); } return(instance); }
public static bool SetThumbnails(string name, SpriteTextureInfo info, UITextureAtlas atlas, string[] states = null) { if (atlas == null || atlas.texture == null) return false; Texture2D atlasTex = atlas.texture; float atlasWidth = atlasTex.width; float atlasHeight = atlasTex.height; float rectWidth = info.width / atlasWidth; float rectHeight = info.height / atlasHeight; int x = info.startX; int y = info.startY; if (states == null) states = new string[] { "" }; for (int i = 0; i < states.Length; i++, x += info.width) { if (x < 0 || x + info.width > atlasWidth || y < 0 || y > atlasHeight) continue; Texture2D spriteTex = new Texture2D(info.width, info.height); spriteTex.SetPixels(atlasTex.GetPixels(x, y, info.width, info.height)); UITextureAtlas.SpriteInfo sprite = new UITextureAtlas.SpriteInfo() { name = name + states[i], region = new Rect(x / atlasWidth, y / atlasHeight, rectWidth, rectHeight), texture = spriteTex }; atlas.AddSprite(sprite); } return true; }
/// <summary> /// Create a new atlas. /// </summary> public static UITextureAtlas CreateTextureAtlas(string atlasName, Texture2D [] textures) { const int maxSize = 2048; Texture2D texture2D = new Texture2D(maxSize, maxSize, TextureFormat.ARGB32, false); Rect[] regions = texture2D.PackTextures(textures, 2, maxSize); Material material = Object.Instantiate <Material>(UIView.GetAView().defaultAtlas.material); material.mainTexture = texture2D; UITextureAtlas textureAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); textureAtlas.material = material; textureAtlas.name = atlasName; for (int i = 0; i < textures.Length; i++) { UITextureAtlas.SpriteInfo item = new UITextureAtlas.SpriteInfo { name = textures[i].name, texture = textures[i], region = regions[i], }; textureAtlas.AddSprite(item); } return(textureAtlas); }
public static UITextureAtlas CreateTextureAtlas(Texture2D texture2D, string atlasName, string[] spriteNames) { UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas>(); Assert(atlas, "uitextureAtlas"); Material material = Object.Instantiate <Material>(UIView.GetAView().defaultAtlas.material); Assert(material, "material"); material.mainTexture = texture2D.TryMakeReadable(); atlas.material = material; atlas.name = atlasName; int n = spriteNames.Length; for (int i = 0; i < n; i++) { float num = 1f / (float)spriteNames.Length; UITextureAtlas.SpriteInfo spriteInfo = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = texture2D, region = new Rect(i * num, 0f, num, 1f) }; atlas.AddSprite(spriteInfo); } return(atlas); }
UITextureAtlas CreateAtlas(string atlasName, string[] spriteNames, Texture2D[] spriteTextures) { Texture2D atlasTex = new Texture2D(1024, 1024, TextureFormat.ARGB32, false); Texture2D[] textures = spriteTextures; Rect[] rects = new Rect[1]; rects = atlasTex.PackTextures(textures, 2, 1024); UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas>(); Material material = (Material)Material.Instantiate(UIView.GetAView().defaultAtlas.material); material.mainTexture = atlasTex; atlas.material = material; atlas.name = atlasName; for (int i = 0; i < rects.Length; i++) { if (spriteNames[i] != null && textures[i] != null) { UITextureAtlas.SpriteInfo spriteInfo = new UITextureAtlas.SpriteInfo() { name = spriteNames[i], texture = textures[i], region = rects[i] }; atlas.AddSprite(spriteInfo); } } return(atlas); }
public static UITextureAtlas CreateAtlas(Texture2D[] sprites) { var atlas = ScriptableObject.CreateInstance <UITextureAtlas>(); atlas.material = new Material(GetUIAtlasShader()); var texture = new Texture2D(0, 0); var rects = texture.PackTextures(sprites, 0); for (var i = 0; i < rects.Length; ++i) { var sprite = sprites[i]; var rect = rects[i]; var spriteInfo = new UITextureAtlas.SpriteInfo { name = sprite.name, texture = sprite, region = rect, border = new RectOffset(), }; atlas.AddSprite(spriteInfo); } atlas.material.mainTexture = texture; return(atlas); }
private void CreateAtlas() { UITextureAtlas textureAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); Texture2D[] textures = new Texture2D[_spriteNames.Length]; Texture2D texture2D = new Texture2D(1, 1, TextureFormat.ARGB32, false); for (int i = 0; i < _spriteNames.Length; i++) { textures[i] = GetTextureFromAssemblyManifest(_spriteNames[i] + ".png"); } int maxSize = 1024; Rect[] regions = texture2D.PackTextures(textures, 2, maxSize); Material material = Object.Instantiate <Material>(UIView.GetAView().defaultAtlas.material); material.mainTexture = texture2D; textureAtlas.material = material; textureAtlas.name = "NetworkSkinsAtlas"; for (int i = 0; i < _spriteNames.Length; i++) { UITextureAtlas.SpriteInfo item = new UITextureAtlas.SpriteInfo { name = _spriteNames[i], texture = textures[i], region = regions[i], }; textureAtlas.AddSprite(item); } UITextureAtlas = textureAtlas; }
UITextureAtlas CreateMyAtlas(string AtlasName, Material BaseMat, string[] sPritesNames) { var size = 1024; Texture2D atlasTex = new Texture2D(size, size, TextureFormat.ARGB32, false); Texture2D[] textures = new Texture2D[sPritesNames.Length]; Rect[] rects = new Rect[sPritesNames.Length]; for (int i = 0; i < sPritesNames.Length; i++) { textures[i] = ResourceLoader.loadTexture(0, 0, sPritesNames[i] + ".png"); } rects = atlasTex.PackTextures(textures, 2, size); UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas>(); Material material = Material.Instantiate(BaseMat); material.mainTexture = atlasTex; atlas.material = material; atlas.name = AtlasName; for (int i = 0; i < sPritesNames.Length; i++) { var spriteInfo = new UITextureAtlas.SpriteInfo() { name = sPritesNames[i], texture = atlasTex, region = rects[i] }; atlas.AddSprite(spriteInfo); } return(atlas); }
public static void AddTexturesToAtlas(UITextureAtlas atlas, Texture2D[] newTextures) { Texture2D[] textures = new Texture2D[atlas.count + newTextures.Length]; for (int i = 0; i < atlas.count; i++) { Texture2D texture2D = atlas.sprites[i].texture; texture2D = texture2D.TryMakeReadable(); textures[i] = texture2D; textures[i].name = atlas.sprites[i].name; } for (int i = 0; i < newTextures.Length; i++) { textures[atlas.count + i] = newTextures[i]; } Rect[] regions = atlas.texture.PackTextures(textures, atlas.padding, 4096, false); atlas.sprites.Clear(); for (int i = 0; i < textures.Length; i++) { UITextureAtlas.SpriteInfo spriteInfo = atlas[textures[i].name]; atlas.sprites.Add(new UITextureAtlas.SpriteInfo { texture = textures[i], name = textures[i].name, border = spriteInfo?.border ?? new RectOffset(), region = regions[i], }); } atlas.RebuildIndexes(); }
UITextureAtlas CreateTextureAtlas(string textureFile, string atlasName, Material baseMaterial, int spriteWidth, int spriteHeight, string[] spriteNames) { Texture2D tex = new Texture2D(spriteWidth * spriteNames.Length, spriteHeight, TextureFormat.ARGB32, false) { filterMode = FilterMode.Bilinear }; { // LoadTexture tex.LoadImage(ResourceLoader.loadResourceData(textureFile)); tex.Apply(true, true); } UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas>(); { // Setup atlas Material material = (Material)Material.Instantiate(baseMaterial); material.mainTexture = tex; atlas.material = material; atlas.name = atlasName; } // Add sprites for (int i = 0; i < spriteNames.Length; ++i) { float uw = 1.0f / spriteNames.Length; var spriteInfo = new UITextureAtlas.SpriteInfo() { name = spriteNames[i], texture = tex, region = new Rect(i * uw, 0, uw, 1), }; atlas.AddSprite(spriteInfo); } return(atlas); }
public static UITextureAtlas CreateTextureAtlas(string atlasName, string[] spriteNames, string assemblyPath) { int maxSize = 1024; Texture2D texture2D = new Texture2D(maxSize, maxSize, TextureFormat.ARGB32, false); Texture2D[] textures = new Texture2D[spriteNames.Length]; Rect[] regions = new Rect[spriteNames.Length]; for (int i = 0; i < spriteNames.Length; i++) textures[i] = TextureLoader.LoadTextureFromAssembly(assemblyPath + spriteNames[i] + ".png"); regions = texture2D.PackTextures(textures, 2, maxSize); UITextureAtlas textureAtlas = ScriptableObject.CreateInstance<UITextureAtlas>(); Material material = UnityEngine.Object.Instantiate<Material>(UIView.GetAView().defaultAtlas.material); material.mainTexture = texture2D; textureAtlas.material = material; textureAtlas.name = atlasName; for (int i = 0; i < spriteNames.Length; i++) { UITextureAtlas.SpriteInfo item = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = textures[i], region = regions[i], }; textureAtlas.AddSprite(item); } return textureAtlas; }
public static UITextureAtlas GetInfoTooltip(this AssetManager assetManager, string infoTooltipName, string infoTooltipPath) { var infoTooltipAtlas = ScriptableObject.CreateInstance<UITextureAtlas>(); infoTooltipAtlas.padding = 0; infoTooltipAtlas.name = infoTooltipName; var shader = Shader.Find("UI/Default UI Shader"); if (shader != null) infoTooltipAtlas.material = new Material(shader); var texture = assetManager.GetTexture(infoTooltipPath); infoTooltipAtlas.material.mainTexture = texture; const int ittW = 535; const int ittH = 150; var sprite = new UITextureAtlas.SpriteInfo { name = string.Format(infoTooltipName.ToUpper()), region = new Rect(0f, 0f, 1f, 1f), texture = new Texture2D(ittW, ittH, TextureFormat.ARGB32, false) }; infoTooltipAtlas.AddSprite(sprite); return infoTooltipAtlas; }
public static UITextureAtlas CreateAtlas(Texture2D[] sprites) { UITextureAtlas atlas = new UITextureAtlas(); atlas.material = new Material(GetUIAtlasShader()); Texture2D texture = new Texture2D(0, 0); Rect[] rects = texture.PackTextures(sprites, 0); for (int i = 0; i < rects.Length; ++i) { Texture2D sprite = sprites[i]; Rect rect = rects[i]; UITextureAtlas.SpriteInfo spriteInfo = new UITextureAtlas.SpriteInfo(); spriteInfo.name = sprite.name; spriteInfo.texture = sprite; spriteInfo.region = rect; spriteInfo.border = new RectOffset(); atlas.AddSprite(spriteInfo); } atlas.material.mainTexture = texture; return(atlas); }
public static UITextureAtlas CreateAtlas(string[] names) { Texture2D[] sprites = ResourceUtils.Load <Texture2D>(names); UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas>(); atlas.material = new Material(ResourceUtils.GetUIAtlasShader()); Texture2D texture = new Texture2D(0, 0); Rect[] rects = texture.PackTextures(sprites, 0); for (int i = 0; i < rects.Length; ++i) { Texture2D sprite = sprites[i]; Rect rect = rects[i]; UITextureAtlas.SpriteInfo spriteInfo = new UITextureAtlas.SpriteInfo(); spriteInfo.name = sprite.name; spriteInfo.texture = sprite; spriteInfo.region = rect; spriteInfo.border = new RectOffset(); atlas.AddSprite(spriteInfo); } atlas.material.mainTexture = texture; return(atlas); }
private Rect CopySpriteToAtlas(UITextureAtlas atlas, int x, int y, string name, Texture2D texture) { var atlasTexture = atlas.material.mainTexture as Texture2D; for (int _x = 0; _x < texture.width; _x++) { for (int _y = 0; _y < texture.height; _y++) { atlasTexture.SetPixel(x + _x, y + _y, texture.GetPixel(_x, _y)); } } float u = (float)x / atlasTexture.width; float v = (float)y / atlasTexture.height; float s = (float)(texture.width) / atlasTexture.width; float t = (float)(texture.height) / atlasTexture.height; var sprite = new UITextureAtlas.SpriteInfo(); sprite.region = new Rect(u, v, s, t); sprite.name = name; sprite.texture = texture; atlas.AddSprite(sprite); return(sprite.region); }
public static UITextureAtlas GenerateLinearAtlas(string name, Texture2D texture, int numSprites, string[] spriteNames) { UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas>(); atlas.padding = 0; atlas.name = name; var shader = Shader.Find("UI/Default UI Shader"); if (shader != null) { atlas.material = new Material(shader); } atlas.material.mainTexture = texture; float spriteWidth = (float)texture.width / (float)numSprites; for (int i = 0; i < numSprites; ++i) { float x = (float)i / (float)numSprites; var sprite = new UITextureAtlas.SpriteInfo { name = spriteNames[i], region = new Rect(x, 0f, spriteWidth / (float)texture.width, 1f) }; var spriteTexture = new Texture2D((int)spriteWidth, texture.height); spriteTexture.SetPixels(texture.GetPixels((int)((float)texture.width * sprite.region.x), (int)((float)texture.height * sprite.region.y), (int)spriteWidth, texture.height)); sprite.texture = spriteTexture; atlas.AddSprite(sprite); } return(atlas); }
private static UITextureAtlas PackTextures(string atlasName, IntVector2 atlasSizeHint, List<Texture2D> loadedTextures, List<string> loadedSpriteNames) { Texture2D texture2D = new Texture2D( width: atlasSizeHint.x, height: atlasSizeHint.y, format: TextureFormat.ARGB32, mipmap: false); Rect[] regions = texture2D.PackTextures( textures: loadedTextures.ToArray(), padding: 2, maximumAtlasSize: Math.Max(atlasSizeHint.x, atlasSizeHint.y)); // Now using loaded and packed textures, create the atlas with sprites UITextureAtlas newAtlas = ScriptableObject.CreateInstance<UITextureAtlas>(); var uiView = UIView.GetAView(); Material material = UnityEngine.Object.Instantiate(uiView.defaultAtlas.material); material.mainTexture = texture2D; newAtlas.material = material; newAtlas.name = atlasName; for (int i = 0; i < loadedTextures.Count; i++) { var item = new UITextureAtlas.SpriteInfo { name = loadedSpriteNames[i], texture = loadedTextures[i], region = regions[i], }; newAtlas.AddSprite(item); } return newAtlas; }
public static UITextureAtlas CreateTextureAtlas(string atlasName, string[] spriteNames, FileDirectory dir) { int maxSize = 1024; Texture2D texture2D = new Texture2D(maxSize, maxSize, TextureFormat.ARGB32, false); Texture2D[] textures = new Texture2D[spriteNames.Length]; Rect[] regions = new Rect[spriteNames.Length]; for (int i = 0; i < spriteNames.Length; i++) { textures[i] = TextureLoader.LoadTextureFromFile(GetFilePath(dir, spriteNames[i] + ".png")); } regions = texture2D.PackTextures(textures, 2, maxSize); UITextureAtlas textureAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); Material material = UnityEngine.Object.Instantiate <Material>(UIView.GetAView().defaultAtlas.material); material.mainTexture = texture2D; textureAtlas.material = material; textureAtlas.name = atlasName; for (int i = 0; i < spriteNames.Length; i++) { UITextureAtlas.SpriteInfo item = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = textures[i], region = regions[i], }; textureAtlas.AddSprite(item); } return(textureAtlas); }
/// <summary> /// Loads a four-sprite texture atlas from a given .png file. /// </summary> /// <param name="atlasName">Atlas name (".png" will be appended fto make the filename)</param> /// <returns>New texture atlas</returns> internal static UITextureAtlas LoadSpriteAtlas(string atlasName) { // Create new texture atlas for button. UITextureAtlas newAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); newAtlas.name = atlasName; newAtlas.material = UnityEngine.Object.Instantiate <Material>(UIView.GetAView().defaultAtlas.material); // Load texture from file. Texture2D newTexture = LoadTexture(atlasName + ".png"); newAtlas.material.mainTexture = newTexture; // Setup sprites. string[] spriteNames = new string[] { "disabled", "normal", "pressed", "hovered" }; int numSprites = spriteNames.Length; float spriteWidth = 1f / spriteNames.Length; // Iterate through each sprite (counter increment is in region setup). for (int i = 0; i < numSprites; ++i) { UITextureAtlas.SpriteInfo sprite = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = newTexture, // Sprite regions are horizontally arranged, evenly spaced. region = new Rect(i * spriteWidth, 0f, spriteWidth, 1f) }; newAtlas.AddSprite(sprite); } return(newAtlas); }
public static UITextureAtlas CreateTextureAtlas(string textureFile, string atlasName, Material baseMaterial, int spriteWidth, int spriteHeight, string[] spriteNames) { Texture2D texture2D = new Texture2D(spriteWidth * spriteNames.Length, spriteHeight, TextureFormat.ARGB32, false); texture2D.filterMode = FilterMode.Bilinear; Assembly executingAssembly = Assembly.GetExecutingAssembly(); Stream manifestResourceStream = executingAssembly.GetManifestResourceStream("RoundaboutBuilder.Resources." + textureFile); byte[] array = new byte[manifestResourceStream.Length]; manifestResourceStream.Read(array, 0, array.Length); texture2D.LoadImage(array); texture2D.Apply(true, true); UITextureAtlas uitextureAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); Material material = UnityEngine.Object.Instantiate <Material>(baseMaterial); material.mainTexture = texture2D; uitextureAtlas.material = material; uitextureAtlas.name = atlasName; int num2; for (int i = 0; i < spriteNames.Length; i = num2) { float num = 1f / (float)spriteNames.Length; UITextureAtlas.SpriteInfo spriteInfo = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = texture2D, region = new Rect((float)i * num, 0f, num, 1f) }; uitextureAtlas.AddSprite(spriteInfo); num2 = i + 1; } return(uitextureAtlas); }
public static UITextureAtlas CreateTextureAtlas(string atlasName, string[] spriteNames, string assemblyPath) { var maxSize = 1024; var texture2D = new Texture2D(maxSize, maxSize, TextureFormat.ARGB32, false); var textures = new Texture2D[spriteNames.Length]; var regions = new Rect[spriteNames.Length]; for (var i = 0; i < spriteNames.Length; i++) { textures[i] = LoadTextureFromAssembly(assemblyPath + "." + spriteNames[i] + ".png"); } regions = texture2D.PackTextures(textures, 2, maxSize); var textureAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); var material = Object.Instantiate(UIView.GetAView().defaultAtlas.material); material.mainTexture = texture2D; textureAtlas.material = material; textureAtlas.name = atlasName; for (var i = 0; i < spriteNames.Length; i++) { var item = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = textures[i], region = regions[i] }; textureAtlas.AddSprite(item); } return(textureAtlas); }
/// <summary> /// Creates a new sprite using the size of the image inside the atlas. /// </summary> /// <param name="dimensions">The location and size of the sprite within the atlas (in pixels).</param> /// <param name="spriteName">The name of the sprite to create</param> /// <param name="atlasName">The name of the atlas to add the sprite to.</param> /// <returns></returns> public static bool AddSpriteToAtlas(Rect dimensions, string spriteName, string atlasName) { bool returnValue = false; if (m_atlasStore.ContainsKey(atlasName)) { UITextureAtlas foundAtlas = m_atlasStore[atlasName]; Texture2D atlasTexture = foundAtlas.texture; Vector2 atlasSize = new Vector2(atlasTexture.width, atlasTexture.height); Rect relativeLocation = new Rect(new Vector2(dimensions.position.x / atlasSize.x, dimensions.position.y / atlasSize.y), new Vector2(dimensions.width / atlasSize.x, dimensions.height / atlasSize.y)); Texture2D spriteTexture = new Texture2D((int)Math.Round(dimensions.width), (int)Math.Round(dimensions.height)); spriteTexture.SetPixels(atlasTexture.GetPixels((int)dimensions.position.x, (int)dimensions.position.y, (int)dimensions.width, (int)dimensions.height)); UITextureAtlas.SpriteInfo createdSprite = new UITextureAtlas.SpriteInfo() { name = spriteName, region = relativeLocation, texture = spriteTexture }; foundAtlas.AddSprite(createdSprite); returnValue = true; } return(returnValue); }
public static UITextureAtlas LoadInfoTooltip(string infoTooltipName, string infoTooltipPath) { var infoTooltipAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); infoTooltipAtlas.padding = 0; infoTooltipAtlas.name = infoTooltipName; var shader = Shader.Find("UI/Default UI Shader"); if (shader != null) { infoTooltipAtlas.material = new Material(shader); } var path = Mod.GetPath() + "/" + infoTooltipPath; var texture = new Texture2D(1, 1, TextureFormat.ARGB32, false); texture.LoadImage(File.ReadAllBytes(path)); infoTooltipAtlas.material.mainTexture = texture; const int ittW = 535; const int ittH = 150; var sprite = new UITextureAtlas.SpriteInfo { name = string.Format(infoTooltipName.ToUpper()), region = new Rect(0f, 0f, 1f, 1f), texture = new Texture2D(ittW, ittH, TextureFormat.ARGB32, false) }; infoTooltipAtlas.AddSprite(sprite); return(infoTooltipAtlas); }
public static UITextureAtlas CreateTextureAtlas(string textureFile, string atlasName, int spriteWidth, int spriteHeight, string[] spriteNames) { Texture2D texture2D = LoadTextureFromAssembly( textureFile, spriteWidth * spriteNames.Length, spriteHeight); UITextureAtlas uitextureAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); //Assert(uitextureAtlas != null, "uitextureAtlas"); Material material = Object.Instantiate <Material>(UIView.GetAView().defaultAtlas.material); //Assert(material != null, "material"); material.mainTexture = texture2D; uitextureAtlas.material = material; uitextureAtlas.name = atlasName; int num2; for (int i = 0; i < spriteNames.Length; i = num2) { float num = 1f / (float)spriteNames.Length; UITextureAtlas.SpriteInfo spriteInfo = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = texture2D, region = new Rect((float)i * num, 0f, num, 1f) }; uitextureAtlas.AddSprite(spriteInfo); num2 = i + 1; } return(uitextureAtlas); }
public static UITextureAtlas CreateTextureAtlas(string textureFile, string atlasName, int spriteWidth, int spriteHeight, string[] spriteNames, RectOffset border = null, int space = 0) { Texture2D texture2D = LoadTextureFromAssembly(textureFile, spriteWidth * spriteNames.Length + space * (spriteNames.Length + 1), spriteHeight + 2 * space); UITextureAtlas uitextureAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); Material material = Object.Instantiate(UIView.GetAView().defaultAtlas.material); material.mainTexture = texture2D; uitextureAtlas.material = material; uitextureAtlas.name = atlasName; var heightRatio = spriteHeight / (float)texture2D.height; var widthRatio = spriteWidth / (float)texture2D.width; var spaceHeightRatio = space / (float)texture2D.height; var spaceWidthRatio = space / (float)texture2D.width; for (int i = 0; i < spriteNames.Length; i += 1) { UITextureAtlas.SpriteInfo spriteInfo = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = texture2D, region = new Rect(i * widthRatio + (i + 1) * spaceWidthRatio, spaceHeightRatio, widthRatio, heightRatio), border = border ?? new RectOffset() }; uitextureAtlas.AddSprite(spriteInfo); } return(uitextureAtlas); }
/// <summary> /// Creates a new sprite using the size of the image inside the atlas. /// </summary> /// <param name="dimensions">The location and size of the sprite within the atlas (in pixels).</param> /// <param name="spriteName">The name of the sprite to create</param> /// <param name="atlasName">The name of the atlas to add the sprite to.</param> /// <returns></returns> public static bool AddSpriteToAtlas(Rect dimensions, string spriteName, string atlasName) { bool returnValue = false; if (m_atlasStore.ContainsKey(atlasName)) { UITextureAtlas foundAtlas = m_atlasStore[atlasName]; Texture2D atlasTexture = foundAtlas.texture; Vector2 atlasSize = new Vector2(atlasTexture.width, atlasTexture.height); Rect relativeLocation = new Rect(new Vector2(dimensions.position.x / atlasSize.x, dimensions.position.y / atlasSize.y), new Vector2(dimensions.width / atlasSize.x, dimensions.height / atlasSize.y)); Texture2D spriteTexture = new Texture2D((int)Math.Round(dimensions.width), (int)Math.Round(dimensions.height)); spriteTexture.SetPixels(atlasTexture.GetPixels((int)dimensions.position.x, (int)dimensions.position.y, (int)dimensions.width, (int)dimensions.height)); UITextureAtlas.SpriteInfo createdSprite = new UITextureAtlas.SpriteInfo() { name = spriteName, region = relativeLocation, texture = spriteTexture, border = new RectOffset() }; foundAtlas.AddSprite(createdSprite); returnValue = true; } return returnValue; }
public static UITextureAtlas CreateAtlas(string atlasName, string[] spriteNames, Texture2D[] sprites) { UITextureAtlas textureAtlas = ScriptableObject.CreateInstance <UITextureAtlas>(); Texture2D texture2D = new Texture2D(0, 0, TextureFormat.ARGB32, false); int maxSize = 4096; Rect[] regions = texture2D.PackTextures(sprites, 4, maxSize); Shader shader = Shader.Find("UI/Default UI Shader"); Material material = new Material(shader); material.mainTexture = texture2D; textureAtlas.material = material; textureAtlas.name = atlasName; for (int i = 0; i < spriteNames.Length; i++) { UITextureAtlas.SpriteInfo item = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = sprites[i], region = regions[i], }; textureAtlas.AddSprite(item); } return(textureAtlas); }
public static void AddTextureSpriteInfo(UITextureAtlas.SpriteInfo spriteInfo) { if (spriteInfo == null || spriteInfo.name == "" || spriteInfo.texture == null || (m_atlas[spriteInfo.name] != null)) { return; } m_atlas.AddSprite(spriteInfo); }
// Generates a texture atlas for a standard prefab button from a single image file. public static UITextureAtlas GenerateAtlas(string name, Texture2D texture) { // Generate Sprite Names string[] spriteStates = new[] { "", "Disabled", "Focused", "Hovered", "Pressed" }; string[] spriteNames = new string[5]; for (int i = 0; i < spriteNames.Length; i++) { spriteNames[i] = name + spriteStates[i].ToString(); } // Create a new texture atlas UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas>(); atlas.padding = 0; atlas.name = name; // Shader assignment var shader = Shader.Find("UI/Default UI Shader"); if (shader != null) { atlas.material = new Material(shader); } atlas.material.mainTexture = texture; // Assign regions and names for (int i = 0; i < 5; i++) { float y = 1; float x = (float)i / (float)5; // Create a new sprite UITextureAtlas.SpriteInfo sprite = new UITextureAtlas.SpriteInfo { name = spriteNames[i], region = new Rect(x, y, 0.2f, 1.0f) }; // Define sprite size and offsets int spriteWidth = 109; int spriteHeight = 100; int spriteOffsetY = 0; int spriteOffsetX = (int)((float)texture.width * sprite.region.x); // Create and fill a new texture Texture2D spriteTexture = new Texture2D(spriteWidth, spriteHeight); spriteTexture.SetPixels(texture.GetPixels(spriteOffsetX, spriteOffsetY, spriteWidth, spriteHeight)); sprite.texture = spriteTexture; // Add the finished sprite to the atlas atlas.AddSprite(sprite); } return(atlas); }
static void AddSprite(string name, Rect region, RectOffset border = null) { UITextureAtlas.SpriteInfo spriteInfo = new UITextureAtlas.SpriteInfo { name = name, texture = Atlas.material.mainTexture as Texture2D, region = region, border = border ?? new RectOffset() }; Atlas.AddSprite(spriteInfo); }
private void AddTexturesInAtlas(UITextureAtlas atlas, Texture2D[] newTextures) { Texture2D[] textures = new Texture2D[atlas.count + newTextures.Length]; for (int i = 0; i < atlas.count; i++) { // Locked textures workaround Texture2D texture2D = atlas.sprites[i].texture; if (texture2D != null) { RenderTexture renderTexture = RenderTexture.GetTemporary(texture2D.width, texture2D.height, 0); Graphics.Blit(texture2D, renderTexture); RenderTexture active = RenderTexture.active; texture2D = new Texture2D(renderTexture.width, renderTexture.height); RenderTexture.active = renderTexture; texture2D.ReadPixels(new Rect(0f, 0f, (float)renderTexture.width, (float)renderTexture.height), 0, 0); texture2D.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(renderTexture); textures[i] = texture2D; textures[i].name = atlas.sprites[i].name; } } for (int i = 0; i < newTextures.Length; i++) { textures[atlas.count + i] = newTextures[i]; } Rect[] regions = atlas.texture.PackTextures(textures, atlas.padding, 4096, false); atlas.sprites.Clear(); for (int i = 0; i < textures.Length; i++) { if (textures[i] != null) { UITextureAtlas.SpriteInfo spriteInfo = atlas[textures[i].name]; atlas.sprites.Add(new UITextureAtlas.SpriteInfo { texture = textures[i], name = textures[i].name, border = (spriteInfo != null) ? spriteInfo.border : new RectOffset(), region = regions[i] }); } } atlas.RebuildIndexes(); }
/*********** custom icons *************/ public static UITextureAtlas CreateTextureAtlas(string textureFile, string atlasName, Material baseMaterial, int spriteWidth, int spriteHeight, int spriteCountHor) { Texture2D tex = new Texture2D(spriteWidth * spriteCountHor, spriteHeight, TextureFormat.ARGB32, false); tex.filterMode = FilterMode.Bilinear; try { // LoadTexture System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream textureStream = assembly.GetManifestResourceStream("ResilientOwners." + textureFile); byte[] buf = new byte[textureStream.Length]; //declare arraysize textureStream.Read(buf, 0, buf.Length); // read from stream to byte array tex.LoadImage(buf); tex.Apply(true, true); } catch { CODebug.Log(LogChannel.Modding, "error opening texture file"); } UITextureAtlas atlas = ScriptableObject.CreateInstance <UITextureAtlas>(); try { // Setup atlas Material material = (Material)Material.Instantiate(baseMaterial); material.mainTexture = tex; atlas.material = material; atlas.name = atlasName; } catch { CODebug.Log(LogChannel.Modding, "error setting texture"); } // Add sprites for (int i = 0; i < spriteCountHor; ++i) { float uw = 1.0f / spriteCountHor; var spriteInfo = new UITextureAtlas.SpriteInfo() { name = atlasName + "_" + i, texture = tex, region = new Rect(i * uw, 0, uw, 1), }; atlas.AddSprite(spriteInfo); } return(atlas); }
public static void AddTextures(Texture2D[] newTextures, bool locked = false) { createStaticAtlas(); Texture2D[] textures = new Texture2D[m_atlas.count + newTextures.Length]; for (int i = 0; i < m_atlas.count; i++) { Texture2D texture2D = m_atlas.sprites[i].texture; if (locked) { // Locked textures workaround RenderTexture renderTexture = RenderTexture.GetTemporary(texture2D.width, texture2D.height, 0); Graphics.Blit(texture2D, renderTexture); RenderTexture active = RenderTexture.active; texture2D = new Texture2D(renderTexture.width, renderTexture.height); RenderTexture.active = renderTexture; texture2D.ReadPixels(new Rect(0f, 0f, (float)renderTexture.width, (float)renderTexture.height), 0, 0); texture2D.Apply(); RenderTexture.active = active; RenderTexture.ReleaseTemporary(renderTexture); } textures[i] = texture2D; textures[i].name = m_atlas.sprites[i].name; } for (int i = 0; i < newTextures.Length; i++) { textures[m_atlas.count + i] = newTextures[i]; } Rect[] regions = m_atlas.texture.PackTextures(textures, m_atlas.padding, 4096, false); m_atlas.sprites.Clear(); for (int i = 0; i < textures.Length; i++) { UITextureAtlas.SpriteInfo spriteInfo = m_atlas[textures[i].name]; m_atlas.sprites.Add(new UITextureAtlas.SpriteInfo { texture = textures[i], name = textures[i].name, border = (spriteInfo != null) ? spriteInfo.border : new RectOffset(), region = regions[i] }); } m_atlas.RebuildIndexes(); }
public static UITextureAtlas CreateTextureAtlas(string textureFile, string atlasName, Material baseMaterial, int spriteWidth, int spriteHeight) { string[] spriteNames = Enum.GetNames(typeof(SpriteName)); Texture2D tex = new Texture2D(spriteWidth * spriteNames.Length, spriteHeight, TextureFormat.ARGB32, false); tex.filterMode = FilterMode.Bilinear; { // LoadTexture System.Reflection.Assembly assembly = System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Stream textureStream = assembly.GetManifestResourceStream("ChangeRoadHeight." + textureFile); byte[] buf = new byte[textureStream.Length]; //declare arraysize textureStream.Read(buf, 0, buf.Length); // read from stream to byte array tex.LoadImage(buf); tex.Apply(true, true); } UITextureAtlas atlas = ScriptableObject.CreateInstance<UITextureAtlas>(); { // Setup atlas Material material = (Material)Material.Instantiate(baseMaterial); material.mainTexture = tex; atlas.material = material; atlas.name = atlasName; } // Add sprites for (int i = 0; i < spriteNames.Length; ++i) { float uw = 1.0f / spriteNames.Length; var spriteInfo = new UITextureAtlas.SpriteInfo() { name = spriteNames[i], texture = tex, region = new Rect(i * uw, 0, uw, 1), }; atlas.AddSprite(spriteInfo); } return atlas; }
/** * All credits to Craxy, authour of Toggle Traffic Lights * */ public static UITextureAtlas CreateAtlas(string file, string name, Material baseMaterial, int spriteWidth, int spriteHeight, string[] spriteNames) { var tex = new Texture2D(spriteWidth * spriteNames.Length, spriteHeight, TextureFormat.ARGB32, false) { filterMode = FilterMode.Bilinear, }; //load texture var assembly = System.Reflection.Assembly.GetExecutingAssembly(); using (var textureStream = assembly.GetManifestResourceStream("CSLMusicMod.Resources." + file)) { var buf = new byte[textureStream.Length]; //declare arraysize textureStream.Read(buf, 0, buf.Length); // read from stream to byte array tex.LoadImage(buf); tex.Apply(true, false); } var atlas = ScriptableObject.CreateInstance<UITextureAtlas>(); // Setup atlas var material = UnityEngine.Object.Instantiate(baseMaterial); material.mainTexture = tex; atlas.material = material; atlas.name = name; //add sprites for (var i = 0; i < spriteNames.Length; ++i) { var uw = 1.0f / spriteNames.Length; var spriteInfo = new UITextureAtlas.SpriteInfo { name = spriteNames[i], texture = tex, region = new Rect(i * uw, 0, uw, 1), }; atlas.AddSprite(spriteInfo); } return atlas; }
public static UITextureAtlas GetThumbnails(this AssetManager assetManager, string thumbnailsName, string thumbnailsPath) { var thumbnailAtlas = ScriptableObject.CreateInstance<UITextureAtlas>(); thumbnailAtlas.padding = 0; thumbnailAtlas.name = thumbnailsName; var shader = Shader.Find("UI/Default UI Shader"); if (shader != null) thumbnailAtlas.material = new Material(shader); var texture = assetManager.GetTexture(thumbnailsPath); texture.FixTransparency(); thumbnailAtlas.material.mainTexture = texture; const int iconW = 109; const int iconH = 100; const int textureW = iconW * 5; const int textureH = 100; string[] ts = { "", "Disabled", "Focused", "Hovered", "Pressed" }; for (int x = 0; x < ts.Length; ++x) { var sprite = new UITextureAtlas.SpriteInfo { name = string.Format(thumbnailsName.ToUpper() + "{0}", ts[x]), region = new Rect( (float)(x * iconW) / textureW, 0f, (float)(iconW) / textureW, (float)(iconH) / textureH), texture = new Texture2D(iconW, iconH, TextureFormat.ARGB32, false) }; thumbnailAtlas.AddSprite(sprite); } return thumbnailAtlas; }
public static UITextureAtlas CreateAtlas(Texture2D[] sprites) { UITextureAtlas atlas = new UITextureAtlas(); atlas.material = new Material(GetUIAtlasShader()); Texture2D texture = new Texture2D(0, 0); Rect[] rects = texture.PackTextures(sprites, 0); for (int i = 0; i < rects.Length; ++i) { Texture2D sprite = sprites[i]; Rect rect = rects[i]; UITextureAtlas.SpriteInfo spriteInfo = new UITextureAtlas.SpriteInfo(); spriteInfo.name = sprite.name; spriteInfo.texture = sprite; spriteInfo.region = rect; spriteInfo.border = new RectOffset(); atlas.AddSprite(spriteInfo); } atlas.material.mainTexture = texture; return atlas; }
UITextureAtlas CreateTextureAtlas(string atlasName, Material baseMaterial, string[] spriteNames, string assemblyPath) { var size = 1024; Texture2D atlasTex = new Texture2D(size, size, TextureFormat.ARGB32, false); Texture2D[] textures = new Texture2D[spriteNames.Length]; Rect[] rects = new Rect[spriteNames.Length]; for(int i = 0; i < spriteNames.Length; i++) { textures[i] = loadTextureFromAssembly(assemblyPath + spriteNames[i] + ".png", false); } rects = atlasTex.PackTextures(textures, 2, size); UITextureAtlas atlas = ScriptableObject.CreateInstance<UITextureAtlas>(); // Setup atlas Material material = Material.Instantiate(baseMaterial); material.mainTexture = atlasTex; atlas.material = material; atlas.name = atlasName; // Add SpriteInfo for (int i = 0; i < spriteNames.Length; i++) { var spriteInfo = new UITextureAtlas.SpriteInfo() { name = spriteNames[i], texture = atlasTex, region = rects[i] }; atlas.AddSprite(spriteInfo); } return atlas; }
public static UITextureAtlas LoadThumbnails() { if (s_thumbnailAtlas != null) { return s_thumbnailAtlas; } var thumbnailAtlas = ScriptableObject.CreateInstance<UITextureAtlas>(); thumbnailAtlas.padding = 0; thumbnailAtlas.name = "AdditionnalSubBar"; var shader = Shader.Find("UI/Default UI Shader"); if (shader != null) thumbnailAtlas.material = new Material(shader); const string PATH = @"Menus\Textures\AdditionnalSubBar.png"; const string BASE = "SubBarButtonBase"; const string ROADS_SMALL_HV_SUBBAR = "SubBar" + AdditionnalMenus.ROADS_SMALL_HV; var versions = new[] { "", "Disabled", "Focused", "Hovered", "Pressed" }; var texture = AssetManager.instance.GetTexture(PATH); texture.FixTransparency(); thumbnailAtlas.material.mainTexture = texture; var x = 1; var y = 1; const int TEXTURE_W = 292; const int TEXTURE_H = 50; // Base ------------------------------------------------------------------------------- const int BASE_ICON_W = 58; const int BASE_ICON_H = 25; foreach (var t in versions) { var sprite = new UITextureAtlas.SpriteInfo { name = string.Format(BASE + "{0}", t), region = new Rect( (float)(x) / TEXTURE_W, (float)(y) / TEXTURE_H, (float)(BASE_ICON_W) / TEXTURE_W, (float)(BASE_ICON_H) / TEXTURE_H), texture = new Texture2D(BASE_ICON_W, BASE_ICON_H, TextureFormat.ARGB32, false) }; thumbnailAtlas.AddSprite(sprite); x += BASE_ICON_W; } x = 1; y += BASE_ICON_H + 1; // RoadsSmallHV ----------------------------------------------------------------------- const int ICON_W = 32; const int ICON_H = 22; foreach (var t in versions) { var sprite = new UITextureAtlas.SpriteInfo { name = string.Format(ROADS_SMALL_HV_SUBBAR + "{0}", t), region = new Rect( (float)(x) / TEXTURE_W, (float)(y) / TEXTURE_H, (float)(ICON_W) / TEXTURE_W, (float)(ICON_H) / TEXTURE_H), texture = new Texture2D(ICON_W, ICON_H, TextureFormat.ARGB32, false) }; thumbnailAtlas.AddSprite(sprite); x += ICON_W; } s_thumbnailAtlas = thumbnailAtlas; return s_thumbnailAtlas; }
private static Rect CopySpriteToAtlas(UITextureAtlas atlas, int x, int y, string name, Texture2D texture) { var atlasTexture = atlas.material.mainTexture as Texture2D; for (int _x = 0; _x < texture.width; _x++) { for (int _y = 0; _y < texture.height; _y++) { if (atlasTexture != null) atlasTexture.SetPixel(x + _x, y + _y, texture.GetPixel(_x, _y)); } } if (atlasTexture != null) { float u = (float)x / atlasTexture.width; float v = (float)y / atlasTexture.height; float s = (float)(texture.width) / atlasTexture.width; float t = (float)(texture.height) / atlasTexture.height; var sprite = new UITextureAtlas.SpriteInfo {region = new Rect(u, v, s, t), name = name, texture = texture}; atlas.AddSprite(sprite); return sprite.region; } return new Rect(); }
public UITextureAtlas GenerateAtlas(string atlasName) { SortSprites(); var atlas = ScriptableObject.CreateInstance<UITextureAtlas>(); atlas.material = new Material(Shader.Find("UI/Default UI Shader")); var atlasTexture = new Texture2D(2048, 2048, TextureFormat.ARGB32, false, false) {filterMode = FilterMode.Bilinear}; atlas.material.mainTexture = atlasTexture; var transparent = new Color(0, 0, 0, 0); for (int _x = 0; _x < atlasTexture.width; _x++) { for (int _y = 0; _y < atlasTexture.height; _y++) { atlasTexture.SetPixel(_x, _y, transparent); } } int x = 2; int y = 2; int maxY = 0; foreach (var item in _rawSprites) { var name = item.Key; var texture = item.Value; if (x + texture.width >= atlasTexture.width) { x = 0; y += maxY + 2; maxY = 0; if (y >= atlasTexture.height) { throw new TooManySprites(); } } CopySpriteToAtlas(atlas, x, y, name, texture); x += texture.width + 2; maxY = Mathf.Max(maxY, texture.height); } foreach (var item in _pathSprites) { var name = item.Key; var pngPath = item.Value; if (_spriteCache.ContainsKey(pngPath)) { var cachedSprite = new UITextureAtlas.SpriteInfo { name = name, texture = _spriteCache[pngPath].Key, region = _spriteCache[pngPath].Value }; atlas.AddSprite(cachedSprite); Debug.LogWarningFormat("Texture for sprite \"{0}\" already exists in atlas, reusing cached copy..", name); continue; } var texture = new Texture2D(0, 0, TextureFormat.ARGB32, false, true); texture.LoadImage(File.ReadAllBytes(pngPath)); if (x + texture.width >= atlasTexture.width) { x = 0; y += maxY + 2; maxY = 0; if (y >= atlasTexture.height) { throw new TooManySprites(); } } var spriteRect = CopySpriteToAtlas(atlas, x, y, name, texture); _spriteCache.Add(pngPath, new KeyValuePair<Texture2D, Rect>(texture, spriteRect)); x += texture.width + 2; maxY = Mathf.Max(maxY, texture.height); } atlasTexture.Apply(); return atlas; }
public UITextureAtlas Build() { var thumbnailAtlas = ScriptableObject.CreateInstance<UITextureAtlas>(); thumbnailAtlas.padding = 0; thumbnailAtlas.name = "RExExtendedSubBar"; var shader = Shader.Find("UI/Default UI Shader"); if (shader != null) thumbnailAtlas.material = new Material(shader); const string PATH = @"Menus\Roads\Textures\RExExtendedSubBar.png"; const string BASE = "SubBarButtonBase"; const string ROADS_TINY_SUBBAR = "SubBar" + RExExtendedMenus.ROADS_TINY; const string ROADS_SMALL_HV_SUBBAR = "SubBar" + RExExtendedMenus.ROADS_SMALL_HV; const string ROADS_BUSWAYS_SUBBAR = "SubBar" + RExExtendedMenus.ROADS_BUSWAYS; const string ROADS_PED_SUBBAR = "SubBar" + RExExtendedMenus.ROADS_PEDESTRIANS; var versions = new[] { "", "Disabled", "Focused", "Hovered", "Pressed" }; var texture = AssetManager.instance.GetTexture(PATH, TextureType.UI); texture.FixTransparency(); thumbnailAtlas.material.mainTexture = texture; var x = 1; var y = 1; const int TEXTURE_W = 292; const int TEXTURE_H = 119; // Base ------------------------------------------------------------------------------- const int BASE_ICON_W = 58; const int BASE_ICON_H = 25; foreach (var t in versions) { var sprite = new UITextureAtlas.SpriteInfo { name = string.Format(BASE + "{0}", t), region = new Rect( (float)(x) / TEXTURE_W, (float)(y) / TEXTURE_H, (float)(BASE_ICON_W) / TEXTURE_W, (float)(BASE_ICON_H) / TEXTURE_H), texture = new Texture2D(BASE_ICON_W, BASE_ICON_H, TextureFormat.ARGB32, false) }; thumbnailAtlas.AddSprite(sprite); x += BASE_ICON_W; } y += BASE_ICON_H; // Button Icons ----------------------------------------------------------------------- var buttonIcons = new[] { ROADS_TINY_SUBBAR, ROADS_SMALL_HV_SUBBAR, ROADS_BUSWAYS_SUBBAR, ROADS_PED_SUBBAR }; const int ICON_W = 32; const int ICON_H = 22; foreach (var bi in buttonIcons) { x = 1; y += 1; foreach (var t in versions) { var sprite = new UITextureAtlas.SpriteInfo { name = string.Format(bi + "{0}", t), region = new Rect( (float)(x) / TEXTURE_W, (float)(y) / TEXTURE_H, (float)(ICON_W) / TEXTURE_W, (float)(ICON_H) / TEXTURE_H), texture = new Texture2D(ICON_W, ICON_H, TextureFormat.ARGB32, false) }; thumbnailAtlas.AddSprite(sprite); x += ICON_W; } y += ICON_H; } return thumbnailAtlas; }