GetUsageMode() private method

private GetUsageMode ( Texture t ) : TextureUsageMode
t UnityEngine.Texture
return TextureUsageMode
 public void OnPreviewSettings(UnityEngine.Object[] targets)
 {
     if (ShaderUtil.hardwareSupportsRectRenderTexture)
     {
         GUI.enabled = true;
         this.InitPreview();
         bool flag  = true;
         bool flag2 = true;
         bool flag3 = false;
         int  a     = 8;
         foreach (Texture texture in targets)
         {
             a = Mathf.Max(a, TextureUtil.GetMipmapCount(texture));
             Cubemap cubemap = texture as Cubemap;
             if (cubemap != null)
             {
                 TextureFormat format = cubemap.format;
                 if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                 {
                     flag2 = false;
                 }
                 if (TextureUtil.HasAlphaTextureFormat(format) && (TextureUtil.GetUsageMode(texture) == TextureUsageMode.Default))
                 {
                     flag3 = true;
                 }
             }
             else
             {
                 flag3 = true;
                 flag2 = false;
             }
         }
         if (flag2)
         {
             this.m_PreviewType = PreviewType.Alpha;
             flag = false;
         }
         else if (!flag3)
         {
             this.m_PreviewType = PreviewType.RGB;
             flag = false;
         }
         if (flag)
         {
             GUIContent[] contentArray = new GUIContent[] { Styles.RGBIcon, Styles.alphaIcon };
             int          previewType  = (int)this.m_PreviewType;
             if (GUILayout.Button(contentArray[previewType], Styles.preButton, new GUILayoutOption[0]))
             {
                 this.m_PreviewType = (PreviewType)(++previewType % contentArray.Length);
             }
         }
         GUI.enabled = a != 1;
         GUILayout.Box(Styles.smallZoom, Styles.preLabel, new GUILayoutOption[0]);
         GUI.changed = false;
         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth(64f) };
         this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(a - 1), 0f, Styles.preSlider, Styles.preSliderThumb, options));
         GUILayout.Box(Styles.largeZoom, Styles.preLabel, new GUILayoutOption[0]);
         GUI.enabled = true;
     }
 }
        public static bool IsNormalMap(Texture t)
        {
            TextureUsageMode usageMode = TextureUtil.GetUsageMode(t);

            if (usageMode != TextureUsageMode.NormalmapPlain)
            {
                return(usageMode == TextureUsageMode.NormalmapDXT5nm);
            }
            return(true);
        }
示例#3
0
        public override string GetInfoString()
        {
            Texture         texture         = base.target as Texture;
            Texture2D       texture2D       = base.target as Texture2D;
            TextureImporter textureImporter = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(texture)) as TextureImporter;
            string          text            = texture.width.ToString() + "x" + texture.height.ToString();

            if (QualitySettings.desiredColorSpace == ColorSpace.Linear)
            {
                text = text + " " + TextureUtil.GetTextureColorSpaceString(texture);
            }
            bool          flag          = textureImporter && textureImporter.qualifiesForSpritePacking;
            bool          flag2         = TextureInspector.IsNormalMap(texture);
            bool          flag3         = TextureUtil.DoesTextureStillNeedToBeCompressed(AssetDatabase.GetAssetPath(texture));
            bool          flag4         = texture2D != null && TextureUtil.IsNonPowerOfTwo(texture2D);
            TextureFormat textureFormat = TextureUtil.GetTextureFormat(texture);
            bool          flag5         = !flag3;

            if (flag4)
            {
                text += " (NPOT)";
            }
            if (flag3)
            {
                text += " (Not yet compressed)";
            }
            else if (flag2)
            {
                switch (textureFormat)
                {
                case TextureFormat.ARGB4444:
                    text += "  Nm 16 bit";
                    goto IL_176;

                case TextureFormat.RGB24:
IL_11D:
                    if (textureFormat != TextureFormat.DXT5)
                    {
                        text = text + "  " + TextureUtil.GetTextureFormatString(textureFormat);
                        goto IL_176;
                    }
                    text += "  DXTnm";
                    goto IL_176;

                case TextureFormat.RGBA32:
                case TextureFormat.ARGB32:
                    text += "  Nm 32 bit";
                    goto IL_176;
                }
                goto IL_11D;
                IL_176 :;
            }
            else if (flag)
            {
                TextureFormat format;
                ColorSpace    colorSpace;
                int           num;
                textureImporter.ReadTextureImportInstructions(EditorUserBuildSettings.activeBuildTarget, out format, out colorSpace, out num);
                string text2 = text;
                text = string.Concat(new string[]
                {
                    text2,
                    "\n ",
                    TextureUtil.GetTextureFormatString(textureFormat),
                    "(Original) ",
                    TextureUtil.GetTextureFormatString(format),
                    "(Atlas)"
                });
            }
            else
            {
                text = text + "  " + TextureUtil.GetTextureFormatString(textureFormat);
            }
            if (flag5)
            {
                text = text + "\n" + EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySizeLong(texture));
            }
            if (TextureUtil.GetUsageMode(texture) == TextureUsageMode.AlwaysPadded)
            {
                int gPUWidth  = TextureUtil.GetGPUWidth(texture);
                int gPUHeight = TextureUtil.GetGPUHeight(texture);
                if (texture.width != gPUWidth || texture.height != gPUHeight)
                {
                    text += string.Format("\nPadded to {0}x{1}", gPUWidth, gPUHeight);
                }
            }
            return(text);
        }
示例#4
0
 public override void OnPreviewSettings()
 {
     if (this.IsCubemap())
     {
         this.m_CubemapPreview.OnPreviewSettings(base.targets);
     }
     else
     {
         if (TextureInspector.s_Styles == null)
         {
             TextureInspector.s_Styles = new TextureInspector.Styles();
         }
         Texture texture = base.target as Texture;
         bool    flag    = true;
         bool    flag2   = false;
         bool    flag3   = true;
         int     num     = 1;
         if (base.target is Texture2D || base.target is ProceduralTexture)
         {
             flag2 = true;
             flag3 = false;
         }
         UnityEngine.Object[] targets = base.targets;
         for (int i = 0; i < targets.Length; i++)
         {
             Texture texture2 = (Texture)targets[i];
             if (!(texture2 == null))
             {
                 TextureFormat format = (TextureFormat)0;
                 bool          flag4  = false;
                 if (texture2 is Texture2D)
                 {
                     format = (texture2 as Texture2D).format;
                     flag4  = true;
                 }
                 else if (texture2 is ProceduralTexture)
                 {
                     format = (texture2 as ProceduralTexture).format;
                     flag4  = true;
                 }
                 if (flag4)
                 {
                     if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                     {
                         flag2 = false;
                     }
                     if (TextureUtil.HasAlphaTextureFormat(format))
                     {
                         if (TextureUtil.GetUsageMode(texture2) == TextureUsageMode.Default)
                         {
                             flag3 = true;
                         }
                     }
                 }
                 num = Mathf.Max(num, TextureUtil.GetMipmapCount(texture2));
             }
         }
         if (flag2)
         {
             this.m_ShowAlpha = true;
             flag             = false;
         }
         else if (!flag3)
         {
             this.m_ShowAlpha = false;
             flag             = false;
         }
         if (flag && texture != null && !TextureInspector.IsNormalMap(texture))
         {
             this.m_ShowAlpha = GUILayout.Toggle(this.m_ShowAlpha, (!this.m_ShowAlpha) ? TextureInspector.s_Styles.RGBIcon : TextureInspector.s_Styles.alphaIcon, TextureInspector.s_Styles.previewButton, new GUILayoutOption[0]);
         }
         GUI.enabled = (num != 1);
         GUILayout.Box(TextureInspector.s_Styles.smallZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.changed     = false;
         this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(num - 1), 0f, TextureInspector.s_Styles.previewSlider, TextureInspector.s_Styles.previewSliderThumb, new GUILayoutOption[]
         {
             GUILayout.MaxWidth(64f)
         }));
         GUILayout.Box(TextureInspector.s_Styles.largeZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.enabled = true;
     }
 }
        public override string GetInfoString()
        {
            Texture         target = base.target as Texture;
            Texture2D       t      = base.target as Texture2D;
            TextureImporter atPath = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(target)) as TextureImporter;
            string          str    = target.width.ToString() + "x" + target.height.ToString();

            if (QualitySettings.desiredColorSpace == ColorSpace.Linear)
            {
                str = str + " " + TextureUtil.GetTextureColorSpaceString(target);
            }
            bool          flag          = true;
            bool          flag2         = (atPath != null) && atPath.qualifiesForSpritePacking;
            bool          flag3         = IsNormalMap(target);
            bool          flag4         = TextureUtil.DoesTextureStillNeedToBeCompressed(AssetDatabase.GetAssetPath(target));
            bool          flag5         = (t != null) && TextureUtil.IsNonPowerOfTwo(t);
            TextureFormat textureFormat = TextureUtil.GetTextureFormat(target);

            flag = !flag4;
            if (flag5)
            {
                str = str + " (NPOT)";
            }
            if (flag4)
            {
                str = str + " (Not yet compressed)";
            }
            else if (!flag3)
            {
                if (flag2)
                {
                    TextureFormat format2;
                    ColorSpace    space;
                    int           num3;
                    atPath.ReadTextureImportInstructions(EditorUserBuildSettings.activeBuildTarget, out format2, out space, out num3);
                    string   str2       = str;
                    string[] textArray1 = new string[] { str2, "\n ", TextureUtil.GetTextureFormatString(textureFormat), "(Original) ", TextureUtil.GetTextureFormatString(format2), "(Atlas)" };
                    str = string.Concat(textArray1);
                }
                else
                {
                    str = str + "  " + TextureUtil.GetTextureFormatString(textureFormat);
                }
            }
            else
            {
                switch (textureFormat)
                {
                case TextureFormat.ARGB4444:
                    str = str + "  Nm 16 bit";
                    goto Label_01EF;

                case TextureFormat.RGBA32:
                case TextureFormat.ARGB32:
                    str = str + "  Nm 32 bit";
                    goto Label_01EF;
                }
                if (textureFormat == TextureFormat.DXT5)
                {
                    str = str + "  DXTnm";
                }
                else
                {
                    str = str + "  " + TextureUtil.GetTextureFormatString(textureFormat);
                }
            }
