コード例 #1
0
        protected void DoAlphaZoomToolbarGUI()
        {
            this.m_ShowAlpha = GUILayout.Toggle(this.m_ShowAlpha, (!this.m_ShowAlpha) ? SpriteUtilityWindow.s_Styles.RGBIcon : SpriteUtilityWindow.s_Styles.alphaIcon, "toolbarButton", new GUILayoutOption[0]);
            this.m_Zoom      = GUILayout.HorizontalSlider(this.m_Zoom, this.GetMinZoom(), 50f, SpriteUtilityWindow.s_Styles.preSlider, SpriteUtilityWindow.s_Styles.preSliderThumb, new GUILayoutOption[]
            {
                GUILayout.MaxWidth(64f)
            });
            int num = 1;

            if (this.m_Texture != null)
            {
                num = Mathf.Max(num, TextureUtil.CountMipmaps(this.m_Texture));
            }
            EditorGUI.BeginDisabledGroup(num == 1);
            GUILayout.Box(SpriteUtilityWindow.s_Styles.smallMip, SpriteUtilityWindow.s_Styles.preLabel, new GUILayoutOption[0]);
            this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(num - 1), 0f, SpriteUtilityWindow.s_Styles.preSlider, SpriteUtilityWindow.s_Styles.preSliderThumb, new GUILayoutOption[]
            {
                GUILayout.MaxWidth(64f)
            }));
            GUILayout.Box(SpriteUtilityWindow.s_Styles.largeMip, SpriteUtilityWindow.s_Styles.preLabel, new GUILayoutOption[0]);
            EditorGUI.EndDisabledGroup();
        }
コード例 #2
0
        public override string GetInfoString()
        {
            RenderTexture renderTexture = base.target as RenderTexture;
            string        text          = renderTexture.width + "x" + renderTexture.height;

            if (renderTexture.dimension == TextureDimension.Tex3D)
            {
                text = text + "x" + renderTexture.volumeDepth;
            }
            if (!renderTexture.isPowerOfTwo)
            {
                text += "(NPOT)";
            }
            if (QualitySettings.desiredColorSpace == ColorSpace.Linear)
            {
                bool flag  = RenderTextureEditor.IsHDRFormat(renderTexture.format);
                bool flag2 = renderTexture.sRGB && !flag;
                text = text + " " + ((!flag2) ? "Linear" : "sRGB");
            }
            text = text + "  " + renderTexture.format;
            return(text + "  " + EditorUtility.FormatBytes(TextureUtil.GetRuntimeMemorySizeLong(renderTexture)));
        }
コード例 #3
0
        private void ShowFace(string label, CubemapFace face)
        {
            var c     = target as Cubemap;
            var iface = (int)face;

            GUI.changed = false;

            var tex = (Texture2D)ObjectField(label, m_Images[iface], typeof(Texture2D), false);

            if (GUI.changed)
            {
                if (tex != null)
                {
                    TextureUtil.CopyTextureIntoCubemapFace(tex, c, face);
                }
                // enable this line in order to retain connections from cube faces to their corresponding
                // texture2D assets, this allows auto-update functionality when editing the source texture
                // images
                //TextureUtil.SetSourceTexture(c, face, tex);
                m_Images[iface] = tex;
            }
        }
コード例 #4
0
        public override void OnInspectorGUI()
        {
            serializedObject.Update();
            EditorGUILayout.PropertyField(m_IsReadable, Styles.readWrite);
            EditorGUILayout.PropertyField(m_sRGBTexture, Styles.sRGBTexture);

            EditorGUI.BeginChangeCheck();
            TextureSettingsGUI();
            if (EditorGUI.EndChangeCheck())
            {
                // copy pasted from TextureImporterInspector.TextureSettingsGUI()
                foreach (AssetImporter importer in targets)
                {
                    Texture tex = AssetDatabase.LoadMainAssetAtPath(importer.assetPath) as Texture;
                    if (m_FilterMode.intValue != -1)
                    {
                        TextureUtil.SetFilterModeNoDirty(tex, (FilterMode)m_FilterMode.intValue);
                    }
                    if ((m_WrapU.intValue != -1 || m_WrapV.intValue != -1 || m_WrapW.intValue != -1) &&
                        !m_WrapU.hasMultipleDifferentValues && !m_WrapV.hasMultipleDifferentValues && !m_WrapW.hasMultipleDifferentValues)
                    {
                        TextureUtil.SetWrapModeNoDirty(tex, (TextureWrapMode)m_WrapU.intValue, (TextureWrapMode)m_WrapV.intValue, (TextureWrapMode)m_WrapW.intValue);
                    }
                }
                SceneView.RepaintAll();
            }

            EditorGUILayout.PropertyField(m_StreamingMipmaps, Styles.streamingMipmaps);

            if (m_StreamingMipmaps.boolValue && !m_StreamingMipmaps.hasMultipleDifferentValues)
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.PropertyField(m_StreamingMipmapsPriority, Styles.streamingMipmapsPriority);
                EditorGUI.indentLevel--;
            }
            serializedObject.ApplyModifiedProperties();
            ApplyRevertGUI();
        }
コード例 #5
0
        // wrap/filter/aniso editors will change serialized object
        // but in case of textures we need an extra step to ApplySettings (so rendering uses new values)
        // alas we cant have good things: it will be PITA to make sure we always call that after applying changes to serialized object
        // meaning that we need to work without relying on it, hence we do similar to TextureImporter:
        //   use TextureUtil methods to update texture settings from current values of serialized property
        // another possibility would be to do it separately for wrap/filter/aniso
        //   alas for wrapmode i dont see how it can be done clearly and leaving it out seems a bit weird

        protected void ApplySettingsToTextures()
        {
            bool anisoDiffer = m_Aniso.hasMultipleDifferentValues, filterDiffer = m_FilterMode.hasMultipleDifferentValues;
            bool wrapDiffer = m_WrapU.hasMultipleDifferentValues || m_WrapV.hasMultipleDifferentValues || m_WrapW.hasMultipleDifferentValues;

            foreach (Texture tex in targets)
            {
                if (!anisoDiffer)
                {
                    TextureUtil.SetAnisoLevelNoDirty(tex, m_Aniso.intValue);
                }

                if (!filterDiffer)
                {
                    TextureUtil.SetFilterModeNoDirty(tex, (FilterMode)m_FilterMode.intValue);
                }

                if (!wrapDiffer)
                {
                    TextureUtil.SetWrapModeNoDirty(tex, (TextureWrapMode)m_WrapU.intValue, (TextureWrapMode)m_WrapV.intValue, (TextureWrapMode)m_WrapW.intValue);
                }
            }
        }
