Example #1
0
 public void SetIcon(UITextureAtlas atlas, string sprite)
 {
     Icon.atlas           = atlas ?? TextureHelper.InGameAtlas;
     Icon.normalBgSprite  = sprite;
     Icon.hoveredBgSprite = sprite;
     Icon.pressedBgSprite = sprite;
 }
Example #2
0
        public void CreateWarningItem(UIComponent parent, string name, int index, UITextureAtlas atlas)
        {
            try
            {
                Name = name;

                _panel                  = UIUtils.CreatePanel(parent, name);
                _panel.anchor           = UIAnchorStyle.Top | UIAnchorStyle.Left;
                _panel.height           = 30f;
                _panel.width            = 180f;
                _panel.relativePosition = new Vector3(25f + (180f * (index % 4)), 75f + (30f * (index / 4)));

                _sprite                  = UIUtils.CreateSprite(_panel, "WarningSprite", "BuildingEventSad");
                _sprite.atlas            = atlas;
                _sprite.size             = new Vector2(25f, 25f);
                _sprite.relativePosition = new Vector3(0f, 0f);

                _count = UIUtils.CreateLabel(_panel, "WarningCount", "0");
                _count.relativePosition = new Vector3(30f, 4.5f);
            }
            catch (Exception e)
            {
                Debug.Log("[Watch It!] WarningItem:CreateWarningItem -> Exception: " + e.Message);
            }
        }
Example #3
0
        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);
        }
        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);
        }
Example #5
0
        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);
        }
Example #6
0
        public StatesButton(UIComponent component, int spriteWidth, int spriteHeight, int spriteCountHorizontal, string icons_atlas, string name, string[] tooltips)
        {
            msb = component.AddUIComponent <UIMultiStateButton> ();

            UITextureAtlas atlas = CreateTextureAtlas(icons_atlas, name, msb.atlas.material, spriteWidth, spriteHeight, spriteCountHorizontal);

            msb.name = name;

            msb.atlas = atlas;
            for (int i = 0; i < spriteCountHorizontal; i++)
            {
                msb.backgroundSprites[i].normal = name + "_" + i;
                if (i < spriteCountHorizontal - 1)
                {
                    msb.backgroundSprites.AddState();
                    msb.foregroundSprites.AddState();
                }
            }
            msb.tooltip = tooltips[0];
            if (tooltips.Length == spriteCountHorizontal)
            {
                msb.eventActiveStateIndexChanged += (component2, value) => {
                    msb.tooltip = tooltips[value];
                };
            }
            msb.width  = spriteWidth;
            msb.height = spriteHeight;
        }
Example #7
0
        public static UIButton CreateButton(UIComponent parent, Vector2 size,
                                            string text             = "", string tooltip = "", string foregroundSprite = "",
                                            string backgroundSprite = "ButtonSmall", bool isFocusable = false,
                                            UITextureAtlas atlas    = null, RectOffset padding        = null, float textScale = 1.0f)
        {
            var button = parent.AddUIComponent <UIButton>();

            button.size                 = size;
            button.text                 = text;
            button.tooltip              = tooltip;
            button.textPadding          = padding ?? new RectOffset(8, 8, 8, 5);
            button.disabledTextColor    = new Color32(128, 128, 128, 255);
            button.normalBgSprite       = backgroundSprite;
            button.hoveredBgSprite      = string.Concat(backgroundSprite, "Hovered");
            button.pressedBgSprite      = string.Concat(backgroundSprite, "Pressed");
            button.disabledBgSprite     = string.Concat(backgroundSprite, "Disabled");
            button.focusedBgSprite      = string.Concat(backgroundSprite, isFocusable ? "Focused" : "");
            button.normalFgSprite       = foregroundSprite;
            button.hoveredFgSprite      = string.Concat(foregroundSprite, "Hovered");
            button.pressedFgSprite      = string.Concat(foregroundSprite, "Pressed");
            button.disabledFgSprite     = string.Concat(foregroundSprite, "Disabled");
            button.focusedFgSprite      = string.Concat(foregroundSprite, isFocusable ? "Focused" : "");
            button.atlas                = atlas ?? UISprites.DefaultAtlas;
            button.textScale            = textScale;
            button.foregroundSpriteMode = UIForegroundSpriteMode.Stretch;
            return(button);
        }