Label_01EF:
            if (flag)
            {
                str = str + "\n" + EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySize(target));
            }
            if (TextureUtil.GetUsageMode(target) != TextureUsageMode.AlwaysPadded)
            {
                return(str);
            }
            int gPUWidth  = TextureUtil.GetGPUWidth(target);
            int gPUHeight = TextureUtil.GetGPUHeight(target);

            if ((target.width == gPUWidth) && (target.height == gPUHeight))
            {
                return(str);
            }
            return(str + $"
Padded to {gPUWidth}x{gPUHeight}");
        }
 public override void OnPreviewSettings()
 {
     if (this.IsCubemap())
     {
         this.m_CubemapPreview.OnPreviewSettings(base.targets);
     }
     else
     {
         if (s_Styles == null)
         {
             s_Styles = new Styles();
         }
         Texture target = base.target as Texture;
         bool    flag   = true;
         bool    flag2  = false;
         bool    flag3  = true;
         int     a      = 1;
         if ((base.target is Texture2D) || (base.target is ProceduralTexture))
         {
             flag2 = true;
             flag3 = false;
         }
         foreach (Texture texture2 in base.targets)
         {
             TextureFormat format = (TextureFormat)0;
             bool          flag4  = false;
             if (texture2 is Texture2D)
             {
                 format = (texture2 as Texture2D).format;
                 flag4  = true;
             }
             else if (texture2 is ProceduralTexture)
             {
                 format = (texture2 as ProceduralTexture).format;
                 flag4  = true;
             }
             if (flag4)
             {
                 if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                 {
                     flag2 = false;
                 }
                 if (TextureUtil.HasAlphaTextureFormat(format) && (TextureUtil.GetUsageMode(texture2) == TextureUsageMode.Default))
                 {
                     flag3 = true;
                 }
             }
             a = Mathf.Max(a, TextureUtil.GetMipmapCount(texture2));
         }
         if (flag2)
         {
             this.m_ShowAlpha = true;
             flag             = false;
         }
         else if (!flag3)
         {
             this.m_ShowAlpha = false;
             flag             = false;
         }
         if (flag && !IsNormalMap(target))
         {
             this.m_ShowAlpha = GUILayout.Toggle(this.m_ShowAlpha, !this.m_ShowAlpha ? s_Styles.RGBIcon : s_Styles.alphaIcon, s_Styles.previewButton, new GUILayoutOption[0]);
         }
         GUI.enabled = a != 1;
         GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.changed = false;
         GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth(64f) };
         this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(a - 1), 0f, s_Styles.previewSlider, s_Styles.previewSliderThumb, options));
         GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.enabled = true;
     }
 }
        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 void OnPreviewSettings()
        {
            if (IsCubemap())
            {
                m_CubemapPreview.OnPreviewSettings(targets);
                return;
            }

            if (IsTexture2DArray() && !SystemInfo.supports2DArrayTextures)
            {
                return;
            }

            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }

            // 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. It's also used for large popups for mini texture fields,
            // and while it's being shown the actual texture object might disappear --
            // make sure to handle null targets.
            Texture tex       = target as Texture;
            bool    alphaOnly = false;
            bool    hasAlpha  = true;
            int     mipCount  = 1;

            if (target is Texture2D)
            {
                alphaOnly = true;
                hasAlpha  = false;
            }

            foreach (Texture t in targets)
            {
                if (t == null) // texture might have disappeared while we're showing this in a preview popup
                {
                    continue;
                }
                TextureFormat format      = 0;
                bool          checkFormat = false;
                if (t is Texture2D)
                {
                    format      = (t as Texture2D).format;
                    checkFormat = true;
                }

                if (checkFormat)
                {
                    if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                    {
                        alphaOnly = false;
                    }
                    if (TextureUtil.HasAlphaTextureFormat(format))
                    {
                        TextureUsageMode mode = TextureUtil.GetUsageMode(t);
                        if (mode == TextureUsageMode.Default) // all other texture usage modes don't displayable alpha
                        {
                            hasAlpha = true;
                        }
                    }
                }

                mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(t));
            }


            List <PreviewMode> previewCandidates = new List <PreviewMode>(5);

            previewCandidates.Add(PreviewMode.RGB);
            previewCandidates.Add(PreviewMode.R);
            previewCandidates.Add(PreviewMode.G);
            previewCandidates.Add(PreviewMode.B);
            previewCandidates.Add(PreviewMode.A);

            if (alphaOnly)
            {
                previewCandidates.Clear();
                previewCandidates.Add(PreviewMode.A);
                m_PreviewMode = PreviewMode.A;
            }
            else if (!hasAlpha)
            {
                previewCandidates.Remove(PreviewMode.A);
            }


            if (previewCandidates.Count > 1 && tex != null && !IsNormalMap(tex))
            {
                int selectedIndex = previewCandidates.IndexOf(m_PreviewMode);
                if (selectedIndex == -1)
                {
                    selectedIndex = 0;
                }

                if (previewCandidates.Contains(PreviewMode.RGB))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.RGB, s_Styles.previewButtonContents[0], s_Styles.toolbarButton)
                        ? PreviewMode.RGB
                        : m_PreviewMode;
                }
                if (previewCandidates.Contains(PreviewMode.R))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.R, s_Styles.previewButtonContents[1], s_Styles.toolbarButton)
                        ? PreviewMode.R
                        : m_PreviewMode;
                }
                if (previewCandidates.Contains(PreviewMode.G))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.G, s_Styles.previewButtonContents[2], s_Styles.toolbarButton)
                        ? PreviewMode.G
                        : m_PreviewMode;
                }
                if (previewCandidates.Contains(PreviewMode.B))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.B, s_Styles.previewButtonContents[3], s_Styles.toolbarButton)
                        ? PreviewMode.B
                        : m_PreviewMode;
                }
                if (previewCandidates.Contains(PreviewMode.A))
                {
                    m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.A, s_Styles.previewButtonContents[4], s_Styles.toolbarButton)
                        ? PreviewMode.A
                        : m_PreviewMode;
                }
            }

            if (mipCount > 1)
            {
                GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel);
                GUI.changed = false;
                m_MipLevel  = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.MaxWidth(64)));

                //For now, we don't have mipmaps smaller than the tile size when using VT.
                if (EditorGUI.UseVTMaterial(tex))
                {
                    int numMipsOfTile = (int)Mathf.Log(VirtualTexturing.EditorHelpers.tileSize, 2) + 1;
                    m_MipLevel = Mathf.Min(m_MipLevel, Mathf.Max(mipCount - numMipsOfTile, 0));
                }

                GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel);
            }
        }
        public override void OnPreviewSettings()
        {
            if (IsCubemap())
            {
                m_CubemapPreview.OnPreviewSettings(targets);
                return;
            }


            if (s_Styles == null)
            {
                s_Styles = new Styles();
            }


            // 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. It's also used for large popups for mini texture fields,
            // and while it's being shown the actual texture object might disappear --
            // make sure to handle null targets.
            Texture tex       = target as Texture;
            bool    showMode  = true;
            bool    alphaOnly = false;
            bool    hasAlpha  = true;
            int     mipCount  = 1;

            if (target is Texture2D)
            {
                alphaOnly = true;
                hasAlpha  = false;
            }

            foreach (Texture t in targets)
            {
                if (t == null) // texture might have disappeared while we're showing this in a preview popup
                {
                    continue;
                }
                TextureFormat format      = 0;
                bool          checkFormat = false;
                if (t is Texture2D)
                {
                    format      = (t as Texture2D).format;
                    checkFormat = true;
                }

                if (checkFormat)
                {
                    if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                    {
                        alphaOnly = false;
                    }
                    if (TextureUtil.HasAlphaTextureFormat(format))
                    {
                        TextureUsageMode mode = TextureUtil.GetUsageMode(t);
                        if (mode == TextureUsageMode.Default) // all other texture usage modes don't displayable alpha
                        {
                            hasAlpha = true;
                        }
                    }
                }

                mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(t));
            }

            if (alphaOnly)
            {
                m_ShowAlpha = true;
                showMode    = false;
            }
            else if (!hasAlpha)
            {
                m_ShowAlpha = false;
                showMode    = false;
            }

            if (showMode && tex != null && !IsNormalMap(tex))
            {
                m_ShowAlpha = GUILayout.Toggle(m_ShowAlpha, m_ShowAlpha ? s_Styles.alphaIcon : s_Styles.RGBIcon, s_Styles.previewButton);
            }

            if (mipCount > 1)
            {
                GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel);
                GUI.changed = false;
                m_MipLevel  = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.MaxWidth(64)));
                GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel);
            }
        }