コード例 #6
0
        protected Rect DoAlphaZoomToolbarGUI(Rect area)
        {
            int mipCount = 1;

            if (m_Texture != null)
            {
                mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(m_Texture));
            }

            Rect drawArea = new Rect(area.width, 0, 0, area.height);

            using (new EditorGUI.DisabledScope(mipCount == 1))
            {
                drawArea.width = m_Styles.largeMip.image.width;
                drawArea.x    -= drawArea.width;
                GUI.Box(drawArea, m_Styles.largeMip, m_Styles.preLabel);

                drawArea.width = EditorGUI.kSliderMinW;
                drawArea.x    -= drawArea.width;
                m_MipLevel     = Mathf.Round(GUI.HorizontalSlider(drawArea, m_MipLevel, mipCount - 1, 0, m_Styles.preSlider, m_Styles.preSliderThumb));

                drawArea.width = m_Styles.smallMip.image.width;
                drawArea.x    -= drawArea.width;
                GUI.Box(drawArea, m_Styles.smallMip, m_Styles.preLabel);
            }

            drawArea.width = EditorGUI.kSliderMinW;
            drawArea.x    -= drawArea.width;
            m_Zoom         = GUI.HorizontalSlider(drawArea, m_Zoom, GetMinZoom(), k_MaxZoom, m_Styles.preSlider, m_Styles.preSliderThumb);

            drawArea.width = EditorGUI.kObjectFieldMiniThumbnailWidth;
            drawArea.x    -= drawArea.width + EditorGUI.kSpacing;
            m_ShowAlpha    = GUI.Toggle(drawArea, m_ShowAlpha, m_ShowAlpha ? m_Styles.alphaIcon : m_Styles.RGBIcon, "toolbarButton");

            // Returns the area that is not used
            return(new Rect(area.x, area.y, drawArea.x, area.height));
        }
コード例 #7
0
        // wrap/filter/aniso editors will change serialized object
        // but in case of textures we need an extra step to ApplySettings (so rendering uses new values)
        // alas we cant have good things: it will be PITA to make sure we always call that after applying changes to serialized object
        // meaning that we need to work without relying on it, hence we do similar to TextureImporter:
        //   use TextureUtil methods to update texture settings from current values of serialized property
        // another possibility would be to do it separately for wrap/filter/aniso
        //   alas for wrapmode i dont see how it can be done clearly and leaving it out seems a bit weird

        protected void ApplySettingsToTextures()
        {
            bool anisoDiffer = m_Aniso.hasMultipleDifferentValues, filterDiffer = m_FilterMode.hasMultipleDifferentValues;
            bool wrapDiffer = m_WrapU.hasMultipleDifferentValues || m_WrapV.hasMultipleDifferentValues || m_WrapW.hasMultipleDifferentValues;

            foreach (Texture tex in targets)
            {
                if (m_Aniso.intValue != -1 && !anisoDiffer)
                {
                    TextureUtil.SetAnisoLevelNoDirty(tex, m_Aniso.intValue);
                }
                if (m_FilterMode.intValue != -1 && !filterDiffer)
                {
                    TextureUtil.SetFilterModeNoDirty(tex, (FilterMode)m_FilterMode.intValue);
                }

                // NB i am not sure if it is *possible* to have -1 in there and if it make sense to pass -1 to SetWrapModeNoDirty
                // NB but this is how TextureImporter checks things and who am i to argue
                if ((m_WrapU.intValue != -1 || m_WrapV.intValue != -1 || m_WrapW.intValue != -1) && !wrapDiffer)
                {
                    TextureUtil.SetWrapModeNoDirty(tex, (TextureWrapMode)m_WrapU.intValue, (TextureWrapMode)m_WrapV.intValue, (TextureWrapMode)m_WrapW.intValue);
                }
            }
        }