Example #8
0
        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);
        }
Example #9
0
        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>
        /// 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);
        }
Example #11
0
        private UITextureAtlas LoadResources()
        {
            try
            {
                if (_textureAtlas == null)
                {
                    string[] spriteNames = new string[]
                    {
                        "buttondown",
                        "buttonleft",
                        "buttonresizecompressed",
                        "buttonresizeexpanded",
                        "buttonright",
                        "buttonup",
                        "hover"
                    };

                    _textureAtlas = ResourceLoader.CreateTextureAtlas("ResizeItAtlas", spriteNames, "ResizeIt.Icons.");
                }

                return(_textureAtlas);
            }
            catch (Exception e)
            {
                Debug.Log("[Resize It!] ModManager:LoadResources -> Exception: " + e.Message);
                return(null);
            }
        }
Example #12
0
        public void Start()
        {
            try
            {
                _textureAtlas = LoadResources();

                _controlPanelValidToolbarButtonNames = new List <string>()
                {
                    "RoadsPanel", "ZoningPanel", "DistrictPanel", "ElectricityPanel", "WaterAndSewagePanel", "GarbagePanel", "HealthcarePanel", "FireDepartmentPanel", "PolicePanel", "EducationPanel", "PublicTransportPanel", "BeautificationPanel", "MonumentsPanel", "WondersPanel", "LandscapingPanel", "ResourcePanel", "WaterPanel", "SurfacePanel", "PloppableBuildingPanel", "FindItGroupPanel"
                };

                ModConfig.Instance.ScalingExpanded = ModConfig.Instance.ScalingExpanded > 0.5f ? ModConfig.Instance.ScalingExpanded : 1f;
                ModConfig.Instance.RowsExpanded    = ModConfig.Instance.RowsExpanded > 0 ? ModConfig.Instance.RowsExpanded : 3;
                ModConfig.Instance.ColumnsExpanded = ModConfig.Instance.ColumnsExpanded > 0 ? ModConfig.Instance.ColumnsExpanded : 7;
                ModConfig.Instance.OpacityExpanded = ModConfig.Instance.OpacityExpanded > 0f ? ModConfig.Instance.OpacityExpanded : 1f;

                ModConfig.Instance.ScalingCompressed = ModConfig.Instance.ScalingCompressed > 0.5f ? ModConfig.Instance.ScalingCompressed : 1f;
                ModConfig.Instance.RowsCompressed    = ModConfig.Instance.RowsCompressed > 0 ? ModConfig.Instance.RowsCompressed : 1;
                ModConfig.Instance.ColumnsCompressed = ModConfig.Instance.ColumnsCompressed > 0 ? ModConfig.Instance.ColumnsCompressed : 7;
                ModConfig.Instance.OpacityCompressed = ModConfig.Instance.OpacityCompressed > 0f ? ModConfig.Instance.OpacityCompressed : 1f;

                CreateControlPanel();
            }
            catch (Exception e)
            {
                Debug.Log("[Resize It!] ModManager:Start -> Exception: " + e.Message);
            }
        }
Example #13
0
        private void Uninstall()
        {
            if (NetworkSkinPanelController.Instance != null)
            {
                NetworkSkinPanelController.Instance.EventToolStateChanged -= OnNetToolStateChanged;
                if (skinControllerGameObject != null)
                {
                    Destroy(skinControllerGameObject);
                    skinControllerGameObject = null;
                }
            }

            if (PersistenceService.Instance != null)
            {
                if (persistenceServiceGameObject != null)
                {
                    Destroy(persistenceServiceGameObject);
                    persistenceServiceGameObject = null;
                }
            }

            if (panel != null && panel.gameObject != null)
            {
                Destroy(panel.gameObject);
                panel = null;
            }

            defaultAtlas = null;
        }
Example #14
0
        /// <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);
        }
Example #15
0
        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);
        }