示例#10
0
        public override string GetInfoString()
        {
            Texture   texture   = this.target as Texture;
            Texture2D texture2D = this.target as Texture2D;
            string    text      = texture.width.ToString() + "x" + texture.height.ToString();

            if (QualitySettings.desiredColorSpace == ColorSpace.Linear)
            {
                text = text + " " + TextureUtil.GetTextureColorSpaceString(texture);
            }
            bool          flag          = TextureInspector.IsNormalMap(texture);
            bool          flag2         = TextureUtil.DoesTextureStillNeedToBeCompressed(AssetDatabase.GetAssetPath(texture));
            bool          flag3         = texture2D != null && TextureUtil.IsNonPowerOfTwo(texture2D);
            TextureFormat textureFormat = TextureUtil.GetTextureFormat(texture);
            bool          flag4         = !flag2;

            if (flag3)
            {
                text += " (NPOT)";
            }
            if (flag2)
            {
                text += " (Not yet compressed)";
            }
            else
            {
                if (flag)
                {
                    TextureFormat textureFormat2 = textureFormat;
                    switch (textureFormat2)
                    {
                    case TextureFormat.ARGB4444:
                        text += "  Nm 16 bit";
                        goto IL_142;

                    case TextureFormat.RGB24:
                    case TextureFormat.RGBA32:
IL_E9:
                        if (textureFormat2 != TextureFormat.DXT5)
                        {
                            text = text + "  " + TextureUtil.GetTextureFormatString(textureFormat);
                            goto IL_142;
                        }
                        text += "  DXTnm";
                        goto IL_142;

                    case TextureFormat.ARGB32:
                        text += "  Nm 32 bit";
                        goto IL_142;
                    }
                    goto IL_E9;
                    IL_142 :;
                }
                else
                {
                    text = text + "  " + TextureUtil.GetTextureFormatString(textureFormat);
                }
            }
            if (flag4)
            {
                text = text + "\n" + EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySize(texture));
            }
            if (TextureUtil.GetUsageMode(texture) == TextureUsageMode.AlwaysPadded)
            {
                int gLWidth  = TextureUtil.GetGLWidth(texture);
                int gLHeight = TextureUtil.GetGLHeight(texture);
                if (texture.width != gLWidth || texture.height != gLHeight)
                {
                    text += string.Format("\nPadded to {0}x{1}", gLWidth, gLHeight);
                }
            }
            return(text);
        }
        public override string GetInfoString()
        {
            Texture         target1 = this.target as Texture;
            Texture2D       target2 = this.target as Texture2D;
            TextureImporter atPath  = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath((UnityEngine.Object)target1)) as TextureImporter;
            string          str1    = target1.width.ToString() + "x" + target1.height.ToString();

            if (QualitySettings.desiredColorSpace == ColorSpace.Linear)
            {
                str1 = str1 + " " + TextureUtil.GetTextureColorSpaceString(target1);
            }
            bool          flag1          = (bool)((UnityEngine.Object)atPath) && atPath.qualifiesForSpritePacking;
            bool          flag2          = TextureInspector.IsNormalMap(target1);
            bool          beCompressed   = TextureUtil.DoesTextureStillNeedToBeCompressed(AssetDatabase.GetAssetPath((UnityEngine.Object)target1));
            bool          flag3          = (UnityEngine.Object)target2 != (UnityEngine.Object)null && TextureUtil.IsNonPowerOfTwo(target2);
            TextureFormat textureFormat1 = TextureUtil.GetTextureFormat(target1);
            bool          flag4          = !beCompressed;

            if (flag3)
            {
                str1 += " (NPOT)";
            }
            string str2;

            if (beCompressed)
            {
                str2 = str1 + " (Not yet compressed)";
            }
            else if (flag2)
            {
                TextureFormat textureFormat2 = textureFormat1;
                switch (textureFormat2)
                {
                case TextureFormat.ARGB4444:
                    str2 = str1 + "  Nm 16 bit";
                    break;

                case TextureFormat.ARGB32:
                    str2 = str1 + "  Nm 32 bit";
                    break;

                default:
                    str2 = textureFormat2 == TextureFormat.DXT5 ? str1 + "  DXTnm" : str1 + "  " + TextureUtil.GetTextureFormatString(textureFormat1);
                    break;
                }
            }
            else if (flag1)
            {
                TextureFormat desiredFormat;
                ColorSpace    colorSpace;
                int           compressionQuality;
                atPath.ReadTextureImportInstructions(EditorUserBuildSettings.activeBuildTarget, out desiredFormat, out colorSpace, out compressionQuality);
                str2 = str1 + "\n " + TextureUtil.GetTextureFormatString(textureFormat1) + "(Original) " + TextureUtil.GetTextureFormatString(desiredFormat) + "(Atlas)";
            }
            else
            {
                str2 = str1 + "  " + TextureUtil.GetTextureFormatString(textureFormat1);
            }
            if (flag4)
            {
                str2 = str2 + "\n" + EditorUtility.FormatBytes(TextureUtil.GetStorageMemorySize(target1));
            }
            if (TextureUtil.GetUsageMode(target1) == TextureUsageMode.AlwaysPadded)
            {
                int glWidth  = TextureUtil.GetGLWidth(target1);
                int glHeight = TextureUtil.GetGLHeight(target1);
                if (target1.width != glWidth || target1.height != glHeight)
                {
                    str2 += string.Format("\nPadded to {0}x{1}", (object)glWidth, (object)glHeight);
                }
            }
            return(str2);
        }
 public override void OnPreviewSettings()
 {
     if (this.IsCubemap())
     {
         this.m_CubemapPreview.OnPreviewSettings(this.targets);
     }
     else
     {
         if (TextureInspector.s_Styles == null)
         {
             TextureInspector.s_Styles = new TextureInspector.Styles();
         }
         Texture target1 = this.target as Texture;
         bool    flag1   = true;
         bool    flag2   = false;
         bool    flag3   = true;
         int     a       = 1;
         if (this.target is Texture2D || this.target is ProceduralTexture)
         {
             flag2 = true;
             flag3 = false;
         }
         foreach (Texture target2 in this.targets)
         {
             TextureFormat format = (TextureFormat)0;
             bool          flag4  = false;
             if (target2 is Texture2D)
             {
                 format = (target2 as Texture2D).format;
                 flag4  = true;
             }
             else if (target2 is ProceduralTexture)
             {
                 format = (target2 as ProceduralTexture).format;
                 flag4  = true;
             }
             if (flag4)
             {
                 if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                 {
                     flag2 = false;
                 }
                 if (TextureUtil.HasAlphaTextureFormat(format) && TextureUtil.GetUsageMode(target2) == TextureUsageMode.Default)
                 {
                     flag3 = true;
                 }
             }
             a = Mathf.Max(a, TextureUtil.CountMipmaps(target2));
         }
         if (flag2)
         {
             this.m_ShowAlpha = true;
             flag1            = false;
         }
         else if (!flag3)
         {
             this.m_ShowAlpha = false;
             flag1            = false;
         }
         if (flag1 && !TextureInspector.IsNormalMap(target1))
         {
             this.m_ShowAlpha = GUILayout.Toggle(this.m_ShowAlpha, !this.m_ShowAlpha ? TextureInspector.s_Styles.RGBIcon : TextureInspector.s_Styles.alphaIcon, TextureInspector.s_Styles.previewButton, new GUILayoutOption[0]);
         }
         GUI.enabled = a != 1;
         GUILayout.Box(TextureInspector.s_Styles.smallZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.changed     = false;
         this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(a - 1), 0.0f, TextureInspector.s_Styles.previewSlider, TextureInspector.s_Styles.previewSliderThumb, GUILayout.MaxWidth(64f)));
         GUILayout.Box(TextureInspector.s_Styles.largeZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]);
         GUI.enabled = true;
     }
 }
