public static BuildPreviewTexture ( int width, int height, |
||
width | int | |
height | int | |
sprite | ||
spriteRendererMaterial | ||
isPolygon | bool | |
리턴 |
public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height) { if (!ShaderUtil.hardwareSupportsRectRenderTexture) { return((Texture2D)null); } Texture target1 = this.target as Texture; if (this.IsCubemap()) { return(this.m_CubemapPreview.RenderStaticPreview(target1, width, height)); } TextureImporter atPath = AssetImporter.GetAtPath(assetPath) as TextureImporter; if ((UnityEngine.Object)atPath != (UnityEngine.Object)null && atPath.spriteImportMode == SpriteImportMode.Polygon) { Sprite subAsset = subAssets[0] as Sprite; if ((bool)((UnityEngine.Object)subAsset)) { return(SpriteInspector.BuildPreviewTexture(width, height, subAsset, (Material)null, true)); } } PreviewHelpers.AdjustWidthAndHeightForStaticPreview(target1.width, target1.height, ref width, ref height); RenderTexture active = RenderTexture.active; Rect rawViewportRect = ShaderUtil.rawViewportRect; bool flag = !TextureUtil.GetLinearSampled(target1); RenderTexture temporary = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, !flag ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB); Material material = EditorGUI.GetMaterialForSpecialTexture(target1); GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; if ((bool)((UnityEngine.Object)material)) { if (Unsupported.IsDeveloperBuild()) { material = new Material(material); } Graphics.Blit(target1, temporary, material); } else { Graphics.Blit(target1, temporary); } GL.sRGBWrite = false; RenderTexture.active = temporary; Texture2D target2 = this.target as Texture2D; Texture2D texture2D = !((UnityEngine.Object)target2 != (UnityEngine.Object)null) || !target2.alphaIsTransparency ? new Texture2D(width, height, TextureFormat.RGB24, false) : new Texture2D(width, height, TextureFormat.ARGB32, false); texture2D.ReadPixels(new Rect(0.0f, 0.0f, (float)width, (float)height), 0, 0); texture2D.Apply(); RenderTexture.ReleaseTemporary(temporary); EditorGUIUtility.SetRenderTextureNoViewport(active); ShaderUtil.rawViewportRect = rawViewportRect; if ((bool)((UnityEngine.Object)material) && Unsupported.IsDeveloperBuild()) { UnityEngine.Object.DestroyImmediate((UnityEngine.Object)material); } return(texture2D); }
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) { if (subAssets.Length <= 0) { result = null; return(result); } 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; RenderTexture temporary = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, RenderTextureReadWrite.Linear); Graphics.Blit(texture, temporary, EditorGUI.GetMaterialForSpecialTexture(texture, EditorGUIUtility.GUITextureBlit2SRGBMaterial)); 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; result = texture2D2; } } return(result); }
public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height) { bool isPolygon = false; TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; if (textureImporter != null) { isPolygon = (textureImporter.spriteImportMode == SpriteImportMode.Polygon); } return(SpriteInspector.BuildPreviewTexture(width, height, this.sprite, null, isPolygon)); }
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height) { bool isPolygon = false; TextureImporter atPath = AssetImporter.GetAtPath(assetPath) as TextureImporter; if ((Object)atPath != (Object)null) { isPolygon = atPath.spriteImportMode == SpriteImportMode.Polygon; } return(SpriteInspector.BuildPreviewTexture(width, height, this.sprite, (Material)null, isPolygon)); }
public static void DrawPreview(Rect r, Sprite frame, Material spriteRendererMaterial, bool isPolygon) { if (!(frame == null)) { float num = Mathf.Min(r.width / frame.rect.width, r.height / frame.rect.height); Rect position = new Rect(r.x, r.y, frame.rect.width * num, frame.rect.height * num); position.center = r.center; Texture2D texture2D = SpriteInspector.BuildPreviewTexture((int)position.width, (int)position.height, frame, spriteRendererMaterial, isPolygon); EditorGUI.DrawTextureTransparent(position, texture2D, ScaleMode.ScaleToFit); Vector4 border = frame.border; if (!Mathf.Approximately((border * num).sqrMagnitude, 0f)) { SpriteEditorUtility.BeginLines(new Color(0f, 1f, 0f, 0.7f)); SpriteEditorUtility.EndLines(); } UnityEngine.Object.DestroyImmediate(texture2D); } }
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); }
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height) { if (!ShaderUtil.hardwareSupportsRectRenderTexture) { return(null); } Texture texture = target as Texture; if (IsCubemap()) { return(m_CubemapPreview.RenderStaticPreview(texture, width, height)); } TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; if (textureImporter != null && textureImporter.textureType == TextureImporterType.Sprite && textureImporter.spriteImportMode == SpriteImportMode.Polygon) { // If the texture importer is a Sprite of primitive, use the sprite inspector for generating preview/icon. if (subAssets.Length > 0) { Sprite sprite = subAssets[0] as Sprite; if (sprite) { return(SpriteInspector.BuildPreviewTexture(width, height, sprite, null, true)); } } else { return(null); } } PreviewHelpers.AdjustWidthAndHeightForStaticPreview(texture.width, texture.height, ref width, ref height); RenderTexture savedRT = RenderTexture.active; Rect savedViewport = ShaderUtil.rawViewportRect; RenderTexture tmp = RenderTexture.GetTemporary( width, height, 0, SystemInfo.GetGraphicsFormat(DefaultFormat.LDR)); Material mat = EditorGUI.GetMaterialForSpecialTexture(texture, null, QualitySettings.activeColorSpace == ColorSpace.Linear, false); if (mat != null) { Graphics.Blit(texture, tmp, mat); } else { Graphics.Blit(texture, tmp); } RenderTexture.active = tmp; Texture2D copy; Texture2D tex2d = target as Texture2D; if (tex2d != null && tex2d.alphaIsTransparency) { copy = new Texture2D(width, height, TextureFormat.RGBA32, false); } else { copy = new Texture2D(width, height, TextureFormat.RGB24, false); } copy.ReadPixels(new Rect(0, 0, width, height), 0, 0); copy.Apply(); RenderTexture.ReleaseTemporary(tmp); EditorGUIUtility.SetRenderTextureNoViewport(savedRT); ShaderUtil.rawViewportRect = savedViewport; return(copy); }
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height) { if (!ShaderUtil.hardwareSupportsRectRenderTexture) { return(null); } Texture texture = target as Texture; GraphicsFormat format = texture.graphicsFormat; if (!(GraphicsFormatUtility.IsIEEE754Format(format) || GraphicsFormatUtility.IsNormFormat(format))) { // Can't generate correct previews for non-float/norm formats. On Metal and Vulkan this even causes validation errors. return(null); } if (IsCubemap()) { return(m_CubemapPreview.RenderStaticPreview(texture, width, height, GetExposureValueForTexture(texture))); } if (IsTexture3D()) { return(m_Texture3DPreview.RenderStaticPreview(texture, width, height)); } TextureImporter textureImporter = AssetImporter.GetAtPath(assetPath) as TextureImporter; if (textureImporter != null && textureImporter.textureType == TextureImporterType.Sprite && textureImporter.spriteImportMode == SpriteImportMode.Polygon) { // If the texture importer is a Sprite of primitive, use the sprite inspector for generating preview/icon. if (subAssets.Length > 0) { Sprite sprite = subAssets[0] as Sprite; if (sprite) { return(SpriteInspector.BuildPreviewTexture(sprite, null, true, width, height)); } } else { return(null); } } PreviewHelpers.AdjustWidthAndHeightForStaticPreview(texture.width, texture.height, ref width, ref height); RenderTexture savedRT = RenderTexture.active; Rect savedViewport = ShaderUtil.rawViewportRect; var rt = texture as RenderTexture; if (rt != null) { rt.Create(); // Ensure RT is created. Otherwise the first attempted Blit will end up binding a dummy 2D Texture where it expects a 2D Texture Array. (validation errors observed on Vulkan/Metal) } RenderTexture tmp = RenderTexture.GetTemporary( width, height, 0, SystemInfo.GetGraphicsFormat(DefaultFormat.LDR)); Material mat = EditorGUI.GetMaterialForSpecialTexture(texture, null, QualitySettings.activeColorSpace == ColorSpace.Linear, false); if (mat != null) { Graphics.Blit(texture, tmp, mat); } else { Graphics.Blit(texture, tmp); } RenderTexture.active = tmp; Texture2D copy; Texture2D tex2d = target as Texture2D; if (tex2d != null && tex2d.alphaIsTransparency) { copy = new Texture2D(width, height, TextureFormat.RGBA32, false); } else { copy = new Texture2D(width, height, TextureFormat.RGB24, false); } copy.ReadPixels(new Rect(0, 0, width, height), 0, 0); copy.Apply(); RenderTexture.ReleaseTemporary(tmp); EditorGUIUtility.SetRenderTextureNoViewport(savedRT); ShaderUtil.rawViewportRect = savedViewport; return(copy); }
public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height) { return(SpriteInspector.BuildPreviewTexture(width, height, this.sprite, null)); }
public static UnityTexture2D RenderStaticPreview(Sprite sprite, Color color, int width, int height, Matrix4x4 transform) { return(SpriteInspector.BuildPreviewTexture(sprite, previewSpriteDefaultMaterial, false, width, height, color, transform)); }
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height) { Texture2D textured; if (!ShaderUtil.hardwareSupportsRectRenderTexture) { return(null); } Texture target = this.target as Texture; if (this.IsCubemap()) { return(this.m_CubemapPreview.RenderStaticPreview(target, width, height)); } TextureImporter atPath = AssetImporter.GetAtPath(assetPath) as TextureImporter; if ((atPath != null) && (atPath.spriteImportMode == SpriteImportMode.Polygon)) { Sprite sprite = subAssets[0] as Sprite; if (sprite != null) { return(SpriteInspector.BuildPreviewTexture(width, height, sprite, null, true)); } } PreviewHelpers.AdjustWidthAndHeightForStaticPreview(target.width, target.height, ref width, ref height); RenderTexture active = RenderTexture.active; Rect rawViewportRect = ShaderUtil.rawViewportRect; bool flag = !TextureUtil.GetLinearSampled(target); RenderTexture dest = RenderTexture.GetTemporary(width, height, 0, RenderTextureFormat.Default, !flag ? RenderTextureReadWrite.Linear : RenderTextureReadWrite.sRGB); Material materialForSpecialTexture = EditorGUI.GetMaterialForSpecialTexture(target); GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear; if (materialForSpecialTexture != null) { if (Unsupported.IsDeveloperBuild()) { materialForSpecialTexture = new Material(materialForSpecialTexture); } Graphics.Blit(target, dest, materialForSpecialTexture); } else { Graphics.Blit(target, dest); } GL.sRGBWrite = false; RenderTexture.active = dest; Texture2D textured2 = this.target as Texture2D; if ((textured2 != null) && textured2.alphaIsTransparency) { textured = new Texture2D(width, height, TextureFormat.ARGB32, false); } else { textured = new Texture2D(width, height, TextureFormat.RGB24, false); } textured.ReadPixels(new Rect(0f, 0f, (float)width, (float)height), 0, 0); textured.Apply(); RenderTexture.ReleaseTemporary(dest); EditorGUIUtility.SetRenderTextureNoViewport(active); ShaderUtil.rawViewportRect = rawViewportRect; if ((materialForSpecialTexture != null) && Unsupported.IsDeveloperBuild()) { Object.DestroyImmediate(materialForSpecialTexture); } return(textured); }