コード例 #8
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }
            Texture texture = base.target as Texture;

            if (!(texture == null))
            {
                RenderTexture renderTexture = texture as RenderTexture;
                if (renderTexture != null)
                {
                    if (!SystemInfo.SupportsRenderTextureFormat(renderTexture.format))
                    {
                        return;
                    }
                    renderTexture.Create();
                }
                if (this.IsCubemap())
                {
                    this.m_CubemapPreview.OnPreviewGUI(texture, r, background);
                }
                else
                {
                    int   num  = Mathf.Max(texture.width, 1);
                    int   num2 = Mathf.Max(texture.height, 1);
                    float mipLevelForRendering = this.GetMipLevelForRendering();
                    float num3 = Mathf.Min(Mathf.Min(r.width / (float)num, r.height / (float)num2), 1f);
                    Rect  rect = new Rect(r.x, r.y, (float)num * num3, (float)num2 * num3);
                    PreviewGUI.BeginScrollView(r, this.m_Pos, rect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
                    float mipMapBias = texture.mipMapBias;
                    TextureUtil.SetMipMapBiasNoDirty(texture, mipLevelForRendering - this.Log2((float)num / rect.width));
                    FilterMode filterMode = texture.filterMode;
                    TextureUtil.SetFilterModeNoDirty(texture, FilterMode.Point);
                    if (this.m_ShowAlpha)
                    {
                        EditorGUI.DrawTextureAlpha(rect, texture);
                    }
                    else
                    {
                        Texture2D texture2D = texture as Texture2D;
                        if (texture2D != null && texture2D.alphaIsTransparency)
                        {
                            EditorGUI.DrawTextureTransparent(rect, texture);
                        }
                        else
                        {
                            EditorGUI.DrawPreviewTexture(rect, texture);
                        }
                    }
                    if (rect.width > 32f && rect.height > 32f)
                    {
                        string           assetPath       = AssetDatabase.GetAssetPath(texture);
                        TextureImporter  textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
                        SpriteMetaData[] array           = (!(textureImporter != null)) ? null : textureImporter.spritesheet;
                        if (array != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple)
                        {
                            Rect rect2 = default(Rect);
                            Rect rect3 = default(Rect);
                            GUI.CalculateScaledTextureRects(rect, ScaleMode.StretchToFill, (float)texture.width / (float)texture.height, ref rect2, ref rect3);
                            int width  = texture.width;
                            int height = texture.height;
                            textureImporter.GetWidthAndHeight(ref width, ref height);
                            float num4 = (float)texture.width / (float)width;
                            HandleUtility.ApplyWireMaterial();
                            GL.PushMatrix();
                            GL.MultMatrix(Handles.matrix);
                            GL.Begin(1);
                            GL.Color(new Color(1f, 1f, 1f, 0.5f));
                            SpriteMetaData[] array2 = array;
                            for (int i = 0; i < array2.Length; i++)
                            {
                                SpriteMetaData spriteMetaData = array2[i];
                                Rect           rect4          = spriteMetaData.rect;
                                this.DrawRect(new Rect
                                {
                                    xMin = rect2.xMin + rect2.width * (rect4.xMin / (float)texture.width * num4),
                                    xMax = rect2.xMin + rect2.width * (rect4.xMax / (float)texture.width * num4),
                                    yMin = rect2.yMin + rect2.height * (1f - rect4.yMin / (float)texture.height * num4),
                                    yMax = rect2.yMin + rect2.height * (1f - rect4.yMax / (float)texture.height * num4)
                                });
                            }
                            GL.End();
                            GL.PopMatrix();
                        }
                    }
                    TextureUtil.SetMipMapBiasNoDirty(texture, mipMapBias);
                    TextureUtil.SetFilterModeNoDirty(texture, filterMode);
                    this.m_Pos = PreviewGUI.EndScrollView();
                    if (mipLevelForRendering != 0f)
                    {
                        EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + mipLevelForRendering);
                    }
                }
            }
        }
コード例 #9
0
        public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height)
        {
            Texture2D result;

            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                result = null;
            }
            else
            {
                Texture texture = base.target as Texture;
                if (this.IsCubemap())
                {
                    result = this.m_CubemapPreview.RenderStaticPreview(texture, width, height);
                }
                else
                {
                    TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter;
                    if (textureImporter != null && textureImporter.textureType == TextureImporterType.Sprite && textureImporter.spriteImportMode == SpriteImportMode.Polygon)
                    {
                        Sprite sprite = subAssets[0] as Sprite;
                        if (sprite)
                        {
                            result = SpriteInspector.BuildPreviewTexture(width, height, sprite, null, true);
                            return(result);
                        }
                    }
                    PreviewHelpers.AdjustWidthAndHeightForStaticPreview(texture.width, texture.height, ref width, ref height);
                    RenderTexture active          = RenderTexture.active;
                    Rect          rawViewportRect = ShaderUtil.rawViewportRect;
                    bool          flag            = !TextureUtil.GetLinearSampled(texture);
                    RenderTexture temporary       = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, (!flag) ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB);
                    Material      material        = EditorGUI.GetMaterialForSpecialTexture(texture);
                    GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
                    if (material)
                    {
                        if (Unsupported.IsDeveloperBuild())
                        {
                            material = new Material(material);
                        }
                        Graphics.Blit(texture, temporary, material);
                    }
                    else
                    {
                        Graphics.Blit(texture, temporary);
                    }
                    GL.sRGBWrite         = false;
                    RenderTexture.active = temporary;
                    Texture2D texture2D = base.target as Texture2D;
                    Texture2D texture2D2;
                    if (texture2D != null && texture2D.alphaIsTransparency)
                    {
                        texture2D2 = new Texture2D(width, height, TextureFormat.RGBA32, false);
                    }
                    else
                    {
                        texture2D2 = new Texture2D(width, height, TextureFormat.RGB24, false);
                    }
                    texture2D2.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
                    texture2D2.Apply();
                    RenderTexture.ReleaseTemporary(temporary);
                    EditorGUIUtility.SetRenderTextureNoViewport(active);
                    ShaderUtil.rawViewportRect = rawViewportRect;
                    if (material && Unsupported.IsDeveloperBuild())
                    {
                        UnityEngine.Object.DestroyImmediate(material);
                    }
                    result = texture2D2;
                }
            }
            return(result);
        }
コード例 #10
0
        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}");
        }
コード例 #11
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;
     }
 }