示例#13
0
        // Native NeedsExposureControl doesn't work for RenderTextures (they are hardcoded to return kTexFormatUnknown).
        protected bool NeedsExposureControl(Texture t)
        {
            TextureUsageMode usageMode = TextureUtil.GetUsageMode(t);

            return(GraphicsFormatUtility.IsHDRFormat(t.graphicsFormat) || TextureUtil.IsRGBMUsageMode(usageMode) || TextureUtil.IsDoubleLDRUsageMode(usageMode));
        }
示例#14
0
        public static bool IsNormalMap(Texture t)
        {
            TextureUsageMode mode = TextureUtil.GetUsageMode(t);

            return(TextureUtil.IsNormalMapUsageMode(mode));
        }
示例#15
0
        public static bool IsNormalMap(Texture t)
        {
            TextureUsageMode usageMode = TextureUtil.GetUsageMode(t);

            return(usageMode == TextureUsageMode.NormalmapPlain || usageMode == TextureUsageMode.NormalmapDXT5nm);
        }
示例#16
0
 public void OnPreviewSettings(UnityEngine.Object[] targets)
 {
     if (ShaderUtil.hardwareSupportsRectRenderTexture)
     {
         GUI.enabled = true;
         this.InitPreview();
         bool flag  = true;
         bool flag2 = true;
         bool flag3 = false;
         int  num   = 8;
         for (int i = 0; i < targets.Length; i++)
         {
             Texture texture = (Texture)targets[i];
             num = Mathf.Max(num, TextureUtil.GetMipmapCount(texture));
             Cubemap cubemap = texture as Cubemap;
             if (cubemap)
             {
                 TextureFormat format = cubemap.format;
                 if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                 {
                     flag2 = false;
                 }
                 if (TextureUtil.HasAlphaTextureFormat(format))
                 {
                     if (TextureUtil.GetUsageMode(texture) == TextureUsageMode.Default)
                     {
                         flag3 = true;
                     }
                 }
             }
             else
             {
                 flag3 = true;
                 flag2 = false;
             }
         }
         if (flag2)
         {
             this.m_PreviewType = CubemapPreview.PreviewType.Alpha;
             flag = false;
         }
         else if (!flag3)
         {
             this.m_PreviewType = CubemapPreview.PreviewType.RGB;
             flag = false;
         }
         if (flag)
         {
             GUIContent[] array = new GUIContent[]
             {
                 CubemapPreview.Styles.RGBIcon,
                 CubemapPreview.Styles.alphaIcon
             };
             int previewType = (int)this.m_PreviewType;
             if (GUILayout.Button(array[previewType], CubemapPreview.Styles.preButton, new GUILayoutOption[0]))
             {
                 this.m_PreviewType = (previewType + CubemapPreview.PreviewType.Alpha) % (CubemapPreview.PreviewType)array.Length;
             }
         }
         GUI.enabled = (num != 1);
         GUILayout.Box(CubemapPreview.Styles.smallZoom, CubemapPreview.Styles.preLabel, new GUILayoutOption[0]);
         GUI.changed     = false;
         this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(num - 1), 0f, CubemapPreview.Styles.preSlider, CubemapPreview.Styles.preSliderThumb, new GUILayoutOption[]
         {
             GUILayout.MaxWidth(64f)
         }));
         GUILayout.Box(CubemapPreview.Styles.largeZoom, CubemapPreview.Styles.preLabel, new GUILayoutOption[0]);
         GUI.enabled = true;
     }
 }
        public void OnPreviewSettings(Object[] targets)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return;
            }
            GUI.enabled = true;
            InitPreview();

            bool showMode  = true;
            bool alphaOnly = true;
            //@TODO: Share some code with texture inspector???
            bool hasAlpha = false;
            int  mipCount = 8;

            foreach (Texture t2 in targets)
            {
                mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(t2));

                Cubemap cubemap = t2 as Cubemap;
                if (cubemap)
                {
                    TextureFormat format = cubemap.format;
                    if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                    {
                        alphaOnly = false;
                    }
                    if (TextureUtil.HasAlphaTextureFormat(format))
                    {
                        TextureUsageMode mode = TextureUtil.GetUsageMode(t2);
                        if (mode == TextureUsageMode.Default) // all other texture usage modes don't displayable alpha
                        {
                            hasAlpha = true;
                        }
                    }
                }
                else
                {
                    hasAlpha  = true;
                    alphaOnly = false;
                }
            }

            if (alphaOnly)
            {
                m_PreviewType = PreviewType.Alpha;
                showMode      = false;
            }
            else if (!hasAlpha)
            {
                m_PreviewType = PreviewType.RGB;
                showMode      = false;
            }

            if (showMode)
            {
                GUIContent[] kPreviewIcons = { Styles.RGBIcon, Styles.alphaIcon };
                int          index         = (int)m_PreviewType;
                if (GUILayout.Button(kPreviewIcons[index], Styles.preButton))
                {
                    m_PreviewType = (PreviewType)(++index % kPreviewIcons.Length);
                }
            }

            GUI.enabled = (mipCount != 1);
            GUILayout.Box(Styles.smallZoom, Styles.preLabel);
            GUI.changed = false;
            m_MipLevel  = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, Styles.preSlider, Styles.preSliderThumb, GUILayout.MaxWidth(64)));
            GUILayout.Box(Styles.largeZoom, Styles.preLabel);
            GUI.enabled = true;
        }
