UnityEditor.TextureInspector.OnPreviewSettings C# (CSharp) Method

OnPreviewSettings() public method

public OnPreviewSettings ( ) : void
return void
        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;
            }
        }

Usage Example

        public override void OnPreviewSettings()
        {
            if (!ValidPreviewSetup())
            {
                return;
            }

            m_CubemapEditor.mipLevel = m_MipLevelPreview;

            EditorGUI.BeginChangeCheck();
            m_CubemapEditor.OnPreviewSettings();
            // Need to repaint, because mipmap value changes affect reflection probe preview in the scene
            if (EditorGUI.EndChangeCheck())
            {
                EditorApplication.SetSceneRepaintDirty();
                m_MipLevelPreview = m_CubemapEditor.mipLevel;
            }
        }