コード例 #12
0
        void Summary()
        {
            GUILayout.BeginVertical(EditorStyles.helpBox);

            long totalMemorySize            = 0;
            int  lightmapCount              = 0;
            Dictionary <Vector2, int> sizes = new Dictionary <Vector2, int>();
            bool directionalLightmapsMode   = false;
            bool shadowmaskMode             = false;

            foreach (LightmapData ld in LightmapSettings.lightmaps)
            {
                if (ld.lightmapColor == null)
                {
                    continue;
                }
                lightmapCount++;

                Vector2 texSize = new Vector2(ld.lightmapColor.width, ld.lightmapColor.height);
                if (sizes.ContainsKey(texSize))
                {
                    sizes[texSize]++;
                }
                else
                {
                    sizes.Add(texSize, 1);
                }

                totalMemorySize += TextureUtil.GetStorageMemorySizeLong(ld.lightmapColor);
                if (ld.lightmapDir)
                {
                    totalMemorySize         += TextureUtil.GetStorageMemorySizeLong(ld.lightmapDir);
                    directionalLightmapsMode = true;
                }
                if (ld.shadowMask)
                {
                    totalMemorySize += TextureUtil.GetStorageMemorySizeLong(ld.shadowMask);
                    shadowmaskMode   = true;
                }
            }
            StringBuilder sizesString = new StringBuilder();

            sizesString.Append(lightmapCount);
            sizesString.Append((directionalLightmapsMode ? " Directional" : " Non-Directional"));
            sizesString.Append(" Lightmap");
            if (lightmapCount != 1)
            {
                sizesString.Append("s");
            }
            if (shadowmaskMode)
            {
                sizesString.Append(" with Shadowmask");
                if (lightmapCount != 1)
                {
                    sizesString.Append("s");
                }
            }

            bool first = true;

            foreach (var s in sizes)
            {
                sizesString.Append(first ? ": " : ", ");
                first = false;
                if (s.Value > 1)
                {
                    sizesString.Append(s.Value);
                    sizesString.Append("x");
                }
                sizesString.Append(s.Key.x.ToString(CultureInfo.InvariantCulture.NumberFormat));
                sizesString.Append("x");
                sizesString.Append(s.Key.y.ToString(CultureInfo.InvariantCulture.NumberFormat));
                sizesString.Append("px");
            }
            sizesString.Append(" ");

            GUILayout.BeginHorizontal();

            GUILayout.BeginVertical();
            GUILayout.Label(sizesString.ToString(), Styles.LabelStyle);
            GUILayout.EndVertical();

            GUILayout.BeginVertical();
            GUILayout.Label(EditorUtility.FormatBytes(totalMemorySize), Styles.LabelStyle);
            GUILayout.Label((lightmapCount == 0 ? "No Lightmaps" : ""), Styles.LabelStyle);
            GUILayout.EndVertical();

            GUILayout.EndHorizontal();

            if (LightmapEditorSettings.lightmapper != LightmapEditorSettings.Lightmapper.Enlighten)
            {
                GUILayout.BeginVertical();
                GUILayout.Label("Occupied Texels: " + InternalEditorUtility.CountToString(Lightmapping.occupiedTexelCount), Styles.LabelStyle);
                if (Lightmapping.isRunning)
                {
                    int numLightmapsInView             = 0;
                    int numConvergedLightmapsInView    = 0;
                    int numNotConvergedLightmapsInView = 0;

                    int numLightmapsNotInView             = 0;
                    int numConvergedLightmapsNotInView    = 0;
                    int numNotConvergedLightmapsNotInView = 0;

                    int numLightmaps = LightmapSettings.lightmaps.Length;
                    for (int i = 0; i < numLightmaps; ++i)
                    {
                        LightmapConvergence lc = Lightmapping.GetLightmapConvergence(i);
                        if (!lc.IsValid())
                        {
                            continue;
                        }

                        if (Lightmapping.GetVisibleTexelCount(i) > 0)
                        {
                            numLightmapsInView++;
                            if (lc.IsConverged())
                            {
                                numConvergedLightmapsInView++;
                            }
                            else
                            {
                                numNotConvergedLightmapsInView++;
                            }
                        }
                        else
                        {
                            numLightmapsNotInView++;
                            if (lc.IsConverged())
                            {
                                numConvergedLightmapsNotInView++;
                            }
                            else
                            {
                                numNotConvergedLightmapsNotInView++;
                            }
                        }
                    }
                    if (Lightmapping.atlasCount > 0)
                    {
                        int convergedMaps = numConvergedLightmapsInView + numConvergedLightmapsNotInView;
                        GUILayout.Label("Lightmap convergence: (" + convergedMaps + "/" + Lightmapping.atlasCount + ")", Styles.LabelStyle);
                    }
                    EditorGUILayout.LabelField("Lightmaps in view: " + numLightmapsInView, Styles.LabelStyle);
                    EditorGUI.indentLevel += 1;
                    EditorGUILayout.LabelField("Converged: " + numConvergedLightmapsInView, Styles.LabelStyle);
                    EditorGUILayout.LabelField("Not Converged: " + numNotConvergedLightmapsInView, Styles.LabelStyle);
                    EditorGUI.indentLevel -= 1;
                    EditorGUILayout.LabelField("Lightmaps not in view: " + numLightmapsNotInView, Styles.LabelStyle);
                    EditorGUI.indentLevel += 1;
                    EditorGUILayout.LabelField("Converged: " + numConvergedLightmapsNotInView, Styles.LabelStyle);
                    EditorGUILayout.LabelField("Not Converged: " + numNotConvergedLightmapsNotInView, Styles.LabelStyle);
                    EditorGUI.indentLevel -= 1;

                    LightProbesConvergence lpc = Lightmapping.GetLightProbesConvergence();
                    if (lpc.IsValid() && lpc.probeSetCount > 0)
                    {
                        GUILayout.Label("Light Probes convergence: (" + lpc.convergedProbeSetCount + "/" + lpc.probeSetCount + ")", Styles.LabelStyle);
                    }
                }
                float bakeTime    = Lightmapping.GetLightmapBakeTimeTotal();
                float mraysPerSec = Lightmapping.GetLightmapBakePerformanceTotal();
                if (mraysPerSec >= 0.0)
                {
                    GUILayout.Label("Bake Performance: " + mraysPerSec.ToString("0.00", CultureInfo.InvariantCulture.NumberFormat) + " mrays/sec", Styles.LabelStyle);
                }
                if (!Lightmapping.isRunning)
                {
                    float bakeTimeRaw = Lightmapping.GetLightmapBakeTimeRaw();
                    if (bakeTime >= 0.0)
                    {
                        int time  = (int)bakeTime;
                        int timeH = time / 3600;
                        time -= 3600 * timeH;
                        int timeM = time / 60;
                        time -= 60 * timeM;
                        int timeS = time;

                        int timeRaw  = (int)bakeTimeRaw;
                        int timeRawH = timeRaw / 3600;
                        timeRaw -= 3600 * timeRawH;
                        int timeRawM = timeRaw / 60;
                        timeRaw -= 60 * timeRawM;
                        int timeRawS = timeRaw;

                        int oHeadTime  = Math.Max(0, (int)(bakeTime - bakeTimeRaw));
                        int oHeadTimeH = oHeadTime / 3600;
                        oHeadTime -= 3600 * oHeadTimeH;
                        int oHeadTimeM = oHeadTime / 60;
                        oHeadTime -= 60 * oHeadTimeM;
                        int oHeadTimeS = oHeadTime;


                        GUILayout.Label("Total Bake Time: " + timeH.ToString("0") + ":" + timeM.ToString("00") + ":" + timeS.ToString("00"), Styles.LabelStyle);
                        if (Unsupported.IsDeveloperBuild())
                        {
                            GUILayout.Label("(Raw Bake Time: " + timeRawH.ToString("0") + ":" + timeRawM.ToString("00") + ":" + timeRawS.ToString("00") + ", Overhead: " + oHeadTimeH.ToString("0") + ":" + oHeadTimeM.ToString("00") + ":" + oHeadTimeS.ToString("00") + ")", Styles.LabelStyle);
                        }
                    }
                }
                string deviceName = Lightmapping.GetLightmapBakeGPUDeviceName();
                if (deviceName.Length > 0)
                {
                    GUILayout.Label("Baking device: " + deviceName, Styles.LabelStyle);
                }
                GUILayout.EndVertical();
            }

            GUILayout.EndVertical();
        }
