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))); }
protected void OnRenderTextureGUI(RenderTextureEditor.GUIElements guiElements) { GUI.changed = false; bool flag = this.m_Dimension.intValue == 3; EditorGUILayout.IntPopup(this.m_Dimension, RenderTextureEditor.styles.dimensionStrings, RenderTextureEditor.styles.dimensionValues, RenderTextureEditor.styles.dimension, new GUILayoutOption[0]); GUILayout.BeginHorizontal(new GUILayoutOption[0]); EditorGUILayout.PrefixLabel(RenderTextureEditor.styles.size, EditorStyles.popup); EditorGUILayout.DelayedIntField(this.m_Width, GUIContent.none, new GUILayoutOption[] { GUILayout.MinWidth(40f) }); GUILayout.Label(RenderTextureEditor.styles.cross, new GUILayoutOption[0]); EditorGUILayout.DelayedIntField(this.m_Height, GUIContent.none, new GUILayoutOption[] { GUILayout.MinWidth(40f) }); if (flag) { GUILayout.Label(RenderTextureEditor.styles.cross, new GUILayoutOption[0]); EditorGUILayout.DelayedIntField(this.m_Depth, GUIContent.none, new GUILayoutOption[] { GUILayout.MinWidth(40f) }); } GUILayout.FlexibleSpace(); GUILayout.EndHorizontal(); if ((guiElements & RenderTextureEditor.GUIElements.RenderTargetAAGUI) != RenderTextureEditor.GUIElements.RenderTargetNoneGUI) { EditorGUILayout.IntPopup(this.m_AntiAliasing, RenderTextureEditor.styles.renderTextureAntiAliasing, RenderTextureEditor.styles.renderTextureAntiAliasingValues, RenderTextureEditor.styles.antiAliasing, new GUILayoutOption[0]); } EditorGUILayout.PropertyField(this.m_ColorFormat, RenderTextureEditor.styles.colorFormat, new GUILayoutOption[0]); if ((guiElements & RenderTextureEditor.GUIElements.RenderTargetDepthGUI) != RenderTextureEditor.GUIElements.RenderTargetNoneGUI) { EditorGUILayout.PropertyField(this.m_DepthFormat, RenderTextureEditor.styles.depthBuffer, new GUILayoutOption[0]); } bool disabled = RenderTextureEditor.IsHDRFormat((RenderTextureFormat)this.m_ColorFormat.intValue); using (new EditorGUI.DisabledScope(disabled)) { EditorGUILayout.PropertyField(this.m_sRGB, RenderTextureEditor.styles.sRGBTexture, new GUILayoutOption[0]); } using (new EditorGUI.DisabledScope(flag)) { EditorGUILayout.PropertyField(this.m_EnableMipmaps, RenderTextureEditor.styles.enableMipmaps, new GUILayoutOption[0]); using (new EditorGUI.DisabledScope(!this.m_EnableMipmaps.boolValue)) { EditorGUILayout.PropertyField(this.m_AutoGeneratesMipmaps, RenderTextureEditor.styles.autoGeneratesMipmaps, new GUILayoutOption[0]); } } if (flag) { EditorGUILayout.HelpBox("3D RenderTextures do not support Mip Maps.", MessageType.Info); } EditorGUILayout.PropertyField(this.m_UseDynamicScale, RenderTextureEditor.styles.useDynamicScale, new GUILayoutOption[0]); RenderTexture renderTexture = base.target as RenderTexture; if (GUI.changed && renderTexture != null) { renderTexture.Release(); } EditorGUILayout.Space(); base.DoWrapModePopup(); base.DoFilterModePopup(); using (new EditorGUI.DisabledScope(this.RenderTextureHasDepth())) { base.DoAnisoLevelSlider(); } if (this.RenderTextureHasDepth()) { this.m_Aniso.intValue = 0; EditorGUILayout.HelpBox("RenderTextures with depth must have an Aniso Level of 0.", MessageType.Info); } }
private static void SaveToDisk(MenuCommand command) { CustomRenderTexture customRenderTexture = command.context as CustomRenderTexture; int width = customRenderTexture.width; int height = customRenderTexture.height; int volumeDepth = customRenderTexture.volumeDepth; bool flag = RenderTextureEditor.IsHDRFormat(customRenderTexture.format); bool flag2 = customRenderTexture.format == RenderTextureFormat.ARGBFloat || customRenderTexture.format == RenderTextureFormat.RFloat; TextureFormat format = (!flag) ? TextureFormat.RGBA32 : TextureFormat.RGBAFloat; int width2 = width; if (customRenderTexture.dimension == TextureDimension.Tex3D) { width2 = width * volumeDepth; } else if (customRenderTexture.dimension == TextureDimension.Cube) { width2 = width * 6; } Texture2D texture2D = new Texture2D(width2, height, format, false); if (customRenderTexture.dimension == TextureDimension.Tex2D) { Graphics.SetRenderTarget(customRenderTexture); texture2D.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0); texture2D.Apply(); } else if (customRenderTexture.dimension == TextureDimension.Tex3D) { int num = 0; for (int i = 0; i < volumeDepth; i++) { Graphics.SetRenderTarget(customRenderTexture, 0, CubemapFace.Unknown, i); texture2D.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), num, 0); texture2D.Apply(); num += width; } } else { int num2 = 0; for (int j = 0; j < 6; j++) { Graphics.SetRenderTarget(customRenderTexture, 0, (CubemapFace)j); texture2D.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), num2, 0); texture2D.Apply(); num2 += width; } } byte[] bytes; if (flag) { bytes = texture2D.EncodeToEXR(Texture2D.EXRFlags.CompressZIP | ((!flag2) ? Texture2D.EXRFlags.None : Texture2D.EXRFlags.OutputAsFloat)); } else { bytes = texture2D.EncodeToPNG(); } UnityEngine.Object.DestroyImmediate(texture2D); string extension = (!flag) ? "png" : "exr"; string directoryName = Path.GetDirectoryName(AssetDatabase.GetAssetPath(customRenderTexture.GetInstanceID())); string text = EditorUtility.SaveFilePanel("Save Custom Texture", directoryName, customRenderTexture.name, extension); if (!string.IsNullOrEmpty(text)) { File.WriteAllBytes(text, bytes); AssetDatabase.Refresh(); } }