Exemple #1
0
        public override string GetInfoString()
        {
            Texture        t      = target as Texture;
            string         info   = t.width + "x" + t.height;
            GraphicsFormat format = GraphicsFormatUtility.GetFormat(t);

            info += "  " + GraphicsFormatUtility.GetFormatString(format);
            return(info);
        }
Exemple #2
0
 private static string[] BuildTextureStrings(int[] texFormatValues)
 {
     string[] retval = new string[texFormatValues.Length];
     for (int i = 0; i < texFormatValues.Length; i++)
     {
         int val = texFormatValues[i];
         retval[i] = (val < 0 ? "Automatic" : GraphicsFormatUtility.GetFormatString((TextureFormat)val));
     }
     return(retval);
 }
Exemple #3
0
        public override string GetInfoString()
        {
            if (m_PreviewTextures != null && m_PreviewPage < m_PreviewTextures.Length)
            {
                Texture2D      t      = m_PreviewTextures[m_PreviewPage];
                GraphicsFormat format = GraphicsFormatUtility.GetFormat(t);

                return(string.Format("{0}x{1} {2}\n{3}", t.width, t.height, GraphicsFormatUtility.GetFormatString(format), EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySizeLong(t))));
            }
            return("");
        }
 public override string GetInfoString() => $"{targetTexture.width}x{targetTexture.height} {GraphicsFormatUtility.GetFormatString(targetTexture.graphicsFormat)}";
        public override string GetInfoString()
        {
            // TextureInspector code is reused for RenderTexture and Cubemap inspectors.
            // Make sure we can handle the situation where target is just a Texture and
            // not a Texture2D.
            Texture         t  = target as Texture;
            Texture2D       t2 = target as Texture2D;
            TextureImporter textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(t)) as TextureImporter;
            string          info            = t.width + "x" + t.height;

            bool           showSize              = true;
            bool           isPackedSprite        = textureImporter && textureImporter.qualifiesForSpritePacking;
            bool           isNormalmap           = IsNormalMap(t);
            bool           stillNeedsCompression = TextureUtil.DoesTextureStillNeedToBeCompressed(AssetDatabase.GetAssetPath(t));
            bool           isNPOT = t2 != null && TextureUtil.IsNonPowerOfTwo(t2);
            GraphicsFormat format = t.graphicsFormat;

            showSize = !stillNeedsCompression;
            if (isNPOT)
            {
                info += " (NPOT)";
            }
            if (stillNeedsCompression)
            {
                info += " (Not yet compressed)";
            }
            else
            {
                if (isNormalmap)
                {
                    switch (format)
                    {
                    case GraphicsFormat.RGBA_DXT5_SRGB:
                    case GraphicsFormat.RGBA_DXT5_UNorm:
                        info += "  DXTnm";
                        break;

                    case GraphicsFormat.R8G8B8A8_SRGB:
                    case GraphicsFormat.R8G8B8A8_UNorm:
                    case GraphicsFormat.B8G8R8A8_SRGB:
                    case GraphicsFormat.B8G8R8A8_UNorm:
                        info += "  Nm 32 bit";
                        break;

                    case GraphicsFormat.R4G4B4A4_UNormPack16:
                    case GraphicsFormat.B4G4R4A4_UNormPack16:
                        info += "  Nm 16 bit";
                        break;

                    default:
                        info += "  " + GraphicsFormatUtility.GetFormatString(format);
                        break;
                    }
                }
                else if (isPackedSprite)
                {
                    TextureFormat desiredFormat;
                    ColorSpace    dummyColorSpace;
                    int           dummyComressionQuality;
                    textureImporter.ReadTextureImportInstructions(EditorUserBuildSettings.activeBuildTarget, out desiredFormat, out dummyColorSpace, out dummyComressionQuality);

                    info += "\n " + GraphicsFormatUtility.GetFormatString(format) + "(Original) " + TextureUtil.GetTextureFormatString(desiredFormat) + "(Atlas)";
                }
                else
                {
                    info += "  " + GraphicsFormatUtility.GetFormatString(format);
                }
            }

            if (showSize)
            {
                info += "\n" + EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySizeLong(t));
            }

            if (TextureUtil.GetUsageMode(t) == TextureUsageMode.AlwaysPadded)
            {
                var glWidth  = TextureUtil.GetGPUWidth(t);
                var glHeight = TextureUtil.GetGPUHeight(t);
                if (t.width != glWidth || t.height != glHeight)
                {
                    info += UnityString.Format("\nPadded to {0}x{1}", glWidth, glHeight);
                }
            }
            else if (TextureUtil.GetUsageMode(t) == TextureUsageMode.BakedLightmapRGBM ||
                     TextureUtil.GetUsageMode(t) == TextureUsageMode.RealtimeLightmapRGBM ||
                     TextureUtil.GetUsageMode(t) == TextureUsageMode.RGBMEncoded)
            {
                info += "\nRGBM encoded";
            }
            else if (TextureUtil.GetUsageMode(t) == TextureUsageMode.DoubleLDR ||
                     TextureUtil.GetUsageMode(t) == TextureUsageMode.BakedLightmapDoubleLDR)
            {
                info += "\ndLDR encoded";
            }

            return(info);
        }
 public override string GetInfoString() => $"{cubemap.width}x{cubemap.height} {GraphicsFormatUtility.GetFormatString(cubemap.graphicsFormat)}";