Example #16
0
        private void Awake()
        {
            try
            {
                if (_tsBar == null)
                {
                    _tsBar = GameObject.Find("TSBar").GetComponent <UISlicedSprite>();
                }

                if (_bulldozerUndergroundToggle == null)
                {
                    _bulldozerUndergroundToggle = GameObject.Find("BulldozerUndergroundToggle").GetComponent <UIMultiStateButton>();
                }

                if (_happiness == null)
                {
                    _happiness = GameObject.Find("Happiness").GetComponent <UISprite>();
                }

                _textureAtlas = LoadResources();

                CreateUI();
            }
            catch (Exception e)
            {
                Debug.Log("[Bulldoze It!] Bulldozer:Awake -> Exception: " + e.Message);
            }
        }
Example #17
0
        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);
        }
Example #18
0
        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 void GetAtlas(string atlasName, out UITextureAtlas result)
 {
     if (!LocalAtlases.TryGetValue(atlasName ?? string.Empty, out result) && ulong.TryParse(atlasName ?? string.Empty, out ulong workshopId))
     {
         AssetAtlases.TryGetValue(workshopId, out result);
     }
 }
Example #20
0
        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();
        }
Example #21
0
        public static UITextureAtlas GetIconsAtlas()
        {
            Texture2D[] textures =
            {
                UIToolOptionPanel.instance.atlas["OptionBase"].texture,
                UIToolOptionPanel.instance.atlas["OptionBaseHovered"].texture,
                UIToolOptionPanel.instance.atlas["OptionBasePressed"].texture,
                UIToolOptionPanel.instance.atlas["OptionBaseDisabled"].texture,
                UIToolOptionPanel.instance.atlas["OptionBaseFocused"].texture
            };

            string[] spriteNames = new string[]
            {
                "NFExpand",
                "NFExpandHover",
                "NFCollapse",
                "NFCollapseHover"
            };

            UITextureAtlas loadedAtlas = ResourceLoader.CreateTextureAtlas("MoveIt_NFBtn", spriteNames, "MoveIt.Icons.");

            ResourceLoader.AddTexturesInAtlas(loadedAtlas, textures);

            return(loadedAtlas);
        }
Example #22
0
        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);

            tex.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 CreateAtlas(Texture2D[] sprites)
        {
            UITextureAtlas atlas = ScriptableObject.CreateInstance <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 = new 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);
        }
Example #25
0
        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);
        }
Example #26
0
        /// <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);
        }
Example #27
0
        private UITextureAtlas GetIconsAtlas()
        {
            Texture2D[] textures =
            {
                atlas["OptionBase"].texture,
                atlas["OptionBaseHovered"].texture,
                atlas["OptionBasePressed"].texture,
                atlas["OptionBaseDisabled"].texture,
                atlas["OptionBaseFocused"].texture
            };

            string[] spriteNames = new string[]
            {
                "AlignHeight",
                "Copy",
                "Bulldoze",
                "Group",
                "Save",
                "Save_disabled",
                "Load",
                "Grid",
                "GridFocused"
            };

            UITextureAtlas loadedAtlas = ResourceLoader.CreateTextureAtlas("MoveIt_Icons", spriteNames, "MoveIt.Icons.");

            ResourceLoader.AddTexturesInAtlas(loadedAtlas, textures);

            return(loadedAtlas);
        }
Example #28
0
        public static UILabel CreateLabelSpriteImage(UIComponent parent, UITextureAtlas atlas_a)
        {
            UILabel label = (UILabel)parent.AddUIComponent <UILabel>();

            label.atlas    = atlas_a;
            label.canFocus = false;
            return(label);
        }
Example #29
0
 private void InitAtlases()
 {
     if (m_IconAtlas == null)
     {
         CSLMusicMod.Log("Creating icon atlases ...");
         m_IconAtlas = TextureHelper.CreateDefaultIconAtlas();
     }
 }
 void Awake()
 {
     this.m_strip = GetComponentInChildren <UITabstrip>();
     this.m_strip.relativePosition   = new Vector3(13, -25);
     this.m_strip.startSelectedIndex = 0;
     this.m_atlas = UIUtils.LoadThumbnailsTextureAtlas("UIThumbnails");
     UIUtils.SetThumbnails("TabBg", sm_thumbnailCoords["TabBackgrounds"], this.m_atlas, sm_thumbnailStates);
     this.m_objectIndex = 0;
 }
 void Awake()
 {
     this.m_strip = GetComponentInChildren<UITabstrip>();
     this.m_strip.relativePosition = new Vector3(13, -25);
     this.m_strip.startSelectedIndex = 0;
     this.m_atlas = UIUtils.LoadThumbnailsTextureAtlas("UIThumbnails");
     UIUtils.SetThumbnails("TabBg", sm_thumbnailCoords["TabBackgrounds"], this.m_atlas, sm_thumbnailStates);
     this.m_objectIndex = 0;
 }