示例#18
0
        public void OnPreviewSettings(Object[] targets)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return;
            }
            GUI.enabled = true;
            this.InitPreview();
            bool flag1 = true;
            bool flag2 = true;
            bool flag3 = false;
            int  a     = 8;

            foreach (Texture target in targets)
            {
                a = Mathf.Max(a, TextureUtil.CountMipmaps(target));
                Cubemap cubemap = target as Cubemap;
                if ((bool)((Object)cubemap))
                {
                    TextureFormat format = cubemap.format;
                    if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                    {
                        flag2 = false;
                    }
                    if (TextureUtil.HasAlphaTextureFormat(format) && TextureUtil.GetUsageMode(target) == TextureUsageMode.Default)
                    {
                        flag3 = true;
                    }
                }
                else
                {
                    flag3 = true;
                    flag2 = false;
                }
            }
            if (flag2)
            {
                this.m_PreviewType = CubemapPreview.PreviewType.Alpha;
                flag1 = false;
            }
            else if (!flag3)
            {
                this.m_PreviewType = CubemapPreview.PreviewType.RGB;
                flag1 = false;
            }
            if (flag1)
            {
                GUIContent[] guiContentArray = new GUIContent[2] {
                    CubemapPreview.Styles.RGBIcon, CubemapPreview.Styles.alphaIcon
                };
                int previewType = (int)this.m_PreviewType;
                if (GUILayout.Button(guiContentArray[previewType], CubemapPreview.Styles.preButton, new GUILayoutOption[0]))
                {
                    int num;
                    this.m_PreviewType = (CubemapPreview.PreviewType)((num = previewType + 1) % guiContentArray.Length);
                }
            }
            GUI.enabled = a != 1;
            GUILayout.Box(CubemapPreview.Styles.smallZoom, CubemapPreview.Styles.preLabel, new GUILayoutOption[0]);
            GUI.changed     = false;
            this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(a - 1), 0.0f, CubemapPreview.Styles.preSlider, CubemapPreview.Styles.preSliderThumb, GUILayout.MaxWidth(64f)));
            GUILayout.Box(CubemapPreview.Styles.largeZoom, CubemapPreview.Styles.preLabel, new GUILayoutOption[0]);
            GUI.enabled = true;
        }