Exemple #7
0
        public virtual void ShowImportSettings(BaseTextureImportPlatformSettings editor)
        {
            // Max texture size
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = editor.model.maxTextureSizeIsDifferent;
            int maxTextureSize = EditorGUILayout.IntPopup(maxSize.text, editor.model.platformTextureSettings.maxTextureSize, kMaxTextureSizeStrings, kMaxTextureSizeValues);

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                editor.model.SetMaxTextureSizeForAll(maxTextureSize);
            }

            // Show a note if max size is overriden globally by the user
            var userMaxSizeOverride = EditorUserBuildSettings.overrideMaxTextureSize;

            if (userMaxSizeOverride > 0 && userMaxSizeOverride < maxTextureSize)
            {
                EditorGUILayout.HelpBox(string.Format(kMaxSizeOverrideString, userMaxSizeOverride), MessageType.Info);
            }

            // Resize Algorithm
            EditorGUI.BeginChangeCheck();
            EditorGUI.showMixedValue = editor.model.resizeAlgorithmIsDifferent;
            int resizeAlgorithmVal = EditorGUILayout.IntPopup(kResizeAlgorithm.text, (int)editor.model.platformTextureSettings.resizeAlgorithm, kResizeAlgorithmStrings, kResizeAlgorithmValues);

            EditorGUI.showMixedValue = false;
            if (EditorGUI.EndChangeCheck())
            {
                editor.model.SetResizeAlgorithmForAll((TextureResizeAlgorithm)resizeAlgorithmVal);
            }

            // Texture format
            int[]    formatValuesForAll        = {};
            string[] formatStringsForAll       = {};
            bool     formatOptionsAreDifferent = false;

            int formatForAll = 0;
            var textureShape = TextureImporterShape.Texture2D;

            // TODO : This should not be calculated every refresh and be kept in a cache somewhere instead...
            for (int i = 0; i < editor.GetTargetCount(); i++)
            {
                TextureImporterSettings settings           = editor.GetImporterSettings(i);
                TextureImporterType     textureTypeForThis = editor.textureTypeHasMultipleDifferentValues ? settings.textureType : editor.textureType;
                int format = (int)editor.model.platformTextureSettings.format;

                int[]    formatValues  = null;
                string[] formatStrings = null;

                if (!editor.model.isDefault && !editor.model.platformTextureSettings.overridden)
                {
                    // If not overriden, show what the auto format is going to be
                    // don't care about alpha in normal maps. If editor.assetTarget is null
                    // then we are dealing with texture preset and we show all options.
                    var showSettingsForPreset = editor.ShowPresetSettings();
                    var sourceHasAlpha        = showSettingsForPreset || (editor.DoesSourceTextureHaveAlpha(i) &&
                                                                          textureTypeForThis != TextureImporterType.NormalMap);

                    format = (int)TextureImporter.DefaultFormatFromTextureParameters(settings,
                                                                                     editor.model.platformTextureSettings,
                                                                                     !showSettingsForPreset && sourceHasAlpha,
                                                                                     !showSettingsForPreset && editor.IsSourceTextureHDR(i),
                                                                                     editor.model.buildTarget);

                    formatValues  = new int[] { format };
                    formatStrings = new string[] { GraphicsFormatUtility.GetFormatString((TextureFormat)format) };
                }
                else
                {
                    // otherwise show valid formats
                    editor.model.GetValidTextureFormatsAndStrings(textureTypeForThis, out formatValues, out formatStrings);
                }

                // Check if values are the same
                if (i == 0)
                {
                    formatValuesForAll  = formatValues;
                    formatStringsForAll = formatStrings;
                    formatForAll        = format;
                    textureShape        = settings.textureShape;
                }
                else
                {
                    if (!formatValues.SequenceEqual(formatValuesForAll) || !formatStrings.SequenceEqual(formatStringsForAll))
                    {
                        formatOptionsAreDifferent = true;
                        break;
                    }
                }
            }

            using (new EditorGUI.DisabledScope(formatOptionsAreDifferent || formatStringsForAll.Length == 1))
            {
                EditorGUI.BeginChangeCheck();
                bool mixedValues = formatOptionsAreDifferent || editor.model.textureFormatIsDifferent;
                EditorGUI.showMixedValue = mixedValues;
                var selectionResult = EditorGUILayout.IntPopup(kTextureFormat, formatForAll, EditorGUIUtility.TempContent(formatStringsForAll), formatValuesForAll);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    editor.model.SetTextureFormatForAll((TextureImporterFormat)selectionResult);
                    formatForAll = selectionResult;
                }

                if (!mixedValues && !Array.Exists(formatValuesForAll, i => i == formatForAll))
                {
                    EditorGUILayout.HelpBox(string.Format(L10n.Tr("The selected format value {0} is not compatible on this platform for the selected texture type, please change it to a valid one from the dropdown."), (TextureImporterFormat)formatForAll), MessageType.Error);
                }
            }

            // Texture Compression
            if (editor.model.isDefault && editor.model.platformTextureSettings.format == TextureImporterFormat.Automatic)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = editor.model.overriddenIsDifferent ||
                                           editor.model.textureCompressionIsDifferent;
                TextureImporterCompression textureCompression =
                    (TextureImporterCompression)EditorGUILayout.IntPopup(kTextureCompression,
                                                                         (int)editor.model.platformTextureSettings.textureCompression, kTextureCompressionOptions,
                                                                         kTextureCompressionValues);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    editor.model.SetTextureCompressionForAll(textureCompression);
                }
            }

            // Use Crunch Compression
            if (editor.model.isDefault &&
                (TextureImporterFormat)formatForAll == TextureImporterFormat.Automatic &&
                editor.model.platformTextureSettings.textureCompression != TextureImporterCompression.Uncompressed &&
                (textureShape == TextureImporterShape.Texture2D || textureShape == TextureImporterShape.TextureCube)) // 2DArray & 3D don't support Crunch
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = editor.model.overriddenIsDifferent ||
                                           editor.model.crunchedCompressionIsDifferent;
                bool crunchedCompression = EditorGUILayout.Toggle(
                    kCrunchedCompression, editor.model.platformTextureSettings.crunchedCompression);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    editor.model.SetCrunchedCompressionForAll(crunchedCompression);
                }
            }

            // compression quality
            bool isCrunchedFormat = false ||
                                    GraphicsFormatUtility.IsCrunchFormat((TextureFormat)formatForAll)
            ;

            if (
                (editor.model.isDefault &&
                 (TextureImporterFormat)formatForAll == TextureImporterFormat.Automatic &&
                 editor.model.platformTextureSettings.textureCompression != TextureImporterCompression.Uncompressed &&
                 editor.model.platformTextureSettings.crunchedCompression) ||
                (editor.model.isDefault && editor.model.platformTextureSettings.crunchedCompression && isCrunchedFormat) ||
                (!editor.model.isDefault && isCrunchedFormat) ||
                (!editor.model.textureFormatIsDifferent && ArrayUtility.Contains <TextureImporterFormat>(
                     TextureImporterInspector.kFormatsWithCompressionSettings,
                     (TextureImporterFormat)formatForAll)))
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = editor.model.overriddenIsDifferent ||
                                           editor.model.compressionQualityIsDifferent;

                // Prior to exposing compression quality for BC6H/BC7 formats they were always compressed at maximum quality even though the setting was
                // defaulted to 'Normal'.  Now BC6H/BC7 quality is exposed to the user as Fast/Normal/Best 'Normal' maps to one setting down from maximum in the
                // ISPC compressor but to maintain the behaviour of existing projects we need to force their quality up to 'Best'.  The 'forceMaximumCompressionQuality_BC6H_BC7'
                // flag is set when loading existing texture platform settings to do this and cleared when the compression quality level is manually set (by UI or API)
                bool forceBestQuality   = editor.model.forceMaximumCompressionQuality_BC6H_BC7 && (((TextureImporterFormat)formatForAll == TextureImporterFormat.BC6H) || ((TextureImporterFormat)formatForAll == TextureImporterFormat.BC7));
                int  compressionQuality = forceBestQuality ? (int)TextureCompressionQuality.Best : editor.model.platformTextureSettings.compressionQuality;

                compressionQuality       = EditCompressionQuality(editor.model.buildTarget, compressionQuality, isCrunchedFormat, (TextureImporterFormat)formatForAll);
                EditorGUI.showMixedValue = false;
                if (EditorGUI.EndChangeCheck())
                {
                    editor.model.SetCompressionQualityForAll(compressionQuality);
                    //SyncPlatformSettings ();
                }
            }

            // show the ETC1 split option only for sprites on platforms supporting ETC and only when there is an alpha channel
            bool isETCPlatform       = TextureImporter.IsETC1SupportedByBuildTarget(BuildPipeline.GetBuildTargetByName(editor.model.platformTextureSettings.name));
            bool isDealingWithSprite = (editor.spriteImportMode != SpriteImportMode.None);
            bool isETCFormatSelected = TextureImporter.IsTextureFormatETC1Compression((TextureFormat)formatForAll);

            if (isETCPlatform && isDealingWithSprite && isETCFormatSelected)
            {
                EditorGUI.BeginChangeCheck();
                EditorGUI.showMixedValue = editor.model.overriddenIsDifferent || editor.model.allowsAlphaSplitIsDifferent;
                bool allowsAlphaSplit = EditorGUILayout.Toggle(kUseAlphaSplitLabel, editor.model.platformTextureSettings.allowsAlphaSplitting);
                if (EditorGUI.EndChangeCheck())
                {
                    editor.model.SetAllowsAlphaSplitForAll(allowsAlphaSplit);
                }
            }
        }
        public override string GetInfoString()
        {
            var tex  = (Texture2DArray)target;
            var info = $"{tex.width}x{tex.height} {tex.depth} slice{(tex.depth != 1 ? "s" : "")} {GraphicsFormatUtility.GetFormatString(tex.format)} {EditorUtility.FormatBytes(TextureUtil.GetRuntimeMemorySizeLong(tex))}";

            return(info);
        }