Example #32
0
        internal UITextureAtlas GetIconsAtlas()
        {
            Texture2D[] textures =
            {
                atlas["OptionBase"].texture,
                atlas["OptionBaseHovered"].texture,
                atlas["OptionBasePressed"].texture,
                atlas["OptionBaseDisabled"].texture,
                atlas["OptionBaseFocused"].texture,
                atlas["OptionsDropboxListbox"].texture,
                atlas["OptionsDropboxListboxHovered"].texture,
                atlas["OptionsDropboxListboxFocused"].texture
            };

            string[] spriteNames = new string[]
            {
                "MoreTools",
                "AlignIndividual",
                "AlignIndividualActive",
                "AlignGroup",
                "AlignGroupActive",
                "AlignRandom",
                "AlignSlope",
                "AlignSlopeA",
                "AlignSlopeB",
                "AlignHeight",
                "AlignLine",
                "AlignMirror",
                "AlignTerrainHeight",
                "MoveTo",
                "MoveToActive",
                "ConvertToPO",
                "EyeDropper",
                "Copy",
                "Bulldoze",
                "ResetObject",
                "MenuHeight",
                "MenuOthers",
                "MenuRotate",
                "Save",
                "Save_disabled",
                "Load",
                "Grid",
                "GridFocused",
                "PO",
                "POFocused",
                "SubmenuBG",
                "SubmenuSeparator"
            };

            UITextureAtlas loadedAtlas = ResourceLoader.CreateTextureAtlas("MoveIt_Icons", spriteNames, "MoveIt.Icons.");

            ResourceLoader.AddTexturesInAtlas(loadedAtlas, textures);

            return(loadedAtlas);
        }
        public static UIButton SpawnSubEntry(UITabstrip strip, string name, string localeID, string unlockText, string spriteBase, bool enabled,
            UIComponent m_OptionsBar, UITextureAtlas m_DefaultInfoTooltipAtlas)
        {
            if (strip.Find<UIButton>(name) != null)
            {
                return null;
            }

            Type type1 = Util.FindType(name + "Group" + "Panel");
            if (type1 != null && !type1.IsSubclassOf(typeof(GeneratedGroupPanel)))
                type1 = (Type)null;
            if (type1 == null)
                return (UIButton)null;
            UIButton button;

            GameObject asGameObject1 = UITemplateManager.GetAsGameObject(kMainToolbarButtonTemplate);
            GameObject asGameObject2 = UITemplateManager.GetAsGameObject(kScrollableSubPanelTemplate);
            UITabstrip uiTabstrip = strip;
            string name1 = name;
            GameObject strip1 = asGameObject1;
            GameObject page = asGameObject2;
            Type[] typeArray = new Type[1];
            int index = 0;
            Type type2 = type1;
            typeArray[index] = type2;
            button = uiTabstrip.AddTab(name1, strip1, page, typeArray) as UIButton;

            button.isEnabled = enabled;
            button.gameObject.GetComponent<TutorialUITag>().tutorialTag = name;
            GeneratedGroupPanel generatedGroupPanel = GameObject.FindObjectOfType(type1) as GeneratedGroupPanel;
            if ((Object)generatedGroupPanel != (Object)null)
            {
                generatedGroupPanel.component.isInteractive = true;
                generatedGroupPanel.m_OptionsBar = m_OptionsBar;
                generatedGroupPanel.m_DefaultInfoTooltipAtlas = m_DefaultInfoTooltipAtlas;
                if (enabled)
                    generatedGroupPanel.RefreshPanel();
            }
            button.normalBgSprite = GetBackgroundSprite(button, spriteBase, name, "Normal");
            button.focusedBgSprite = GetBackgroundSprite(button, spriteBase, name, "Focused");
            button.hoveredBgSprite = GetBackgroundSprite(button, spriteBase, name, "Hovered");
            button.pressedBgSprite = GetBackgroundSprite(button, spriteBase, name, "Pressed");
            button.disabledBgSprite = GetBackgroundSprite(button, spriteBase, name, "Disabled");
            string str = spriteBase + name;
            button.normalFgSprite = str;
            button.focusedFgSprite = str + "Focused";
            button.hoveredFgSprite = str + "Hovered";
            button.pressedFgSprite = str + "Pressed";
            button.disabledFgSprite = str + "Disabled";
            if (unlockText != null)
                button.tooltip = Locale.Get(localeID, name) + " - " + unlockText;
            else
                button.tooltip = Locale.Get(localeID, name);
            return button;
        }
 private void Awake()
 {
     this.m_atlas = UIUtils.LoadThumbnailsTextureAtlas("UIThumbnails");
     this.m_scrollablePanel = GetComponentInChildren<UIScrollablePanel>();
     this.m_scrollablePanel.autoLayoutStart = LayoutStart.TopLeft;
     UIScrollbar scrollbar = this.GetComponentInChildren<UIScrollbar>();
     if (scrollbar != null)
         scrollbar.incrementAmount = 109;
     this.m_objectIndex = m_selectedIndex = 0;
     this.m_panelType = Panel.Unset;
 }
 public override void Start()
 {
     base.Start();
     this.size = new Vector2(432, 25);
     this.relativePosition = new Vector2(13, -25);
     this.name = "SubBuildingsTabstrip";
     this.startSelectedIndex = 0;
     this.padding = new RectOffset(0, 3, 0, 0);
     ingame = Resources.FindObjectsOfTypeAll<UITextureAtlas>().FirstOrDefault(a => a.name == "Ingame");
     thumbnails = Resources.FindObjectsOfTypeAll<UITextureAtlas>().FirstOrDefault(a => a.name == "Thumbnails");
 }
        public void LoadAtlasIcons()
        {
            string[] sPritesNames = {

                "FavoriteCimsButton",
                "FavoriteCimsButtonHovered",
                "FavoriteCimsButtonPressed",
                "FavoriteCimsButtonFocused",
                "icon_fav_subscribed",
                "icon_fav_unsubscribed"
            };

            FavCimsAtlas = CreateMyAtlas ("FavCimsAtlas", UIView.GetAView ().defaultAtlas.material, sPritesNames);
        }
		public static UITextureAtlas GetQuartzAtlas()
        {
            if (_atlas == null)
            {
                var atlasPacker = new AtlasPacker();
				atlasPacker.AddSprite("QuartzIcon", GetTextureResource("QuartzIcon.png"));
				atlasPacker.AddSprite("QuartzIconHover", GetTextureResource("QuartzIconHover.png"));
				atlasPacker.AddSprite("QuartzIconPressed", GetTextureResource("QuartzIconPressed.png"));
                atlasPacker.AddSprite("DefaultPanelBackground", GetTextureResource("DefaultPanelBackground.png"));
				_atlas = atlasPacker.GenerateAtlas("QuartzIconsAtlas");
            }

            return _atlas;
        }
 public static void CopySprite(string originalName, string newName, UITextureAtlas destAtlas)
 {
     try
     {
         var spriteInfo = UIView.GetAView().defaultAtlas[originalName];
         destAtlas.AddSprite(new UITextureAtlas.SpriteInfo
         {
             border = spriteInfo.border,
             name = newName,
             region = spriteInfo.region,
             texture = spriteInfo.texture
         });
     }
     catch (Exception e)
     {
         Debug.LogException(e);
     }
 }