コード例 #13
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);
        }
コード例 #14
0
        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;
        }
コード例 #15
0
        private static Texture2D BuildPreviewTexture(int width, int height, Sprite sprite, Material spriteRendererMaterial)
        {
            if (!ShaderUtil.hardwareSupportsRectRenderTexture)
            {
                return(null);
            }
            float     num           = sprite.rect.width;
            float     num2          = sprite.rect.height;
            Texture2D spriteTexture = UnityEditor.Sprites.SpriteUtility.GetSpriteTexture(sprite, false);

            PreviewHelpers.AdjustWidthAndHeightForStaticPreview((int)num, (int)num2, ref width, ref height);
            EditorUtility.SetTemporarilyAllowIndieRenderTexture(true);
            SavedRenderTargetState state = new SavedRenderTargetState();
            RenderTexture          temp  = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Default);

            RenderTexture.active = temp;
            GL.sRGBWrite         = QualitySettings.activeColorSpace == ColorSpace.Linear;
            GL.Clear(true, true, new Color(0f, 0f, 0f, 0f));
            Texture texture = null;
            Vector4 vector  = new Vector4(0f, 0f, 0f, 0f);
            bool    flag    = false;
            bool    flag2   = false;

            if (spriteRendererMaterial != null)
            {
                flag  = spriteRendererMaterial.HasProperty("_MainTex");
                flag2 = spriteRendererMaterial.HasProperty("_MainTex_TexelSize");
            }
            Material material = null;

            if (spriteRendererMaterial != null)
            {
                if (flag)
                {
                    texture = spriteRendererMaterial.GetTexture("_MainTex");
                    spriteRendererMaterial.SetTexture("_MainTex", spriteTexture);
                }
                if (flag2)
                {
                    vector = spriteRendererMaterial.GetVector("_MainTex_TexelSize");
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", TextureUtil.GetTexelSizeVector(spriteTexture));
                }
                spriteRendererMaterial.SetPass(0);
            }
            else
            {
                material = new Material(Shader.Find("Hidden/BlitCopy"))
                {
                    mainTexture = spriteTexture
                };
                material.SetPass(0);
            }
            float num3 = sprite.rect.width / sprite.bounds.size.x;

            Vector2[] vertices  = sprite.vertices;
            Vector2[] uv        = sprite.uv;
            ushort[]  triangles = sprite.triangles;
            Vector2   pivot     = sprite.pivot;

            GL.PushMatrix();
            GL.LoadOrtho();
            GL.Color(new Color(1f, 1f, 1f, 1f));
            GL.Begin(4);
            for (int i = 0; i < sprite.triangles.Length; i++)
            {
                ushort  index   = triangles[i];
                Vector2 vector3 = vertices[index];
                Vector2 vector4 = uv[index];
                GL.TexCoord(new Vector3(vector4.x, vector4.y, 0f));
                GL.Vertex3(((vector3.x * num3) + pivot.x) / num, ((vector3.y * num3) + pivot.y) / num2, 0f);
            }
            GL.End();
            GL.PopMatrix();
            GL.sRGBWrite = false;
            if (spriteRendererMaterial != null)
            {
                if (flag)
                {
                    spriteRendererMaterial.SetTexture("_MainTex", texture);
                }
                if (flag2)
                {
                    spriteRendererMaterial.SetVector("_MainTex_TexelSize", vector);
                }
            }
            Texture2D textured2 = new Texture2D(width, height, TextureFormat.ARGB32, false)
            {
                hideFlags = HideFlags.HideAndDontSave
            };

            textured2.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0);
            textured2.Apply();
            RenderTexture.ReleaseTemporary(temp);
            state.Restore();
            EditorUtility.SetTemporarilyAllowIndieRenderTexture(false);
            if (material != null)
            {
                UnityEngine.Object.DestroyImmediate(material);
            }
            return(textured2);
        }
コード例 #16
0
        public override void OnInspectorGUI()
        {
            if (m_Images == null)
            {
                InitTexturesFromCubemap();
            }

            EditorGUIUtility.labelWidth = 50;
            var c = target as Cubemap;

            if (c == null)
            {
                return;
            }

            GUILayout.BeginVertical();

            GUILayout.BeginHorizontal();
            ShowFace("Right\n(+X)", CubemapFace.PositiveX);
            ShowFace("Left\n(-X)", CubemapFace.NegativeX);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            ShowFace("Top\n(+Y)", CubemapFace.PositiveY);
            ShowFace("Bottom\n(-Y)", CubemapFace.NegativeY);
            GUILayout.EndHorizontal();

            GUILayout.BeginHorizontal();
            ShowFace("Front\n(+Z)", CubemapFace.PositiveZ);
            ShowFace("Back\n(-Z)", CubemapFace.NegativeZ);
            GUILayout.EndHorizontal();

            GUILayout.EndVertical();

            EditorGUIUtility.labelWidth = 0;

            EditorGUILayout.Space();

            EditorGUI.BeginChangeCheck();

            EditorGUILayout.HelpBox("Lowering face size is a destructive operation, you might need to re-assign the textures later to fix resolution issues. It's preferable to use Cubemap texture import type instead of Legacy Cubemap assets.", MessageType.Warning);
            int faceSize = TextureUtil.GetGPUWidth(c);

            faceSize = EditorGUILayout.IntPopup("Face size", faceSize, kSizes, kSizesValues);

            int  mipMaps   = TextureUtil.GetMipmapCount(c);
            bool useMipMap = EditorGUILayout.Toggle("MipMaps", mipMaps > 1);

            bool streamingMipmaps = TextureUtil.GetCubemapStreamingMipmaps(c);

            if (useMipMap)
            {
                streamingMipmaps = EditorGUILayout.Toggle(EditorGUIUtility.TrTextContent("Streaming Mipmaps", "Don't load image data immediately but wait till image data is requested from script."), streamingMipmaps);
            }

            bool linear = TextureUtil.GetLinearSampled(c);

            linear = EditorGUILayout.Toggle("Linear", linear);

            bool readable = TextureUtil.IsCubemapReadable(c);

            readable = EditorGUILayout.Toggle("Readable", readable);

            if (EditorGUI.EndChangeCheck())
            {
                // reformat the cubemap
                if (TextureUtil.ReformatCubemap(c, faceSize, faceSize, c.format, useMipMap, linear))
                {
                    InitTexturesFromCubemap();
                }

                TextureUtil.MarkCubemapReadable(c, readable);
                TextureUtil.SetCubemapStreamingMipmaps(c, streamingMipmaps);
                c.Apply();
            }
        }
