예제 #1
0
        /// <summary>
        /// Prepare the style subwindow
        /// </summary>
        /// <param name="editStyle">If not null set in edit mode</param>
        public NewFolderStyleInspector(StyleGrid.StyleElement editStyle, bool isVarient)
        {
            this.editStyle  = editStyle;
            iconsUi         = new IconGrid(ResourceUtil.StyleIconsPath, 36, 12);
            styleProperties = new StyleProperties();

            if (editStyle != null)
            {
                nameEdited = true;
                styleName  = editStyle.Name;
                styleColor = editStyle.MainColor;

                selectedIcon = iconsUi.GetIconForId(editStyle.IconId);
                if (selectedIcon != null)
                {
                    folderOriginalIcon48 = selectedIcon.VeryHighResTex;
                    folderOriginalIcon24 = selectedIcon.HighResTex;
                    folderOriginalIcon10 = selectedIcon.LowResTex;
                    initIconsTexture     = true;
                }

                ReadGradientInfo();

                if (isVarient)
                {
                    this.editStyle = null;
                }
            }
            else
            {
                styleColor = Color.HSVToRGB(Random.value, 0.85F, 0.75F);
                styleName  = "New Style";
            }
        }
예제 #2
0
        // Quick & (really) dirty converter
        public static void ConvertStyles()
        {
            StyleGrid sg      = new StyleGrid(ResourceUtil.CustomStylesPath, 64.0F + 16.0F, 8.0F);
            IconGrid  iconsUi = new IconGrid(ResourceUtil.StyleIconsPath, 36, 12);

            foreach (ButtonGrid.GridElement ge in sg.elementList)
            {
                StyleGrid.StyleElement style = (StyleGrid.StyleElement)ge;
                NewFolderStyleInspector.StyleProperties styleProperties = new NewFolderStyleInspector.StyleProperties();
                IconGrid.IconElement selectedIcon = iconsUi.GetIconForId(style.IconId);
                string styleName  = style.Name;
                Color  styleColor = style.MainColor;

                string lastJsonPath = null;
                string newPath      = ResourceUtil.CustomStylesPath + "/" + ColorUtils.ColorToInt(styleColor) + ";" + GetIconId(selectedIcon) + ";" + styleName + "_prop.json";
                if (File.Exists(newPath))
                {
                    StreamReader reader = new StreamReader(newPath);
                    string       json   = reader.ReadToEnd();
                    reader.Close();

                    styleProperties = JsonUtility.FromJson <NewFolderStyleInspector.StyleProperties>(json);

                    lastJsonPath = newPath;
                }

                Texture2D folderOriginalTexture64;
                Texture2D folderOriginalTexture16;
                if (PreferencesUI.settings.useNewUI)
                {
                    folderOriginalTexture64 = (Texture2D)AssetDatabase.LoadMainAssetAtPath(ResourceUtil.TexturesPath + "/folder_icon_new.png");
                    folderOriginalTexture16 = (Texture2D)AssetDatabase.LoadMainAssetAtPath(ResourceUtil.TexturesPath + "/folder_icon_new_16.png");
                }
                else
                {
                    folderOriginalTexture64 = (Texture2D)AssetDatabase.LoadMainAssetAtPath(ResourceUtil.TexturesPath + "/folder_icon_64.png");
                    folderOriginalTexture16 = (Texture2D)AssetDatabase.LoadMainAssetAtPath(ResourceUtil.TexturesPath + "/folder_icon_16.png");
                }

                Texture2D folderTexture64;
                Texture2D folderTexture16;
                folderTexture64 = new Texture2D(folderOriginalTexture64.width, folderOriginalTexture64.height, folderOriginalTexture64.format, false);
                Graphics.CopyTexture(folderOriginalTexture64, 0, 0, folderTexture64, 0, 0);

                folderTexture16 = new Texture2D(folderOriginalTexture16.width, folderOriginalTexture16.height, folderOriginalTexture16.format, false);
                Graphics.CopyTexture(folderOriginalTexture16, 0, 0, folderTexture16, 0, 0);

                Texture2D folderIcon48         = null;
                Texture2D folderOriginalIcon48 = null;
                Texture2D folderIcon24         = null;
                Texture2D folderOriginalIcon24 = null;
                Texture2D folderIcon10         = null;
                Texture2D folderOriginalIcon10 = null;

                if (selectedIcon != null)
                {
                    // Very High res icon
                    folderIcon48 = new Texture2D(selectedIcon.VeryHighResTex.width, selectedIcon.VeryHighResTex.height, TextureFormat.RGBA32, true);
                    Graphics.CopyTexture(selectedIcon.VeryHighResTex, 0, 0, folderIcon48, 0, 0);
                    folderOriginalIcon48 = selectedIcon.VeryHighResTex;

                    // High res icon
                    folderIcon24 = new Texture2D(selectedIcon.HighResTex.width, selectedIcon.HighResTex.height, TextureFormat.RGBA32, true);
                    Graphics.CopyTexture(selectedIcon.HighResTex, 0, 0, folderIcon24, 0, 0);
                    folderOriginalIcon24 = selectedIcon.HighResTex;

                    // Low res icon
                    folderIcon10 = new Texture2D(selectedIcon.LowResTex.width, selectedIcon.LowResTex.height, TextureFormat.RGBA32, true);
                    Graphics.CopyTexture(selectedIcon.LowResTex, 0, 0, folderIcon10, 0, 0);
                    folderOriginalIcon10 = selectedIcon.LowResTex;
                }

                int        xOffset   = Mathf.Clamp(styleProperties.iconOffset.x, -32, 8);
                int        yOffset   = Mathf.Clamp(styleProperties.iconOffset.y, -26, 14);
                Vector2Int bigOffset = new Vector2Int(xOffset, yOffset);

                xOffset = Mathf.Clamp(styleProperties.iconOffset.x / 4, -6, 0);
                yOffset = Mathf.Clamp(styleProperties.iconOffset.y / 4, -6, 0);
                Vector2Int smallOffset = new Vector2Int(xOffset, yOffset);

                if (PreferencesUI.settings.useNewUI)
                {
                    UpdateTextureColor(styleProperties, styleColor, folderOriginalTexture64, folderTexture64, -7, 2, 96, 80, 16, 24, 2.0F);
                    UpdateTextureColor(styleProperties, styleColor, folderOriginalTexture16, folderTexture16, 1, 3, 15, 13, 2, 3, 0.25F);

                    UpdateTextureColor(styleProperties, styleColor, folderOriginalIcon24, folderIcon24, 32 + bigOffset.x - 3, 14 - bigOffset.y + 1, 48, 40, 8, 16, 1.0F);
                    UpdateTextureColor(styleProperties, styleColor, folderOriginalIcon10, folderIcon10, 6 + smallOffset.x + 1, -smallOffset.y + 3, 15, 13, 2, 3, 0.25F);
                }
                else
                {
                    UpdateTextureColor(styleProperties, styleColor, folderOriginalTexture64, folderTexture64, 3, 7, 56, 50, 3, 10, 1.0F);
                    UpdateTextureColor(styleProperties, styleColor, folderOriginalTexture16, folderTexture16, 2, 3, 15, 13, 0, 1, 0.25F);


                    UpdateTextureColor(styleProperties, styleColor, folderOriginalIcon24, folderIcon24, 32 + bigOffset.x + 3, 14 - bigOffset.y + 6, 56, 50, 4, 10, 1.0F);
                    UpdateTextureColor(styleProperties, styleColor, folderOriginalIcon10, folderIcon10, 6 + smallOffset.x + 2, -smallOffset.y + 3, 15, 13, 0, 1, 0.25F);
                }

                Texture2D finalHigh;
                if (PreferencesUI.settings.useNewUI)
                {
                    UpdateTextureColor(styleProperties, styleColor, folderOriginalIcon48, folderIcon48, (32 + bigOffset.x - 3) * 2, (14 - bigOffset.y + 1) * 2, 96, 80, 16, 24, 2.0F);
                    finalHigh = BakeFinalTexture(folderTexture64, folderIcon48, (32 + bigOffset.x) * 2, (14 - bigOffset.y) * 2);
                }
                else
                {
                    finalHigh = BakeFinalTexture(folderTexture64, folderIcon24, 32 + bigOffset.x, 14 - bigOffset.y);
                }

                Texture2D finalLow = BakeFinalTexture(folderTexture16, folderIcon10, 6 + smallOffset.x, -smallOffset.y);
                EditStyle(styleName, styleColor, style, selectedIcon, finalHigh, true, "64");
                EditStyle(styleName, styleColor, style, selectedIcon, finalLow, false, "16");

                // Delete previous json info if existing
                if (lastJsonPath != null)
                {
                    AssetDatabase.DeleteAsset(lastJsonPath);
                }

                if (!(styleProperties.iconOffset == Vector2Int.zero && styleProperties.colorType == NewFolderStyleInspector.ColorType.SolidColor))
                {
                    int iconId = 0;
                    if (selectedIcon != null)
                    {
                        iconId = selectedIcon.Id;
                    }

                    StreamWriter writer = new StreamWriter(lastJsonPath, false);
                    writer.Write(JsonUtility.ToJson(styleProperties));
                    writer.Close();
                }
            }

            AssetDatabase.Refresh(ImportAssetOptions.ForceUpdate);
        }