示例#1
0
 public void OnExposureSlider()
 {
     if (s_Styles == null)
     {
         s_Styles = new Styles();
     }
     m_ExposureSliderValue = EditorGUIInternal.ExposureSlider(m_ExposureSliderValue, ref m_ExposureSliderMax, s_Styles.previewSlider);
 }
        private void DrawPreviewSettings()
        {
            using (new EditorGUI.DisabledScope(!SelectedTextureTypeNeedsExposureControl()))
            {
                m_ExposureSliderValue = EditorGUIInternal.ExposureSlider(m_ExposureSliderValue, ref m_ExposureSliderMax, EditorStyles.toolbarSlider);
            }

            m_ShowUVOverlay = GUILayout.Toggle(m_ShowUVOverlay, Styles.UVOverlayIcon, EditorStyles.toolbarButton);

            Rect dropRect = GUILayoutUtility.GetRect(14, 160, EditorGUI.kWindowToolbarHeight, EditorGUI.kWindowToolbarHeight);

            GUIContent[]    options = isRealtimeLightmap ? Styles.RealtimePreviewTextureOptions : Styles.BakedPreviewTextureOptions;
            GITextureType[] types   = isRealtimeLightmap ? kRealtimePreviewTextureTypes : kBakedPreviewTextureTypes;

            if ((m_SelectedPreviewTextureOptionIndex < 0 || m_SelectedPreviewTextureOptionIndex >= options.Length) || !LightmapVisualizationUtility.IsTextureTypeEnabled(types[m_SelectedPreviewTextureOptionIndex]))
            {
                m_SelectedPreviewTextureOptionIndex = 0;
            }

            if (EditorGUI.DropdownButton(dropRect, options[m_SelectedPreviewTextureOptionIndex], FocusType.Passive, EditorStyles.toolbarDropDownRight))
            {
                GenericMenu menu = new GenericMenu();

                for (int i = 0; i < options.Length; i++)
                {
                    if (LightmapVisualizationUtility.IsTextureTypeEnabled(types[i]))
                    {
                        menu.AddItem(options[i], m_SelectedPreviewTextureOptionIndex == i, SelectPreviewTextureIndex, options.ElementAt(i));
                    }
                    else
                    {
                        menu.AddDisabledItem(options.ElementAt(i));
                    }
                }
                menu.DropDown(dropRect);
            }
        }
        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;
            bool needsExposureControl = false;
            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;
                }

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

                if (t is Texture2D)
                {
                    TextureFormat    format = (t as Texture2D).format;
                    TextureUsageMode mode   = TextureUtil.GetUsageMode(t);

                    if (!TextureUtil.IsAlphaOnlyTextureFormat(format))
                    {
                        alphaOnly = false;
                    }

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

                    if (TextureUtil.NeedsExposureControl(t))
                    {
                        needsExposureControl = true;
                    }
                }
            }

            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 (needsExposureControl)
            {
                m_ExposureSliderValue = EditorGUIInternal.ExposureSlider(m_ExposureSliderValue, ref m_ExposureSliderMax, s_Styles.previewSlider);
            }

            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);
            }
        }
示例#4
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;
            bool needsExposureControl = 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;
                        }
                    }

                    if (TextureUtil.NeedsExposureControl(t2))
                    {
                        needsExposureControl = 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);
                }
            }

            if (needsExposureControl)
            {
                m_ExposureSliderValue = EditorGUIInternal.ExposureSlider(m_ExposureSliderValue, ref m_ExposureSliderMax, Styles.preSlider);
            }

            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;
        }