コード例 #17
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);
        }
コード例 #18
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;
     }
 }
コード例 #19
0
        public override string GetInfoString()
        {
            Texture3D target = this.target as Texture3D;

            return(string.Format("{0}x{1}x{2} {3} {4}", (object)target.width, (object)target.height, (object)target.depth, (object)TextureUtil.GetTextureFormatString(target.format), (object)EditorUtility.FormatBytes(TextureUtil.GetRuntimeMemorySize((Texture)target))));
        }
コード例 #20
0
 private bool RenderTextureHasDepth()
 {
     return(TextureUtil.IsDepthRTFormat((RenderTextureFormat)this.m_ColorFormat.enumValueIndex) || (this.m_DepthFormat.enumValueIndex != 0));
 }
コード例 #21
0
        public static bool IsNormalMap(Texture t)
        {
            TextureUsageMode usageMode = TextureUtil.GetUsageMode(t);

            return(usageMode == TextureUsageMode.NormalmapPlain || usageMode == TextureUsageMode.NormalmapDXT5nm);
        }
コード例 #22
0
        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);
            }
        }
コード例 #23
0
        public override string GetInfoString()
        {
            var tex  = (Texture2DArray)target;
            var info = $"{tex.width}x{tex.height} {tex.depth} slice{(tex.depth != 1 ? "s" : "")} {TextureUtil.GetTextureFormatString(tex.format)} {EditorUtility.FormatBytes(TextureUtil.GetRuntimeMemorySizeLong(tex))}";

            return(info);
        }
コード例 #24
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }

            // show texture
            Texture t = target as Texture;

            if (t == null) // texture might be gone by now, in case this code is used for floating texture preview
            {
                return;
            }

            // Render target must be created before we can display it (case 491797)
            RenderTexture rt = t as RenderTexture;

            if (rt != null)
            {
                if (!SystemInfo.IsFormatSupported(rt.graphicsFormat, FormatUsage.Render))
                {
                    return; // can't do this RT format
                }
                rt.Create();
            }

            if (IsCubemap())
            {
                m_CubemapPreview.OnPreviewGUI(t, r, background);
                return;
            }

            // target can report zero sizes in some cases just after a parameter change;
            // guard against that.
            int texWidth  = Mathf.Max(t.width, 1);
            int texHeight = Mathf.Max(t.height, 1);

            float mipLevel   = GetMipLevelForRendering();
            float zoomLevel  = Mathf.Min(Mathf.Min(r.width / texWidth, r.height / texHeight), 1);
            Rect  wantedRect = new Rect(r.x, r.y, texWidth * zoomLevel, texHeight * zoomLevel);

            PreviewGUI.BeginScrollView(r, m_Pos, wantedRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
            FilterMode oldFilter = t.filterMode;

            TextureUtil.SetFilterModeNoDirty(t, FilterMode.Point);
            Texture2D      t2d            = t as Texture2D;
            ColorWriteMask colorWriteMask = ColorWriteMask.All;

            switch (m_PreviewMode)
            {
            case PreviewMode.R:
                colorWriteMask = ColorWriteMask.Red | ColorWriteMask.Alpha;
                break;

            case PreviewMode.G:
                colorWriteMask = ColorWriteMask.Green | ColorWriteMask.Alpha;
                break;

            case PreviewMode.B:
                colorWriteMask = ColorWriteMask.Blue | ColorWriteMask.Alpha;
                break;
            }

            if (m_PreviewMode == PreviewMode.A)
            {
                EditorGUI.DrawTextureAlpha(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel);
            }
            else
            {
                if (t2d != null && t2d.alphaIsTransparency)
                {
                    EditorGUI.DrawTextureTransparent(wantedRect, t, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask);
                }
                else
                {
                    EditorGUI.DrawPreviewTexture(wantedRect, t, null, ScaleMode.StretchToFill, 0, mipLevel, colorWriteMask);
                }
            }

            // TODO: Less hacky way to prevent sprite rects to not appear in smaller previews like icons.
            if ((wantedRect.width > 32 && wantedRect.height > 32) && Event.current.type == EventType.Repaint)
            {
                string           path            = AssetDatabase.GetAssetPath(t);
                TextureImporter  textureImporter = AssetImporter.GetAtPath(path) as TextureImporter;
                SpriteMetaData[] spritesheet     = textureImporter != null ? textureImporter.spritesheet : null;

                if (spritesheet != null && textureImporter.spriteImportMode == SpriteImportMode.Multiple)
                {
                    Rect screenRect = new Rect();
                    Rect sourceRect = new Rect();
                    GUI.CalculateScaledTextureRects(wantedRect, ScaleMode.StretchToFill, (float)t.width / (float)t.height, ref screenRect, ref sourceRect);

                    int origWidth  = t.width;
                    int origHeight = t.height;
                    textureImporter.GetWidthAndHeight(ref origWidth, ref origHeight);
                    float definitionScale = (float)t.width / (float)origWidth;

                    HandleUtility.ApplyWireMaterial();
                    GL.PushMatrix();
                    GL.MultMatrix(Handles.matrix);
                    GL.Begin(GL.LINES);
                    GL.Color(new Color(1f, 1f, 1f, 0.5f));
                    foreach (SpriteMetaData sprite in spritesheet)
                    {
                        Rect spriteRect       = sprite.rect;
                        Rect spriteScreenRect = new Rect();
                        spriteScreenRect.xMin = screenRect.xMin + screenRect.width * (spriteRect.xMin / t.width * definitionScale);
                        spriteScreenRect.xMax = screenRect.xMin + screenRect.width * (spriteRect.xMax / t.width * definitionScale);
                        spriteScreenRect.yMin = screenRect.yMin + screenRect.height * (1f - spriteRect.yMin / t.height * definitionScale);
                        spriteScreenRect.yMax = screenRect.yMin + screenRect.height * (1f - spriteRect.yMax / t.height * definitionScale);
                        DrawRect(spriteScreenRect);
                    }
                    GL.End();
                    GL.PopMatrix();
                }
            }

            TextureUtil.SetFilterModeNoDirty(t, oldFilter);

            m_Pos = PreviewGUI.EndScrollView();
            if (mipLevel != 0)
            {
                EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20), "Mip " + mipLevel);
            }
        }