Example #39
0
        public void LoadResources()
        {
            string[] spriteNames = {
                                           "TerrainLevel",
                                           "TerrainLevelDisabled",
                                           "TerrainLevelFocused",
                                           "TerrainLevelHovered",
                                           "TerrainLevelPressed",
                                           "TerrainShift",
                                           "TerrainShiftDisabled",
                                           "TerrainShiftFocused",
                                           "TerrainShiftHovered",
                                           "TerrainShiftPressed",
                                           "TerrainSlope",
                                           "TerrainSlopeDisabled",
                                           "TerrainSlopeFocused",
                                           "TerrainSlopeHovered",
                                           "TerrainSlopePressed",
                                           "TerrainSoften",
                                           "TerrainSoftenDisabled",
                                           "TerrainSoftenFocused",
                                           "TerrainSoftenHovered",
                                           "TerrainSoftenPressed",
                                           "ToolbarIconTerrain",
                                           "ToolbarIconTerrainDisabled",
                                           "ToolbarIconTerrainFocused",
                                           "ToolbarIconTerrainHovered",
                                           "ToolbarIconTerrainPressed",
                                           "ToolbarIconGroup6Focused",
                                           "ToolbarIconGroup6Hovered",
                                           "ToolbarIconGroup6Pressed",
                                           "ResourceSand",
                                           "ResourceSandDisabled",
                                           "ResourceSandFocused",
                                           "ResourceSandHovered",
                                           "ResourceSandPressed",
                                           "TerrainDitch",
                                           "TerrainDitchFocused",
                                           "TerrainDitchPressed",
                                       };

            terraform_atlas = CreateTextureAtlas("TerraformUI", UIView.GetAView().defaultAtlas.material, spriteNames, "TerraformTool.icon.");
        }
