Preview for Prefabs

Hi all,

I want to rendere a preview of my Prefab in the Inspector like the preview of a normal model.

So I have overridden the HasPreviewGUI (returns true) methode and the OnPreviewGUI.
But I don’t know how to render the prefab now!

Can someone help me please…

EDIT:

I got this to work:

private Camera cam;
        public override void OnPreviewGUI(Rect r, GUIStyle background) {
            base.OnPreviewGUI(r, background);
            if (cam == null) {
                var camObj = new GameObject();
                camObj.hideFlags = HideFlags.HideAndDontSave;
                camObj.transform.position = new Vector3(0.5f, 2.0f, -5.0f);
                camObj.transform.eulerAngles = new Vector3(19.0f, -5.0f, 0.0f);
                cam = camObj.AddComponent<Camera>();
                cam.fieldOfView = 19;
            }

            Handles.DrawCamera(r, cam, DrawCameraMode.TexturedWire);
        }

The problem:
It also renders it in the Game View… and renders the Game View…

Thx in advance.

Not 100% if i understand you correctly but previewing a gameobject / prefab can be done via a custom editor.

You have to change the editor style to shometing other thern in the example or it will torw errors.
I would recommend EditorStyles.foldout for example

Look like Prefabs with more then one object behave differently then prefabs with only one object. Sorry for the misinterpretation of your question.

Ok I solved my main problem…
I want to draw icons for buttons in an editor window based on the preview actually…

But I did something wrong on creating the prefab, so it has no preview for that.

So the question is solved… I created a new prefab and I get now a preview!

Thx you anyway :slight_smile:

Hello Spy-Shifty, I’ve just finished my own preview asset, maybe it will be useful for you: https://forum.unity3d.com/threads/powerful-preview.460157/.
Looks and behaves just like the native preview.