コード例 #25
0
        private void OnGUI()
        {
            EditorGUIUtility.labelWidth = (base.position.width - 64f) - 20f;
            bool flag = true;

            this.m_ScrollPosition = EditorGUILayout.BeginVerticalScrollView(this.m_ScrollPosition, false, GUI.skin.verticalScrollbar, GUI.skin.scrollView, new GUILayoutOption[0]);
            flag &= this.ValidateTerrain();
            EditorGUI.BeginChangeCheck();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            string label           = "";
            float  alignmentOffset = 0f;

            switch (this.m_Terrain.materialType)
            {
            case Terrain.MaterialType.BuiltInStandard:
                label           = " Albedo (RGB)\nSmoothness (A)";
                alignmentOffset = 15f;
                break;

            case Terrain.MaterialType.BuiltInLegacyDiffuse:
                label           = "\n Diffuse (RGB)";
                alignmentOffset = 15f;
                break;

            case Terrain.MaterialType.BuiltInLegacySpecular:
                label           = "Diffuse (RGB)\n   Gloss (A)";
                alignmentOffset = 12f;
                break;

            case Terrain.MaterialType.Custom:
                label           = " \n  Splat";
                alignmentOffset = 0f;
                break;
            }
            TextureFieldGUI(label, ref this.m_Texture, alignmentOffset);
            TextureFieldGUI("\nNormal", ref this.m_NormalMap, -4f);
            GUILayout.FlexibleSpace();
            GUILayout.EndHorizontal();
            flag &= this.ValidateMainTexture(this.m_Texture);
            if (flag)
            {
                if (IsUsingMetallic(this.m_Terrain.materialType, this.m_Terrain.materialTemplate))
                {
                    EditorGUILayout.Space();
                    float labelWidth = EditorGUIUtility.labelWidth;
                    EditorGUIUtility.labelWidth = 75f;
                    this.m_Metallic             = EditorGUILayout.Slider("Metallic", this.m_Metallic, 0f, 1f, new GUILayoutOption[0]);
                    EditorGUIUtility.labelWidth = labelWidth;
                }
                else if (IsUsingSpecular(this.m_Terrain.materialType, this.m_Terrain.materialTemplate))
                {
                    this.m_Specular = EditorGUILayout.ColorField("Specular", this.m_Specular, new GUILayoutOption[0]);
                }
                if (IsUsingSmoothness(this.m_Terrain.materialType, this.m_Terrain.materialTemplate) && !TextureUtil.HasAlphaTextureFormat(this.m_Texture.format))
                {
                    EditorGUILayout.Space();
                    float num3 = EditorGUIUtility.labelWidth;
                    EditorGUIUtility.labelWidth = 75f;
                    this.m_Smoothness           = EditorGUILayout.Slider("Smoothness", this.m_Smoothness, 0f, 1f, new GUILayoutOption[0]);
                    EditorGUIUtility.labelWidth = num3;
                }
            }
            SplatSizeGUI(ref this.m_TileSize, ref this.m_TileOffset);
            bool flag2 = EditorGUI.EndChangeCheck();

            EditorGUILayout.EndScrollView();
            GUILayout.FlexibleSpace();
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.FlexibleSpace();
            GUI.enabled = flag;
            GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MinWidth(100f) };
            if (GUILayout.Button(this.m_ButtonTitle, options))
            {
                this.ApplyTerrainSplat();
                base.Close();
                GUIUtility.ExitGUI();
            }
            GUI.enabled = true;
            GUILayout.EndHorizontal();
            if ((flag2 && flag) && (this.m_Index != -1))
            {
                this.ApplyTerrainSplat();
            }
        }
コード例 #26
0
        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);
        }
コード例 #27
0
 // For mip maps we render by default with mipLevel 0 but allow for
 public float GetMipLevelForRendering(Texture texture)
 {
     return(Mathf.Min(m_MipLevel, TextureUtil.GetMipmapCount(texture)));
 }