Example #40
0
        /**
         * Method sourced from SamsamTSs Airport Roads mod for Cities Skylines
         * Adds array of Texture2D objects to a UITextureAtlas
         * https://github.com/SamsamTS/CS-AirportRoads/blob/master/AirportRoads/AirportRoads.cs
         **/
        private static 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;

                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++) {
                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();
        }
Example #41
0
        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;
        }
Example #42
0
 private void SetDefaultSettingsForButton(UIButton button, UITextureAtlas atlas)
 {
     button.name = "ChangeRoadHeightButton";
     button.atlas = atlas;
     button.size = new Vector2(spriteWidth, spriteHeight);
     button.normalBgSprite = SpriteName.ButtonBackground.ToString();
     button.disabledBgSprite = SpriteName.ButtonBackground.ToString();
     button.hoveredBgSprite = SpriteName.ButtonBackgroundHovered.ToString();
     button.pressedBgSprite = SpriteName.ButtonBackgroundPressed.ToString();
     button.focusedBgSprite = SpriteName.ButtonBackgroundPressed.ToString();
     button.playAudioEvents = true;
 }
Example #43
0
        private void InitAtlases()
        {
            if (_atlas == null)
            {

                Debug.Log("[CSLMusicMod] Creating icon atlases ...");
                _atlas = TextureHelper.CreateAtlas("Icons.png", "CSLMusicModUI", UIView.Find<UITabstrip>("ToolMode").atlas.material, 31, 31, new string[]
                    {
                        "OptionBase",
                        "OptionBaseDisabled",
                        "OptionBaseFocused",
                        "OptionBaseHovered",
                        "OptionBasePressed",
                        "Music",
                        "Next",
                        "Previous",
                        "Shuffle",
                        "SortAscending",
                        "SortDescending",
                        "Search",
                        "Clear"
                    });

            }
        }
Example #44
0
        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();
        }
