public TextureInspectorTypeGUIProperties(TextureImporterInspector.TextureInspectorGUIElement _commonElements, TextureImporterInspector.TextureInspectorGUIElement _advancedElements, TextureImporterShape _shapeCaps)
 {
     this.commonElements = _commonElements;
     this.advancedElements = _advancedElements;
     this.shapeCaps = _shapeCaps;
 }
Beispiel #2
0
        protected override void ExportYAMLInner(IExportContainer container, YAMLMappingNode node)
        {
            base.ExportYAMLInner(container, node);

            SpriteMetaData[] sprites = new SpriteMetaData[m_sprites.Count];
            for (int i = 0; i < m_sprites.Count; i++)
            {
                sprites[i] = new SpriteMetaData(m_sprites[i]);
            }

            node.AddSerializedVersion(GetSerializedVersion(container.Version));

            YAMLMappingNode mipmap = new YAMLMappingNode();

            mipmap.Add("mipMapMode", (int)TextureImporterMipFilter.BoxFilter);
            mipmap.Add("enableMipMap", m_texture.MipCount > 1 ? true : false);
            mipmap.Add("sRGBTexture", m_texture.ColorSpace == ColorSpace.Gamma ? true : false);
            mipmap.Add("linearTexture", false);
            mipmap.Add("fadeOut", false);
            mipmap.Add("borderMipMap", false);
            mipmap.Add("mipMapsPreserveCoverage", false);
            mipmap.Add("alphaTestReferenceValue", 0.5f);
            mipmap.Add("mipMapFadeDistanceStart", 1);
            mipmap.Add("mipMapFadeDistanceEnd", 3);
            node.Add("mipmaps", mipmap);

            YAMLMappingNode bumpmap = new YAMLMappingNode();

            bumpmap.Add("convertToNormalMap", false);
            bumpmap.Add("externalNormalMap", false);
            bumpmap.Add("heightScale", 0.25f);
            bumpmap.Add("normalMapFilter", (int)TextureImporterNormalFilter.Standard);
            node.Add("bumpmap", bumpmap);

            node.Add("isReadable", m_texture.IsReadable);
            node.Add("grayScaleToAlpha", false);
            node.Add("generateCubemap", (int)TextureImporterGenerateCubemap.AutoCubemap);
            node.Add("cubemapConvolution", 0);
            node.Add("seamlessCubemap", false);
            node.Add("textureFormat", (int)m_texture.TextureFormat);

            int maxSize = m_texture.Width > m_texture.Height ? m_texture.Width : m_texture.Height;

            maxSize = maxSize > 2048 ? maxSize : 2048;
            node.Add("maxTextureSize", maxSize);

            TextureImportSettings importSettings = new TextureImportSettings(m_texture.TextureSettings);

            node.Add("textureSettings", importSettings.ExportYAML(container));

            node.Add("nPOTScale", (int)TextureImporterNPOTScale.None);
            node.Add("lightmap", false);
            node.Add("compressionQuality", 50);

            SpriteImportMode spriteMode;
            uint             extrude;
            SpriteMeshType   meshType;
            SpriteAlignment  alignment;
            Vector2f         pivot = new Vector2f(0.5f, 0.5f);
            Vector4f         border;
            float            pixelPerUnit;

            switch (m_sprites.Count)
            {
            case 0:
            {
                spriteMode   = SpriteImportMode.Single;
                extrude      = 1;
                meshType     = SpriteMeshType.Tight;
                alignment    = SpriteAlignment.Center;
                pivot        = new Vector2f(0.5f, 0.5f);
                border       = default;
                pixelPerUnit = 100.0f;
            }
            break;

            case 1:
            {
                Sprite sprite = m_sprites[0];
                if (sprite.Rect == sprite.RD.TextureRect)
                {
                    spriteMode = sprite.Name == m_texture.Name ? SpriteImportMode.Single : SpriteImportMode.Multiple;
                }
                else
                {
                    spriteMode = SpriteImportMode.Multiple;
                }
                extrude      = sprite.Extrude;
                meshType     = sprite.RD.MeshType;
                alignment    = SpriteAlignment.Custom;
                pivot        = sprite.Pivot;
                border       = sprite.Border;
                pixelPerUnit = sprite.PixelsToUnits;
            }
            break;

            default:
            {
                Sprite sprite = m_sprites[0];
                spriteMode   = SpriteImportMode.Multiple;
                extrude      = sprite.Extrude;
                meshType     = sprite.RD.MeshType;
                alignment    = SpriteAlignment.Center;
                pivot        = new Vector2f(0.5f, 0.5f);
                border       = default;
                pixelPerUnit = sprite.PixelsToUnits;
            }
            break;
            }
            node.Add("spriteMode", (int)spriteMode);
            node.Add("spriteExtrude", extrude);
            node.Add("spriteMeshType", (int)meshType);
            node.Add("alignment", (int)alignment);

            node.Add("spritePivot", pivot.ExportYAML(container));
            node.Add("spriteBorder", border.ExportYAML(container));
            node.Add("spritePixelsToUnits", pixelPerUnit);
            node.Add("alphaUsage", (int)TextureImporterAlphaSource.FromInput);
            node.Add("alphaIsTransparency", true);
            node.Add("spriteTessellationDetail", -1.0f);

            TextureImporterType type;

            if (m_texture.LightmapFormat.IsNormalmap())
            {
                type = TextureImporterType.NormalMap;
            }
            else
            {
                type = m_sprites.Count == 0 ? TextureImporterType.Default : TextureImporterType.Sprite;
            }
            node.Add("textureType", (int)type);

            TextureImporterShape shape = (m_texture is Cubemap) ? TextureImporterShape.TextureCube : TextureImporterShape.Texture2D;

            node.Add("textureShape", (int)shape);

            node.Add("maxTextureSizeSet", false);
            node.Add("compressionQualitySet", false);
            node.Add("textureFormatSet", false);

            TextureImporterPlatformSettings platform = new TextureImporterPlatformSettings(m_texture.TextureFormat.ToDefaultFormat());

            TextureImporterPlatformSettings[] platforms = new TextureImporterPlatformSettings[] { platform };
            node.Add("platformSettings", platforms.ExportYAML(container));

            SpriteSheetMetaData spriteSheet;

            if (spriteMode == SpriteImportMode.Single)
            {
                if (sprites.Length == 0)
                {
                    spriteSheet = new SpriteSheetMetaData(sprites);
                }
                else
                {
                    spriteSheet = new SpriteSheetMetaData(sprites[0]);
                }
            }
            else
            {
                spriteSheet = new SpriteSheetMetaData(sprites);
            }
            node.Add("spriteSheet", spriteSheet.ExportYAML(container));

            node.Add("spritePackingTag", string.Empty);
        }
        public override void DrawRuleGUI()
        {
            base.DrawRuleGUI();
            GUILayout.Space(10);

            EditorGUILayout.LabelField("Texture Rule Settings", EditorStyles.boldLabel);
            EditorGUI.DrawRect(EditorGUILayout.GetControlRect(false, 2), QuickEditorColors.DarkGrayX11);
            GUILayout.Space(3);

            int mTextureTypeIndex = Math.Max(Array.FindIndex(AssetImportStyles.Texture.TextureTypeOpts, opt => opt.text.Equals(textureType.ToString())), 0);

            mTextureTypeIndex = EditorGUILayout.Popup(AssetImportStyles.Texture.TextureType, mTextureTypeIndex, AssetImportStyles.Texture.TextureTypeOpts);
            textureType       = AssetImportStyles.Texture.TextureTypeEnumOpts[mTextureTypeIndex];

            bool disabled = (textureType == TextureImporterType.Default || textureType == TextureImporterType.NormalMap || textureType == TextureImporterType.SingleChannel) ? false : true;

            EditorGUI.BeginDisabledGroup(disabled);
            textureShape = (TextureImporterShape)EditorGUILayout.EnumPopup("Texture Shape", textureShape);
            EditorGUI.EndDisabledGroup();
            if (disabled)
            {
                textureShape = TextureImporterShape.Texture2D;
            }

            GUILayout.Space(5);

            advanceFoldout = EditorGUILayout.Foldout(advanceFoldout, AssetImportStyles.Texture.Advanced);

            if (advanceFoldout)
            {
                QuickGUILayout.IndentBlock(() =>
                {
                    npotScale     = (TextureImporterNPOTScale)EditorGUILayout.EnumPopup(AssetImportStyles.Texture.NonPowerof2, npotScale);
                    isReadable    = EditorGUILayout.Toggle(AssetImportStyles.Texture.ReadWriteEnable, isReadable);
                    mipmapEnabled = EditorGUILayout.Toggle(AssetImportStyles.Texture.GenMipMaps, mipmapEnabled);
                });
            }

            GUILayout.Space(5);

            wrapMode   = (TextureWrapMode)EditorGUILayout.EnumPopup(AssetImportStyles.Texture.WrapMode, wrapMode);
            filterMode = (FilterMode)EditorGUILayout.EnumPopup(AssetImportStyles.Texture.FilterMode, filterMode);
            anisoLevel = EditorGUILayout.IntSlider(AssetImportStyles.Texture.AnisoLevel, anisoLevel, 0, 16);

            GUILayout.Space(10);

            GUILayout.BeginHorizontal(EditorStyles.toolbar);

            QuickGUILayout.Toolbar(ref curPlatformIndex, mPlatformNames, EditorStyles.toolbarButton, GUILayout.ExpandWidth(true));
            GUILayout.Space(10);
            GUILayout.EndHorizontal();

            EditorGUILayout.BeginVertical("Box");

            if (curPlatformIndex == 0)
            {
                StandaloneTextureImporterSettings.overridden = EditorGUILayout.Toggle("Override for Standalone", StandaloneTextureImporterSettings.overridden);
            }
            else if (curPlatformIndex == 1)
            {
                AndroidTextureImporterSettings.overridden = EditorGUILayout.Toggle("Override for Android", AndroidTextureImporterSettings.overridden);
            }
            else if (curPlatformIndex == 2)
            {
                iOSTextureImporterSettings.overridden = EditorGUILayout.Toggle("Override for iOS", iOSTextureImporterSettings.overridden);
            }

            int num = Array.FindIndex(AssetImportStyles.Texture.MaxSizeOpts, content => content.text.Equals(maxTextureSize.ToString()));

            num            = Math.Max(num, 0);
            num            = EditorGUILayout.Popup(AssetImportStyles.Texture.MaxSize, num, AssetImportStyles.Texture.MaxSizeOpts);
            maxTextureSize = Convert.ToInt32(AssetImportStyles.Texture.MaxSizeOpts[num].text);

            if (curPlatformIndex == 0)
            {
                StandaloneTextureImporterSettings.resizeAlgorithm = (TextureResizeAlgorithm)EditorGUILayout.EnumPopup("Resize Algorithm", StandaloneTextureImporterSettings.resizeAlgorithm);
                StandaloneTextureImporterSettings.format          = (TextureImporterFormat)EditorGUILayout.EnumPopup("Format", StandaloneTextureImporterSettings.format);
            }
            else if (curPlatformIndex == 1)
            {
                AndroidTextureImporterSettings.resizeAlgorithm = (TextureResizeAlgorithm)EditorGUILayout.EnumPopup("Resize Algorithm", AndroidTextureImporterSettings.resizeAlgorithm);
                AndroidTextureImporterSettings.format          = (TextureImporterFormat)EditorGUILayout.EnumPopup("Format", AndroidTextureImporterSettings.format);
            }
            else if (curPlatformIndex == 2)
            {
                iOSTextureImporterSettings.resizeAlgorithm = (TextureResizeAlgorithm)EditorGUILayout.EnumPopup("Resize Algorithm", iOSTextureImporterSettings.resizeAlgorithm);
                iOSTextureImporterSettings.format          = (TextureImporterFormat)EditorGUILayout.EnumPopup("Format", iOSTextureImporterSettings.format);
            }

            EditorGUILayout.EndVertical();
        }
    void OnGUI()
    {
        Undo.RecordObject(this, "lb");

        scrollPos = EditorGUILayout.BeginScrollView(scrollPos,
                                                    false,
                                                    false,
                                                    GUILayout.Width(Screen.width),
                                                    GUILayout.Height(Screen.height));

        EditorGUILayout.Space(); EditorGUILayout.Space();
        EditorGUILayout.Space(); EditorGUILayout.Space();

        importerType = (TexImporterType)EditorGUILayout.EnumPopup("Importer Mode", importerType, GUILayout.Width(343));
        if (GUILayout.Button("Batch Import"))
        {
            if (importerType == TexImporterType.AllTextures)
            {
                var files = Directory.GetFiles("Assets", "*.*", SearchOption.AllDirectories)
                            .Where(s => s.EndsWith(".png") || s.EndsWith(".jpg") || s.EndsWith(".psd") || s.EndsWith(".gif") ||
                                   s.EndsWith(".iff") || s.EndsWith(".tga") || s.EndsWith(".tiff") || s.EndsWith(".bmp") ||
                                   s.EndsWith(".pict"));

                foreach (string s in files)
                {
                    TextureImporter tImporter = AssetImporter.GetAtPath(s) as TextureImporter;
                    tImporter.maxTextureSize = textureSize;

                    if (comprissonMode == TextureCompressionType.None)
                    {
                        tImporter.textureCompression = TextureImporterCompression.Uncompressed;
                    }
                    if (comprissonMode == TextureCompressionType.LowQuality)
                    {
                        tImporter.textureCompression = TextureImporterCompression.CompressedLQ;
                    }
                    if (comprissonMode == TextureCompressionType.HighQuality)
                    {
                        tImporter.textureCompression = TextureImporterCompression.CompressedHQ;
                    }

                    if (advancedMode)
                    {
                        tImporter.textureType         = textureType;
                        tImporter.textureShape        = textureShape;
                        tImporter.sRGBTexture         = textureRGB;
                        tImporter.alphaSource         = textureAlphaSource;
                        tImporter.alphaIsTransparency = AlphaIsTransparent;
                        tImporter.isReadable          = ReadWriteEnabled;
                        tImporter.mipmapEnabled       = GenerateMipMaps;
                        tImporter.wrapMode            = wrapMode;
                        tImporter.filterMode          = filterMode;
                        tImporter.anisoLevel          = AnisoLevel;
                    }

                    AssetDatabase.ImportAsset(s, ImportAssetOptions.ForceUpdate);
                }
            }

            if (importerType == TexImporterType.CustomPath)
            {
                if (CustomPath.Length > 0)
                {
                    foreach (string f in CustomPath)
                    {
                        var files = Directory.GetFiles(f, "*.*", SearchOption.AllDirectories)
                                    .Where(s => s.EndsWith(".png") || s.EndsWith(".jpg") || s.EndsWith(".psd") || s.EndsWith(".gif") ||
                                           s.EndsWith(".iff") || s.EndsWith(".tga") || s.EndsWith(".tiff") || s.EndsWith(".bmp") ||
                                           s.EndsWith(".pict"));

                        foreach (string ss in files)
                        {
                            TextureImporter tImporter = AssetImporter.GetAtPath(ss) as TextureImporter;
                            tImporter.maxTextureSize = textureSize;

                            if (comprissonMode == TextureCompressionType.None)
                            {
                                tImporter.textureCompression = TextureImporterCompression.Uncompressed;
                            }
                            if (comprissonMode == TextureCompressionType.LowQuality)
                            {
                                tImporter.textureCompression = TextureImporterCompression.CompressedLQ;
                            }
                            if (comprissonMode == TextureCompressionType.HighQuality)
                            {
                                tImporter.textureCompression = TextureImporterCompression.CompressedHQ;
                            }

                            if (advancedMode)
                            {
                                tImporter.textureType         = textureType;
                                tImporter.textureShape        = textureShape;
                                tImporter.sRGBTexture         = textureRGB;
                                tImporter.alphaSource         = textureAlphaSource;
                                tImporter.alphaIsTransparency = AlphaIsTransparent;
                                tImporter.isReadable          = ReadWriteEnabled;
                                tImporter.mipmapEnabled       = GenerateMipMaps;
                                tImporter.wrapMode            = wrapMode;
                                tImporter.filterMode          = filterMode;
                                tImporter.anisoLevel          = AnisoLevel;
                            }
                            AssetDatabase.ImportAsset(ss, ImportAssetOptions.ForceUpdate);
                        }
                    }
                }
            }


            if (importerType == TexImporterType.CustomTextures)
            {
                if (targets.Length > 0)
                {
                    foreach (Texture2D s in targets)
                    {
                        TextureImporter tImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(s)) as TextureImporter;
                        tImporter.maxTextureSize = textureSize;

                        if (comprissonMode == TextureCompressionType.None)
                        {
                            tImporter.textureCompression = TextureImporterCompression.Uncompressed;
                        }
                        if (comprissonMode == TextureCompressionType.LowQuality)
                        {
                            tImporter.textureCompression = TextureImporterCompression.CompressedLQ;
                        }
                        if (comprissonMode == TextureCompressionType.HighQuality)
                        {
                            tImporter.textureCompression = TextureImporterCompression.CompressedHQ;
                        }

                        if (advancedMode)
                        {
                            tImporter.textureType         = textureType;
                            tImporter.textureShape        = textureShape;
                            tImporter.sRGBTexture         = textureRGB;
                            tImporter.alphaSource         = textureAlphaSource;
                            tImporter.alphaIsTransparency = AlphaIsTransparent;
                            tImporter.isReadable          = ReadWriteEnabled;
                            tImporter.mipmapEnabled       = GenerateMipMaps;
                            tImporter.wrapMode            = wrapMode;
                            tImporter.filterMode          = filterMode;
                            tImporter.anisoLevel          = AnisoLevel;
                        }
                        AssetDatabase.ImportAsset(AssetDatabase.GetAssetPath(s), ImportAssetOptions.ForceUpdate);
                    }
                }
            }
        }

        EditorGUILayout.Space();
        EditorGUILayout.Space();

        if (importerType == TexImporterType.CustomTextures)
        {
            ScriptableObject   target          = this;
            SerializedObject   so              = new SerializedObject(target);
            SerializedProperty stringsProperty = so.FindProperty("targets");
            EditorGUILayout.PropertyField(stringsProperty, true); // True means show children
            so.ApplyModifiedProperties();                         // Remember to apply modified properties
        }

        if (importerType == TexImporterType.CustomPath)
        {
            ScriptableObject   target          = this;
            SerializedObject   so              = new SerializedObject(target);
            SerializedProperty stringsProperty = so.FindProperty("CustomPath");
            EditorGUILayout.PropertyField(stringsProperty, true); // True means show children
            so.ApplyModifiedProperties();                         // Remember to apply modified properties
        }

        textureSize = EditorGUILayout.IntField("Texture Size", textureSize, GUILayout.Width(343));
        EditorGUILayout.Space(); EditorGUILayout.Space();

        comprissonMode = (TextureCompressionType)EditorGUILayout.EnumPopup("Comprisson Mode", comprissonMode, GUILayout.Width(343));
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        advancedMode = EditorGUILayout.Toggle("Show Advanced Options", advancedMode);
        EditorGUILayout.Space();
        EditorGUILayout.Space();
        if (advancedMode)
        {
            EditorGUILayout.LabelField("Recommended non-advanced mode to avoid problems");

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            textureType        = (TextureImporterType)EditorGUILayout.EnumPopup("Texture Type", textureType, GUILayout.Width(343));
            textureShape       = (TextureImporterShape)EditorGUILayout.EnumPopup("Texture Shape", textureShape, GUILayout.Width(343));
            textureRGB         = EditorGUILayout.Toggle("sRGB Mode", textureRGB, GUILayout.Width(343));
            textureAlphaSource = (TextureImporterAlphaSource)EditorGUILayout.EnumPopup("Alpha Source", textureAlphaSource, GUILayout.Width(343));
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            AlphaIsTransparent = EditorGUILayout.Toggle("Alpha Is Transparent", AlphaIsTransparent, GUILayout.Width(343));
            ReadWriteEnabled   = EditorGUILayout.Toggle("Read Write Enabled", ReadWriteEnabled, GUILayout.Width(343));
            GenerateMipMaps    = EditorGUILayout.Toggle("Generate Mip Maps", GenerateMipMaps, GUILayout.Width(343));
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            wrapMode   = (TextureWrapMode)EditorGUILayout.EnumPopup("Wrap Mode", wrapMode, GUILayout.Width(343));
            filterMode = (FilterMode)EditorGUILayout.EnumPopup("Filter Mode", filterMode, GUILayout.Width(343));
            EditorGUILayout.Space();
            EditorGUILayout.Space();
            AnisoLevel = EditorGUILayout.IntField("Aniso Level", AnisoLevel, GUILayout.Width(343));
        }
        EditorGUILayout.EndScrollView();
    }
Beispiel #5
0
 private void DisplayTextureShape()
 {
     textureShape = (TextureImporterShape)EditorGUILayout.EnumPopup("Texture Shape", textureShape);
     DisplayCubeMapSettings();
 }