Example #1
0
        public void Select(int index)
        {
            try
            {
                if (currentData != null && currentData.asset != null && currentData.asset.prefab != null && !fixedFocusedTexture.Contains(currentData.asset.prefab))
                {
                    if (ImageUtils.FixFocusedTexture(currentData.asset.prefab))
                    {
                        // Debugging.Message("Fixed focused texture: " + currentData.asset.prefab.name);
                    }
                    fixedFocusedTexture.Add(currentData.asset.prefab);
                }

                component.normalFgSprite  = currentData.asset.prefab.m_Thumbnail + "Focused";
                component.hoveredFgSprite = currentData.asset.prefab.m_Thumbnail + "Focused";
            }
            catch (Exception e)
            {
                if (currentData != null)
                {
                    Debugging.Message("Select failed : " + currentData.name);
                }
                else
                {
                    Debugging.Message("Select failed");
                }
                Debugging.LogException(e);
            }
        }
Example #2
0
        public static bool FixFocusedTexture(PrefabInfo prefab)
        {
            if (prefab == null || prefab.m_Atlas == null || prefab.m_Thumbnail.IsNullOrWhiteSpace())
            {
                return(false);
            }

            UITextureAtlas.SpriteInfo sprite = prefab.m_Atlas[prefab.m_Thumbnail + "Focused"];
            if (sprite != null)
            {
                Color32[] pixels = sprite.texture.GetPixels32();

                int count = 0;

                foreach (Color32 pixel in pixels)
                {
                    if (pixel.a > 127 && (pixel.r + pixel.g + pixel.b) > 0)
                    {
                        Color.RGBToHSV(pixel, out float h, out float s, out float v);

                        if (h < 0.66f || h > 0.68f || s < 0.98f)
                        {
                            return(false);
                        }

                        if (++count > 32)
                        {
                            break;
                        }
                    }
                }

                if (count > 0)
                {
                    ImageUtils.FixFocusedTexture(prefab.m_Atlas[prefab.m_Thumbnail].texture, sprite.texture);
                    Color32[] colors = sprite.texture.GetPixels32();

                    prefab.m_Atlas.texture.SetPixels32((int)(sprite.region.x * prefab.m_Atlas.texture.width), (int)(sprite.region.y * prefab.m_Atlas.texture.height), sprite.texture.width, sprite.texture.height, colors);
                    prefab.m_Atlas.texture.Apply();

                    return(true);
                }
            }

            return(false);
        }