Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by DaiMangouDev · Mar 29, 2017 at 10:48 PM · cameraeditoreditor-scriptingpreview

Any idea how to use PreviewRenderUtility ?

I was coding and I typed "preview.." and saw PreviewRenderUtility. A public class with function that seem to allows up to now quickly draw our own preview windows in the unity Editor .... But it has not been documented yet so attempts to make it work are hit and miss.

Anyone used this before and got it working ? Could you how me how it is used ?

If I am correct it should allows us to finally do things like this easily .alt text

prev.png (14.8 kB)
Comment
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

3 Replies

· Add your reply
  • Sort: 
avatar image
2
Best Answer

Answer by chingwa · Jul 11, 2017 at 09:46 PM

@DMDev I noticed code for this after viewing this Unite talk here: https://www.youtube.com/watch?v=sd9KotQ2PhA

You can see them talk about asset previews around the 8:00 minute mark. This is the code they use:

PreviewRenderUtility renderUtility = new PreviewRenderUtility();

void OnGUI(){ Rect rect = new Rect(40,200,200,200); renderUtility.BeginPreview(rect, ""); renderUtility.DrawMesh(previewModel.mesh, Vector3.one, Quaternion.identity, previewModel.material,0); renderUtility.EndAndDrawPreview(rect); }

Comment
Add comment · Show 1 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image DaiMangouDev · Jul 13, 2017 at 02:59 AM 0
Share

this is great! thanks for sharing

avatar image
0

Answer by EJSainz · Jul 22, 2019 at 02:38 PM

Just in case somebody stomps here looking for some info on PreviewRenderUtility, I just gathered the following code from here and there to draw a prefab using it:

     void BeginDraw(Rect r)
     {
         if (prevRenderer == null)
             prevRenderer = new PreviewRenderUtility();
 
         prevRenderer.camera.transform.position = camPosition;
         prevRenderer.camera.transform.LookAt(Vector3.zero, Vector3.up);
         prevRenderer.camera.farClipPlane = 30;
 
         prevRenderer.lights[0].intensity = 0.5f;
         prevRenderer.lights[0].transform.rotation = Quaternion.Euler(30f, 30f, 0f);
         prevRenderer.lights[1].intensity = 0.5f;
 
         prefabTransform.SetTRS(prefabTranslation, Quaternion.Euler(prefabRotation), prefabScale);
 
         prevRenderer.BeginPreview(r, GUIStyle.none);
     }
 
     void EndDraw(Rect r)
     {
         bool fog = RenderSettings.fog;
         Unsupported.SetRenderSettingsUseFogNoDirty(false);
         prevRenderer.camera.Render();
         Unsupported.SetRenderSettingsUseFogNoDirty(fog);
 
         Texture texture = prevRenderer.EndPreview();
         GUI.DrawTexture(r, texture);
     }
 
     public void DrawRenderPreview()
     {
         if (prefab != null)
         {
             MeshFilter[] meshFilters = prefab.GetComponentsInChildren<MeshFilter>();
             for (int i = 0; i < meshFilters.Length; i++)
             {
                 if (meshFilters[i].sharedMesh)
                 {
                     MeshRenderer meshRenderer = meshFilters[i].gameObject.GetComponent<MeshRenderer>();
                     for (int j = 0; j < meshFilters[i].sharedMesh.subMeshCount; j++)
                     if (meshRenderer != null)
                     {
                             prevRenderer.DrawMesh(
                                 meshFilters[i].sharedMesh,
                                 prefabTransform * meshRenderer.transform.localToWorldMatrix,
                                 meshRenderer.sharedMaterials[j],
                                 j);
                     }
                 }
             }
         }
     }
 
     private void OnGUI()
     {
         Rect r = new Rect(0.0f, 0.0f, position.width, position.height);
 
         BeginDraw(r);
         DrawRenderPreview();
         EndDraw(r);
     }
 
 

This code will draw a GameObject referenced in the prefab variable, and it's part of an EditorWindow. I'm sorry I have not enough time to prepare the full working class, but the code is pretty self explanatory, and you can have it working in no time.

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by web · Oct 08, 2021 at 09:07 PM

https://github.com/CyberFoxHax/Unity3D_PreviewRenderUtility_Documentation

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

109 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Cannot close Preview Scene 0 Answers

Unity editor 2D, not zoom during focus 0 Answers

Get default preview for GameObject Editor 2 Answers

OnInteractivePreviewGUI multiple selection. Works but spams errors. 0 Answers

How can I simulate the "f" hotkey in the editor? 4 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges