public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height) { AudioClip clip = target as AudioClip; AssetImporter importer = AssetImporter.GetAtPath(assetPath); AudioImporter audioImporter = importer as AudioImporter; if (audioImporter == null || !ShaderUtil.hardwareSupportsRectRenderTexture) { return(null); } if (m_PreviewUtility == null) { m_PreviewUtility = new PreviewRenderUtility(); } m_PreviewUtility.BeginStaticPreview(new Rect(0, 0, width, height)); // We're drawing into an offscreen here which will have a resolution defined by EditorGUIUtility.pixelsPerPoint. This is different from the DoRenderPreview call below where we draw directly to the screen, so we need to take // the higher resolution into account when drawing into the offscreen, otherwise only the upper-left quarter of the preview texture will be drawn. DoRenderPreview(clip, audioImporter, new Rect(0.05f * width * EditorGUIUtility.pixelsPerPoint, 0.05f * width * EditorGUIUtility.pixelsPerPoint, 1.9f * width * EditorGUIUtility.pixelsPerPoint, 1.9f * height * EditorGUIUtility.pixelsPerPoint), 1.0f); return(m_PreviewUtility.EndStaticPreview()); }
public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height) { if (!ShaderUtil.hardwareSupportsRectRenderTexture) { return(null); } OnEnable(); Rect r = new Rect(0, 0, width, height); m_PreviewUtility.BeginStaticPreview(r); DrawPreview(); return(m_PreviewUtility.EndStaticPreview()); }
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height) { if (!ShaderUtil.hardwareSupportsRectRenderTexture) { return(null); } InitPreview(); m_PreviewUtility.BeginStaticPreview(new Rect(0, 0, width, height)); DoRenderPreview(true); return(m_PreviewUtility.EndStaticPreview()); }
public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height) { if (!ShaderUtil.hardwareSupportsRectRenderTexture) { //Debug.Log("Could not generate static preview. Render texture not supported by hardware."); return(null); } Init(); m_PreviewUtility.BeginStaticPreview(new Rect(0, 0, width, height)); DoRenderPreview(); return(m_PreviewUtility.EndStaticPreview()); }
public override Texture2D RenderStaticPreview(string assetPath, Object[] subAssets, int width, int height) { if (!ShaderUtil.hardwareSupportsRectRenderTexture || !SystemInfo.supports2DArrayTextures) { return(null); } var texture = target as Texture2DArray; if (texture == null) { return(null); } var previewUtility = new PreviewRenderUtility(); previewUtility.BeginStaticPreview(new Rect(0, 0, width, height)); InitPreview(); m_Material.mainTexture = texture; m_Material.SetInt(s_ShaderColorMask, 15); m_Material.SetFloat(s_ShaderMip, 0); m_Material.SetInt(s_ShaderToSrgb, 0); m_Material.SetInt(s_ShaderIsNormalMap, IsNormalMap(texture) ? 1 : 0); int sliceDistance = previewUtility.renderTexture.width / 12; var elementCount = Mathf.Min(texture.depth, 6); Rect screenRect = new Rect(), sourceRect = new Rect(); var subRect = new Rect(0, 0, previewUtility.renderTexture.width - sliceDistance * (elementCount - 1), previewUtility.renderTexture.height - sliceDistance * (elementCount - 1)); for (var el = elementCount - 1; el >= 0; --el) { m_Material.SetInt(s_ShaderSliceIndex, el); subRect.x = sliceDistance * el; subRect.y = previewUtility.renderTexture.height - subRect.height - sliceDistance * el; var aspect = texture.width / (float)texture.height; GUI.CalculateScaledTextureRects(subRect, ScaleMode.ScaleToFit, aspect, ref screenRect, ref sourceRect); Graphics.DrawTexture(screenRect, texture, sourceRect, 0, 0, 0, 0, Color.white, m_Material); } var res = previewUtility.EndStaticPreview(); previewUtility.Cleanup(); return(res); }
public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height) { Texture2D result; if (!this.HasStaticPreview() || !ShaderUtil.hardwareSupportsRectRenderTexture) { result = null; } else { PreviewRenderUtility renderUtility = this.GetPreviewData().renderUtility; renderUtility.BeginStaticPreview(new Rect(0f, 0f, (float)width, (float)height)); this.DoRenderPreview(); result = renderUtility.EndStaticPreview(); } return(result); }
public Texture2D RenderStaticPreview(Texture t, int width, int height, float exposure) { if (!ShaderUtil.hardwareSupportsRectRenderTexture) { return(null); } InitPreview(); m_PreviewUtility.BeginStaticPreview(new Rect(0, 0, width, height)); const float previewDistance = 5.3f; Vector2 previewDirection = new Vector2(0, 0); // When rendering the cubemap preview we don't need lighting so we provide a custom list with no lights. // If we don't do this and we are generating the preview for a point light cookie, if a light uses this cookie it will try to bind it which result in internal assert in AssetDatabase due to using the texture while building it. m_PreviewUtility.ambientColor = Color.black; RenderCubemap(t, previewDirection, previewDistance, exposure); return(m_PreviewUtility.EndStaticPreview()); }
public override Texture2D RenderStaticPreview(string assetPath, UnityEngine.Object[] subAssets, int width, int height) { if (!ShaderUtil.hardwareSupportsRectRenderTexture || !SystemInfo.supports3DTextures) { return(null); } if (target == null) { return(null); } OnEnable(); m_QualityModifier *= 2; Rect r = new Rect(0, 0, width, height); m_PreviewUtility.BeginStaticPreview(r); DrawPreview(); return(m_PreviewUtility.EndStaticPreview()); }