protected Rect DoAlphaZoomToolbarGUI(Rect area) { int num = 1; if (this.m_Texture != null) { num = Mathf.Max(num, TextureUtil.GetMipmapCount(this.m_Texture)); } Rect position = new Rect(area.width, 0f, 0f, area.height); using (new EditorGUI.DisabledScope(num == 1)) { position.width = (float)this.m_Styles.largeMip.image.width; position.x -= position.width; GUI.Box(position, this.m_Styles.largeMip, this.m_Styles.preLabel); position.width = 60f; position.x -= position.width; this.m_MipLevel = Mathf.Round(GUI.HorizontalSlider(position, this.m_MipLevel, (float)(num - 1), 0f, this.m_Styles.preSlider, this.m_Styles.preSliderThumb)); position.width = (float)this.m_Styles.smallMip.image.width; position.x -= position.width; GUI.Box(position, this.m_Styles.smallMip, this.m_Styles.preLabel); } position.width = 60f; position.x -= position.width; this.m_Zoom = GUI.HorizontalSlider(position, this.m_Zoom, this.GetMinZoom(), 50f, this.m_Styles.preSlider, this.m_Styles.preSliderThumb); position.width = 32f; position.x -= position.width + 5f; this.m_ShowAlpha = GUI.Toggle(position, this.m_ShowAlpha, (!this.m_ShowAlpha) ? this.m_Styles.RGBIcon : this.m_Styles.alphaIcon, "toolbarButton"); return(new Rect(area.x, area.y, position.x, area.height)); }
public void OnPreviewSettings(UnityEngine.Object[] targets) { if (ShaderUtil.hardwareSupportsRectRenderTexture) { GUI.enabled = true; this.InitPreview(); bool flag = true; bool flag2 = true; bool flag3 = false; int a = 8; foreach (Texture texture in targets) { a = Mathf.Max(a, TextureUtil.GetMipmapCount(texture)); Cubemap cubemap = texture as Cubemap; if (cubemap != null) { TextureFormat format = cubemap.format; if (!TextureUtil.IsAlphaOnlyTextureFormat(format)) { flag2 = false; } if (TextureUtil.HasAlphaTextureFormat(format) && (TextureUtil.GetUsageMode(texture) == TextureUsageMode.Default)) { flag3 = true; } } else { flag3 = true; flag2 = false; } } if (flag2) { this.m_PreviewType = PreviewType.Alpha; flag = false; } else if (!flag3) { this.m_PreviewType = PreviewType.RGB; flag = false; } if (flag) { GUIContent[] contentArray = new GUIContent[] { Styles.RGBIcon, Styles.alphaIcon }; int previewType = (int)this.m_PreviewType; if (GUILayout.Button(contentArray[previewType], Styles.preButton, new GUILayoutOption[0])) { this.m_PreviewType = (PreviewType)(++previewType % contentArray.Length); } } GUI.enabled = a != 1; GUILayout.Box(Styles.smallZoom, Styles.preLabel, new GUILayoutOption[0]); GUI.changed = false; GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth(64f) }; this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(a - 1), 0f, Styles.preSlider, Styles.preSliderThumb, options)); GUILayout.Box(Styles.largeZoom, Styles.preLabel, new GUILayoutOption[0]); GUI.enabled = true; } }
protected void DrawTexture() { int num = Mathf.Max(this.m_Texture.width, 1); float num2 = Mathf.Min(this.m_MipLevel, (float)(TextureUtil.GetMipmapCount(this.m_Texture) - 1)); float mipMapBias = this.m_Texture.mipMapBias; TextureUtil.SetMipMapBiasNoDirty(this.m_Texture, num2 - this.Log2((float)num / this.m_TextureRect.width)); FilterMode filterMode = this.m_Texture.filterMode; TextureUtil.SetFilterModeNoDirty(this.m_Texture, FilterMode.Point); if (this.m_ShowAlpha) { if (this.m_TextureAlphaOverride != null) { EditorGUI.DrawTextureTransparent(this.m_TextureRect, this.m_TextureAlphaOverride); } else { EditorGUI.DrawTextureAlpha(this.m_TextureRect, this.m_Texture); } } else { EditorGUI.DrawTextureTransparent(this.m_TextureRect, this.m_Texture); } TextureUtil.SetMipMapBiasNoDirty(this.m_Texture, mipMapBias); TextureUtil.SetFilterModeNoDirty(this.m_Texture, filterMode); }
protected void DrawTexture() { float mipLevel = Mathf.Min(m_MipLevel, TextureUtil.GetMipmapCount(m_Texture) - 1); FilterMode oldFilter = m_Texture.filterMode; TextureUtil.SetFilterModeNoDirty(m_Texture, FilterMode.Point); if (m_ShowAlpha) { // check if we have a valid alpha texture if (m_TextureAlphaOverride != null) { EditorGUI.DrawTextureTransparent(m_TextureRect, m_TextureAlphaOverride, ScaleMode.StretchToFill, 0, mipLevel); } // else use the original texture and display its alpha else { EditorGUI.DrawTextureAlpha(m_TextureRect, m_Texture, ScaleMode.StretchToFill, 0, mipLevel); } } else { EditorGUI.DrawTextureTransparent(m_TextureRect, m_Texture, ScaleMode.StretchToFill, 0, mipLevel); } TextureUtil.SetFilterModeNoDirty(m_Texture, oldFilter); }
public float GetMipLevelForRendering() { if (base.target == null) { return(0f); } if (this.IsCubemap()) { return(this.m_CubemapPreview.GetMipLevelForRendering(base.target as Texture)); } return(Mathf.Min(this.m_MipLevel, (float)(TextureUtil.GetMipmapCount(base.target as Texture) - 1))); }
public override void OnInspectorGUI() { if (this.m_Images == null) { this.InitTexturesFromCubemap(); } EditorGUIUtility.labelWidth = 50f; Cubemap cubemap = this.target as Cubemap; if (cubemap == null) { return; } GUILayout.BeginVertical(new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); this.ShowFace("Right\n(+X)", CubemapFace.PositiveX); this.ShowFace("Left\n(-X)", CubemapFace.NegativeX); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(new GUILayoutOption[0]); this.ShowFace("Top\n(+Y)", CubemapFace.PositiveY); this.ShowFace("Bottom\n(-Y)", CubemapFace.NegativeY); GUILayout.EndHorizontal(); GUILayout.BeginHorizontal(new GUILayoutOption[0]); this.ShowFace("Front\n(+Z)", CubemapFace.PositiveZ); this.ShowFace("Back\n(-Z)", CubemapFace.NegativeZ); GUILayout.EndHorizontal(); GUILayout.EndVertical(); EditorGUIUtility.labelWidth = 0f; 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 num = TextureUtil.GetGPUWidth(cubemap); num = EditorGUILayout.IntPopup("Face size", num, CubemapInspector.kSizes, CubemapInspector.kSizesValues, new GUILayoutOption[0]); int mipmapCount = TextureUtil.GetMipmapCount(cubemap); bool useMipmap = EditorGUILayout.Toggle("MipMaps", mipmapCount > 1, new GUILayoutOption[0]); bool flag = TextureUtil.GetLinearSampled(cubemap); flag = EditorGUILayout.Toggle("Linear", flag, new GUILayoutOption[0]); bool flag2 = TextureUtil.IsCubemapReadable(cubemap); flag2 = EditorGUILayout.Toggle("Readable", flag2, new GUILayoutOption[0]); if (EditorGUI.EndChangeCheck()) { if (TextureUtil.ReformatCubemap(ref cubemap, num, num, cubemap.format, useMipmap, flag)) { this.InitTexturesFromCubemap(); } TextureUtil.MarkCubemapReadable(cubemap, flag2); cubemap.Apply(); } }
public float GetMipLevelForRendering() { if (target == null) { return(0.0f); } if (IsCubemap()) { return(m_CubemapPreview.GetMipLevelForRendering(target as Texture)); } else { return(Mathf.Min(m_MipLevel, TextureUtil.GetMipmapCount(target as Texture) - 1)); } }
//VT textures can be very large and aren't in GPU memory yet. To avoid unnecessary streaming and cache use, we limit the default shown mip resolution. private void SetMipLevelDefaultForVT() { foreach (var t in targets) { var tex = t as Texture; if (EditorGUI.UseVTMaterial(tex)) { int mips = TextureUtil.GetMipmapCount(tex); const int numMipsFor1K = 11; if (mips > numMipsFor1K) { mipLevel = Mathf.Max(mipLevel, mips - numMipsFor1K); //set to 1024x1024 or less } } } }
public float GetMipLevelForRendering() { float result; if (base.target == null) { result = 0f; } else if (this.IsCubemap()) { result = this.m_CubemapPreview.GetMipLevelForRendering(base.target as Texture); } else { result = Mathf.Min(this.m_MipLevel, (float)(TextureUtil.GetMipmapCount(base.target as Texture) - 1)); } return(result); }
protected void DoAlphaZoomToolbarGUI() { this.m_ShowAlpha = GUILayout.Toggle(this.m_ShowAlpha, !this.m_ShowAlpha ? s_Styles.RGBIcon : s_Styles.alphaIcon, "toolbarButton", new GUILayoutOption[0]); GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth(64f) }; this.m_Zoom = GUILayout.HorizontalSlider(this.m_Zoom, this.GetMinZoom(), 50f, s_Styles.preSlider, s_Styles.preSliderThumb, options); int a = 1; if (this.m_Texture != null) { a = Mathf.Max(a, TextureUtil.GetMipmapCount(this.m_Texture)); } using (new EditorGUI.DisabledScope(a == 1)) { GUILayout.Box(s_Styles.smallMip, s_Styles.preLabel, new GUILayoutOption[0]); GUILayoutOption[] optionArray2 = new GUILayoutOption[] { GUILayout.MaxWidth(64f) }; this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(a - 1), 0f, s_Styles.preSlider, s_Styles.preSliderThumb, optionArray2)); GUILayout.Box(s_Styles.largeMip, s_Styles.preLabel, new GUILayoutOption[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.GetMipmapCount(this.m_Texture)); } using (new EditorGUI.DisabledScope(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]); } }
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)); }
// 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))); }
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; }
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(); } }
public override void OnPreviewSettings() { if (IsCubemap()) { m_CubemapPreview.OnPreviewSettings(targets); return; } if (s_Styles == null) { s_Styles = new Styles(); } // TextureInspector code is reused for RenderTexture and Cubemap inspectors. // Make sure we can handle the situation where target is just a Texture and // not a Texture2D. It's also used for large popups for mini texture fields, // and while it's being shown the actual texture object might disappear -- // make sure to handle null targets. Texture tex = target as Texture; bool showMode = true; bool alphaOnly = false; bool hasAlpha = true; int mipCount = 1; if (target is Texture2D) { alphaOnly = true; hasAlpha = false; } foreach (Texture t in targets) { if (t == null) // texture might have disappeared while we're showing this in a preview popup { continue; } TextureFormat format = 0; bool checkFormat = false; if (t is Texture2D) { format = (t as Texture2D).format; checkFormat = true; } if (checkFormat) { if (!TextureUtil.IsAlphaOnlyTextureFormat(format)) { alphaOnly = false; } if (TextureUtil.HasAlphaTextureFormat(format)) { TextureUsageMode mode = TextureUtil.GetUsageMode(t); if (mode == TextureUsageMode.Default) // all other texture usage modes don't displayable alpha { hasAlpha = true; } } } mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(t)); } if (alphaOnly) { m_ShowAlpha = true; showMode = false; } else if (!hasAlpha) { m_ShowAlpha = false; showMode = false; } if (showMode && tex != null && !IsNormalMap(tex)) { m_ShowAlpha = GUILayout.Toggle(m_ShowAlpha, m_ShowAlpha ? s_Styles.alphaIcon : s_Styles.RGBIcon, s_Styles.previewButton); } if (mipCount > 1) { GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel); GUI.changed = false; m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.MaxWidth(64))); GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel); } }
public override void OnPreviewSettings() { if (this.IsCubemap()) { this.m_CubemapPreview.OnPreviewSettings(base.targets); } else { if (TextureInspector.s_Styles == null) { TextureInspector.s_Styles = new TextureInspector.Styles(); } Texture texture = base.target as Texture; bool flag = true; bool flag2 = false; bool flag3 = true; int num = 1; if (base.target is Texture2D || base.target is ProceduralTexture) { flag2 = true; flag3 = false; } UnityEngine.Object[] targets = base.targets; for (int i = 0; i < targets.Length; i++) { Texture texture2 = (Texture)targets[i]; if (!(texture2 == null)) { TextureFormat format = (TextureFormat)0; bool flag4 = false; if (texture2 is Texture2D) { format = (texture2 as Texture2D).format; flag4 = true; } else if (texture2 is ProceduralTexture) { format = (texture2 as ProceduralTexture).format; flag4 = true; } if (flag4) { if (!TextureUtil.IsAlphaOnlyTextureFormat(format)) { flag2 = false; } if (TextureUtil.HasAlphaTextureFormat(format)) { if (TextureUtil.GetUsageMode(texture2) == TextureUsageMode.Default) { flag3 = true; } } } num = Mathf.Max(num, TextureUtil.GetMipmapCount(texture2)); } } if (flag2) { this.m_ShowAlpha = true; flag = false; } else if (!flag3) { this.m_ShowAlpha = false; flag = false; } if (flag && texture != null && !TextureInspector.IsNormalMap(texture)) { this.m_ShowAlpha = GUILayout.Toggle(this.m_ShowAlpha, (!this.m_ShowAlpha) ? TextureInspector.s_Styles.RGBIcon : TextureInspector.s_Styles.alphaIcon, TextureInspector.s_Styles.previewButton, new GUILayoutOption[0]); } GUI.enabled = (num != 1); GUILayout.Box(TextureInspector.s_Styles.smallZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]); GUI.changed = false; this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(num - 1), 0f, TextureInspector.s_Styles.previewSlider, TextureInspector.s_Styles.previewSliderThumb, new GUILayoutOption[] { GUILayout.MaxWidth(64f) })); GUILayout.Box(TextureInspector.s_Styles.largeZoom, TextureInspector.s_Styles.previewLabel, new GUILayoutOption[0]); GUI.enabled = true; } }
public override void OnPreviewSettings() { if (this.IsCubemap()) { this.m_CubemapPreview.OnPreviewSettings(base.targets); } else { if (s_Styles == null) { s_Styles = new Styles(); } Texture target = base.target as Texture; bool flag = true; bool flag2 = false; bool flag3 = true; int a = 1; if ((base.target is Texture2D) || (base.target is ProceduralTexture)) { flag2 = true; flag3 = false; } foreach (Texture texture2 in base.targets) { TextureFormat format = (TextureFormat)0; bool flag4 = false; if (texture2 is Texture2D) { format = (texture2 as Texture2D).format; flag4 = true; } else if (texture2 is ProceduralTexture) { format = (texture2 as ProceduralTexture).format; flag4 = true; } if (flag4) { if (!TextureUtil.IsAlphaOnlyTextureFormat(format)) { flag2 = false; } if (TextureUtil.HasAlphaTextureFormat(format) && (TextureUtil.GetUsageMode(texture2) == TextureUsageMode.Default)) { flag3 = true; } } a = Mathf.Max(a, TextureUtil.GetMipmapCount(texture2)); } if (flag2) { this.m_ShowAlpha = true; flag = false; } else if (!flag3) { this.m_ShowAlpha = false; flag = false; } if (flag && !IsNormalMap(target)) { this.m_ShowAlpha = GUILayout.Toggle(this.m_ShowAlpha, !this.m_ShowAlpha ? s_Styles.RGBIcon : s_Styles.alphaIcon, s_Styles.previewButton, new GUILayoutOption[0]); } GUI.enabled = a != 1; GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel, new GUILayoutOption[0]); GUI.changed = false; GUILayoutOption[] options = new GUILayoutOption[] { GUILayout.MaxWidth(64f) }; this.m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(this.m_MipLevel, (float)(a - 1), 0f, s_Styles.previewSlider, s_Styles.previewSliderThumb, options)); GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel, new GUILayoutOption[0]); GUI.enabled = true; } }
public float GetMipLevelForRendering(Texture texture) => Mathf.Min(this.m_MipLevel, (float)TextureUtil.GetMipmapCount(texture));
public override void OnPreviewSettings() { if (IsCubemap()) { m_CubemapPreview.OnPreviewSettings(targets); return; } if (IsTexture2DArray() && !SystemInfo.supports2DArrayTextures) { return; } if (s_Styles == null) { s_Styles = new Styles(); } // TextureInspector code is reused for RenderTexture and Cubemap inspectors. // Make sure we can handle the situation where target is just a Texture and // not a Texture2D. It's also used for large popups for mini texture fields, // and while it's being shown the actual texture object might disappear -- // make sure to handle null targets. Texture tex = target as Texture; bool alphaOnly = false; bool hasAlpha = true; int mipCount = 1; if (target is Texture2D) { alphaOnly = true; hasAlpha = false; } foreach (Texture t in targets) { if (t == null) // texture might have disappeared while we're showing this in a preview popup { continue; } TextureFormat format = 0; bool checkFormat = false; if (t is Texture2D) { format = (t as Texture2D).format; checkFormat = true; } if (checkFormat) { if (!TextureUtil.IsAlphaOnlyTextureFormat(format)) { alphaOnly = false; } if (TextureUtil.HasAlphaTextureFormat(format)) { TextureUsageMode mode = TextureUtil.GetUsageMode(t); if (mode == TextureUsageMode.Default) // all other texture usage modes don't displayable alpha { hasAlpha = true; } } } mipCount = Mathf.Max(mipCount, TextureUtil.GetMipmapCount(t)); } List <PreviewMode> previewCandidates = new List <PreviewMode>(5); previewCandidates.Add(PreviewMode.RGB); previewCandidates.Add(PreviewMode.R); previewCandidates.Add(PreviewMode.G); previewCandidates.Add(PreviewMode.B); previewCandidates.Add(PreviewMode.A); if (alphaOnly) { previewCandidates.Clear(); previewCandidates.Add(PreviewMode.A); m_PreviewMode = PreviewMode.A; } else if (!hasAlpha) { previewCandidates.Remove(PreviewMode.A); } if (previewCandidates.Count > 1 && tex != null && !IsNormalMap(tex)) { int selectedIndex = previewCandidates.IndexOf(m_PreviewMode); if (selectedIndex == -1) { selectedIndex = 0; } if (previewCandidates.Contains(PreviewMode.RGB)) { m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.RGB, s_Styles.previewButtonContents[0], s_Styles.toolbarButton) ? PreviewMode.RGB : m_PreviewMode; } if (previewCandidates.Contains(PreviewMode.R)) { m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.R, s_Styles.previewButtonContents[1], s_Styles.toolbarButton) ? PreviewMode.R : m_PreviewMode; } if (previewCandidates.Contains(PreviewMode.G)) { m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.G, s_Styles.previewButtonContents[2], s_Styles.toolbarButton) ? PreviewMode.G : m_PreviewMode; } if (previewCandidates.Contains(PreviewMode.B)) { m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.B, s_Styles.previewButtonContents[3], s_Styles.toolbarButton) ? PreviewMode.B : m_PreviewMode; } if (previewCandidates.Contains(PreviewMode.A)) { m_PreviewMode = GUILayout.Toggle(m_PreviewMode == PreviewMode.A, s_Styles.previewButtonContents[4], s_Styles.toolbarButton) ? PreviewMode.A : m_PreviewMode; } } if (mipCount > 1) { GUILayout.Box(s_Styles.smallZoom, s_Styles.previewLabel); GUI.changed = false; m_MipLevel = Mathf.Round(GUILayout.HorizontalSlider(m_MipLevel, mipCount - 1, 0, s_Styles.previewSlider, s_Styles.previewSliderThumb, GUILayout.MaxWidth(64))); //For now, we don't have mipmaps smaller than the tile size when using VT. if (EditorGUI.UseVTMaterial(tex)) { int numMipsOfTile = (int)Mathf.Log(VirtualTexturing.EditorHelpers.tileSize, 2) + 1; m_MipLevel = Mathf.Min(m_MipLevel, Mathf.Max(mipCount - numMipsOfTile, 0)); } GUILayout.Box(s_Styles.largeZoom, s_Styles.previewLabel); } }
public 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; } }