Example #45
0
 public SpriteNotFoundException(string spriteName, UITextureAtlas atlas)
 {
     _spriteNameInternal = spriteName;
     _atlasInternal = 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;
        }
 protected UIButton SpawnEntry(string name, string tooltip, string thumbnail, UITextureAtlas atlas, bool enabled, bool grouped)
 {
     if (atlas == null)
     {
         atlas = this.m_atlas;
     }
     if (string.IsNullOrEmpty(thumbnail) || atlas[thumbnail] == null)
     {
         thumbnail = "ThumbnailBuildingDefault";
     }
     return this.CreateButton(name, tooltip, name, -1, atlas, null, enabled, grouped);
 }
        protected UIButton CreateButton(string name, string tooltip, string baseIconName, int index, UITextureAtlas atlas, UIComponent tooltipBox, bool enabled, bool grouped)
        {
            UIButton btn;
            if (this.m_scrollablePanel.childCount > this.m_objectIndex)
            {
                btn = (this.m_scrollablePanel.components[this.m_objectIndex] as UIButton);
            }
            else
            {
                GameObject asGameObject = UITemplateManager.GetAsGameObject(RoadCustomizerPanel.kItemTemplate);
                btn = (this.m_scrollablePanel.AttachUIComponent(asGameObject) as UIButton);
                btn.eventClick += OnClick;
            }
            btn.gameObject.GetComponent<TutorialUITag>().tutorialTag = name;
            btn.text = string.Empty;
            btn.name = name;
            btn.tooltipAnchor = UITooltipAnchor.Anchored;
            btn.tabStrip = true;
            btn.horizontalAlignment = UIHorizontalAlignment.Center;
            btn.verticalAlignment = UIVerticalAlignment.Middle;
            btn.pivot = UIPivotPoint.TopCenter;
            if (atlas != null)
            {
                btn.atlas = atlas;
                switch (m_panelType)
                {
                    case Panel.VehicleRestrictions:
                        SetVehicleButtonsThumbnails(btn);
                        break;
                    case Panel.SpeedRestrictions:
                        UIUtils.SetThumbnails("SpeedSignBackground", sm_thumbnailCoords["SpeedSignBackground"], atlas, sm_speedThumbnailStates);
                        SetSpeedButtonsThumbnails(btn);
                        break;
                    default:
                        break;
                }

            }
            if (index != -1)
            {
                btn.zOrder = index;
            }
            btn.verticalAlignment = UIVerticalAlignment.Bottom;
            btn.foregroundSpriteMode = UIForegroundSpriteMode.Fill;

            UIComponent uIComponent = (btn.childCount <= 0) ? null : btn.components[0];
            if (uIComponent != null)
            {
                uIComponent.isVisible = false;
            }
            btn.isEnabled = enabled;
            btn.state = UIButton.ButtonState.Disabled;
            btn.tooltip = tooltip;
            btn.tooltipBox = tooltipBox;
            btn.group = grouped ? this.m_scrollablePanel : null;
            this.m_objectIndex++;
            return btn;
        }
        private void Init()
        {
            if (loaded) {
                Debug.Print("Already Loaded");
                return;
            }
            loaded = false;

            this.m_buttonAtlas = TextureLoader.CreateTextureAtlas("ToolbarIconSearchAtlas", spriteNames, "BuildingSearch.Source.Images.");

            //Debug.Print (typeof(SearchGroupPanel).Name);
            //Debug.Print (System.Type.GetType (typeof(ZoningPanel).Name));

            //DestroyOld(UISearchBox.NAME);
            //DestroyOld("UISearchButton");
            DestroyOld("SearchDefaultPanel");
            DestroyOld("SearchPanel");
            DestroyOld("Search");
            //DestroyOld("FindContainer");

            MainToolbar toolbar = ToolsModifierControl.mainToolbar;
            UITabstrip tabstrip = (UITabstrip)toolbar.component;
            UITabContainer tabcontainer = tabstrip.tabContainer;
            //return;
            UIButton button = this.SpawnSubEntry(toolbar, tabstrip, "Search", "MAIN_TOOL", "Unlock", "ToolbarIcon", true);
            button.atlas = m_buttonAtlas;
            button.normalFgSprite = "ToolbarIconSearch";
            button.focusedFgSprite = button.normalFgSprite + "Focused";
            button.hoveredFgSprite = button.normalFgSprite + "Hovered";
            button.pressedFgSprite = button.normalFgSprite + "Pressed";
            button.disabledFgSprite = button.normalFgSprite + "Disabled";
            Debug.Print("Successfully added button");
            var searchPanel = tabcontainer.Find<UIPanel>("SearchPanel").Find<UITabContainer>("GTSContainer").Find<UIPanel>("SearchDefaultPanel").GetComponent<SearchPanel>();
            Debug.Print(searchPanel, typeof(SearchPanel), searchPanel.Equals(typeof(SearchPanel)), searchPanel.Equals(typeof(GeneratedScrollPanel)));
            Debug.Print(typeof(SearchPanel) == Type.GetType("SearchPanel"));
            UISearchBox.CreateUISearch(searchPanel);

            //UISearchBox.CreateUISearch(searchPanel);
        }