コード例 #28
0
        public override void OnPreviewGUI(Rect r, GUIStyle background)
        {
            if (Event.current.type == EventType.Repaint)
            {
                background.Draw(r, false, false, false, false);
            }
            Texture       target   = base.target as Texture;
            RenderTexture texture2 = target as RenderTexture;

            if (texture2 != null)
            {
                if (!SystemInfo.SupportsRenderTextureFormat(texture2.format))
                {
                    return;
                }
                texture2.Create();
            }
            if (this.IsCubemap())
            {
                this.m_CubemapPreview.OnPreviewGUI(target, r, background);
            }
            else
            {
                int   num  = Mathf.Max(target.width, 1);
                int   num2 = Mathf.Max(target.height, 1);
                float mipLevelForRendering = this.GetMipLevelForRendering();
                float num4     = Mathf.Min(Mathf.Min((float)(r.width / ((float)num)), (float)(r.height / ((float)num2))), 1f);
                Rect  viewRect = new Rect(r.x, r.y, num * num4, num2 * num4);
                PreviewGUI.BeginScrollView(r, this.m_Pos, viewRect, "PreHorizontalScrollbar", "PreHorizontalScrollbarThumb");
                float mipMapBias = target.mipMapBias;
                TextureUtil.SetMipMapBiasNoDirty(target, mipLevelForRendering - this.Log2(((float)num) / viewRect.width));
                UnityEngine.FilterMode filterMode = target.filterMode;
                TextureUtil.SetFilterModeNoDirty(target, UnityEngine.FilterMode.Point);
                if (this.m_ShowAlpha)
                {
                    EditorGUI.DrawTextureAlpha(viewRect, target);
                }
                else
                {
                    Texture2D textured = target as Texture2D;
                    if ((textured != null) && textured.alphaIsTransparency)
                    {
                        EditorGUI.DrawTextureTransparent(viewRect, target);
                    }
                    else
                    {
                        EditorGUI.DrawPreviewTexture(viewRect, target);
                    }
                }
                if ((viewRect.width > 32f) && (viewRect.height > 32f))
                {
                    TextureImporter  atPath      = AssetImporter.GetAtPath(AssetDatabase.GetAssetPath(target)) as TextureImporter;
                    SpriteMetaData[] spritesheet = atPath?.spritesheet;
                    if ((spritesheet != null) && (atPath.spriteImportMode == SpriteImportMode.Multiple))
                    {
                        Rect outScreenRect = new Rect();
                        Rect outSourceRect = new Rect();
                        GUI.CalculateScaledTextureRects(viewRect, ScaleMode.StretchToFill, ((float)target.width) / ((float)target.height), ref outScreenRect, ref outSourceRect);
                        int width  = target.width;
                        int height = target.height;
                        atPath.GetWidthAndHeight(ref width, ref height);
                        float num8 = ((float)target.width) / ((float)width);
                        HandleUtility.ApplyWireMaterial();
                        GL.PushMatrix();
                        GL.MultMatrix(Handles.matrix);
                        GL.Begin(1);
                        GL.Color(new Color(1f, 1f, 1f, 0.5f));
                        foreach (SpriteMetaData data in spritesheet)
                        {
                            Rect rect  = data.rect;
                            Rect rect5 = new Rect {
                                xMin = outScreenRect.xMin + (outScreenRect.width * ((rect.xMin / ((float)target.width)) * num8)),
                                xMax = outScreenRect.xMin + (outScreenRect.width * ((rect.xMax / ((float)target.width)) * num8)),
                                yMin = outScreenRect.yMin + (outScreenRect.height * (1f - ((rect.yMin / ((float)target.height)) * num8))),
                                yMax = outScreenRect.yMin + (outScreenRect.height * (1f - ((rect.yMax / ((float)target.height)) * num8)))
                            };
                            this.DrawRect(rect5);
                        }
                        GL.End();
                        GL.PopMatrix();
                    }
                }
                TextureUtil.SetMipMapBiasNoDirty(target, mipMapBias);
                TextureUtil.SetFilterModeNoDirty(target, filterMode);
                this.m_Pos = PreviewGUI.EndScrollView();
                if (mipLevelForRendering != 0f)
                {
                    EditorGUI.DropShadowLabel(new Rect(r.x, r.y, r.width, 20f), "Mip " + mipLevelForRendering);
                }
            }
        }
コード例 #29
0
        private void Summary()
        {
            GUILayout.BeginVertical(EditorStyles.helpBox, new GUILayoutOption[0]);
            int num  = 0;
            int num2 = 0;
            Dictionary <Vector2, int> dictionary = new Dictionary <Vector2, int>();
            bool flag = false;

            LightmapData[] lightmaps = LightmapSettings.lightmaps;
            for (int i = 0; i < lightmaps.Length; i++)
            {
                LightmapData lightmapData = lightmaps[i];
                if (!(lightmapData.lightmapFar == null))
                {
                    num2++;
                    Vector2 vector = new Vector2((float)lightmapData.lightmapFar.width, (float)lightmapData.lightmapFar.height);
                    if (dictionary.ContainsKey(vector))
                    {
                        Dictionary <Vector2, int> dictionary2;
                        Dictionary <Vector2, int> expr_7C = dictionary2 = dictionary;
                        Vector2 key;
                        Vector2 expr_81 = key = vector;
                        int     num3    = dictionary2[key];
                        expr_7C[expr_81] = num3 + 1;
                    }
                    else
                    {
                        dictionary.Add(vector, 1);
                    }
                    num += TextureUtil.GetStorageMemorySize(lightmapData.lightmapFar);
                    if (lightmapData.lightmapNear)
                    {
                        num += TextureUtil.GetStorageMemorySize(lightmapData.lightmapNear);
                        flag = true;
                    }
                }
            }
            string text = string.Concat(new object[]
            {
                num2,
                (!flag) ? " non-directional" : " directional",
                " lightmap",
                (num2 != 1) ? "s" : string.Empty
            });
            bool flag2 = true;

            foreach (KeyValuePair <Vector2, int> current in dictionary)
            {
                text += ((!flag2) ? ", " : ": ");
                flag2 = false;
                if (current.Value > 1)
                {
                    text = text + current.Value + "x";
                }
                string text2 = text;
                text = string.Concat(new object[]
                {
                    text2,
                    current.Key.x,
                    "x",
                    current.Key.y,
                    "px"
                });
            }
            GUILayout.BeginHorizontal(new GUILayoutOption[0]);
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Label(text + " ", LightingWindow.styles.labelStyle, new GUILayoutOption[0]);
            GUILayout.EndVertical();
            GUILayout.BeginVertical(new GUILayoutOption[0]);
            GUILayout.Label(EditorUtility.FormatBytes(num), LightingWindow.styles.labelStyle, new GUILayoutOption[0]);
            GUILayout.Label((num2 != 0) ? string.Empty : "No Lightmaps", LightingWindow.styles.labelStyle, new GUILayoutOption[0]);
            GUILayout.EndVertical();
            GUILayout.EndHorizontal();
            GUILayout.EndVertical();
        }
コード例 #30
0
 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;
     }
 }