MeshEditorWithPreview Class Reference

Detailed Description

This version of the class overrides the base version. Rather than abstract functions, it explicitly specifies components and how to set them up.
This example specifies that a mesh filter and mesh render are to be used, and how to set them up. Since unity includes a preview for meshes, this example is merely demonstrates how one might use a procedurally generated mesh, without going into procedural details.

Public Member Functions

override string GetInfoString ()
 This function returns the string that will be displayed as the title of the preview pane in the editor. Your derived class will need to define this abstract function.
 
- Public Member Functions inherited from EditorWithPreview< Mesh >
void GenerateSnapshot (Quaternion rotation, Vector2 size, ref RenderTexture snapShot)
 This function is the "magic" part of the class. It will manipulate the diorama objects, based on the parameters, and then render it to a RenderTexture.
 
void GenerateSnapshot (Quaternion rotation, Vector2 size, ref Texture2D snapShot)
 This Public function allows the user to generate the Snapshot, and get the result in the form of a Texture2D.
 
override bool HasPreviewGUI ()
 Specifies that this type of editor window should indeed draw a preview pane.
 
virtual void OnEnable ()
 When enabled will perform setup steps required to create the diorama, and prepares to render it.
 
override void OnInspectorGUI ()
 Override this function if you would like to change how the inspector of the editor is drawn. This version just draws the Default Inspector.
 
override void OnInteractivePreviewGUI (Rect rect, GUIStyle background)
 Calls the OnPreviewGUI function since the same logic is used to draw both.
 
override void OnPreviewGUI (Rect rect, GUIStyle background)
 This function will render the diorama and display it in the Rect provided. PreviewPref options will adjust how the preview is rendered. If the rect is below 32 pixels in height, the cashed thumbImage will be drawing the provided Rect, rather than re-rendering the entire diorama.
 
override Texture2D RenderStaticPreview (string assetPath, Object[] subAssets, int width, int height)
 Overrides the Unity Editor class function of the same name to provide static Previews of objects. Not intended for use by end User.
 
void RepaintNow ()
 Call this function to force the preview to be repainted.
 
override bool RequiresConstantRepaint ()
 Overridden Editor function that informs unity when the editor needs to be repainted.
 

Protected Member Functions

override void DoGLrendering (Camera cam)
 
override Bounds GetBounds ()
 This function will allow the preview camera to be properly placed, such that it encompass the bounds of the object. The preference-option to offset object to bounds center, will affect weather the camera focuses on the center on the returned bounds, or the origin,.
 
override System.Type[] GetTypesOfRendererComponents ()
 Abstract base class (EditorWithPreview) functions specified.
 
override void PreCameraRendering (Camera cam)
 This function is called immediately before the preview camera is rendered. Override and declare your own version to call drawing functions that queue up specific render tasks, like Graphics.DrawMesh.
 
override void SetupPreviewObject ()
 Performs the setup necessary for the PreviewObject to be drawn to the preview camera. This would include actions like assigning the current Editor's target to the appropriate PreviewObject components. previewObject.GetComponent(MeshFilter>().sharedMesh = (Mesh)target;This abstract function will need to be defined in your derived class.
 
override void SetupPreviewObjectRendererWithMaterial (Material previewMaterial)
 
- Protected Member Functions inherited from EditorWithPreview< Mesh >
virtual void CreatePreviewObjects ()
 Creates all the objects needed to render the diorama including the camera, preview objects, and diorama shoe-box. Protected, but otherwise internal function that you can override for additional creation steps, if needed.
 
virtual void DestroyPreviewObjects ()
 Destroys all the dynamic objects needed to render the diorama like the preview object, and render Textures. Non-changing items like the diorama shoe-box, and preview camera are not destroyed. Protected, but otherwise internal function that you can override for additional destruction steps, if needed.
 
void DrawAxis (Camera cam, Vector3 offset)
 Draws an Axis based upon PreviewPrefs settings to the provided camera.
 
virtual void OnDestroy ()
 Destroys the dynamic elements of the diorama.
 
virtual void OnDisable ()
 Destroys the dynamic elements of the diorama, and resets the rotation of the preview.
 

Additional Inherited Members

- Static Public Member Functions inherited from EditorWithPreview< Mesh >
static void ProjectItemOnGUI (string guid, Rect rect)
 finds or generates icons for items, if they have a EditorWithPreview defined for the type of object.
 
- Protected Attributes inherited from EditorWithPreview< Mesh >
RenderTexture previewImage
 A reference to the render texture that is displayed in the preview pane. This image is updated dynamically.
The texture is destroyed when the Editor window goes out of scope. The texture is destroyed and recreated, every time the preview is repainted.
 
GameObject previewObject
 This is a reference to the object created in the scene diorama. It is destroyed when the Editor window goes out of scope.
 
Texture2D thumbImage
 This image is generated once, is small, and static. It is used to for the Target's icon in both inspector and project window.
 
- Properties inherited from EditorWithPreview< Mesh >
static Material axisMaterial [get, set]
 Reference to the material that will be used to draw the coordinate axes, in the preview window.
 
static Camera previewCamera [get]
 this is the preview camera that will be used for all previews.
 
static Material previewMaterial [get]
 Reference to the dynamically created preview material, which uses the previwShader
 
static Shader previewShader [get, set]
 this is the special preview shader used to draw preview objects.
 
+ Inheritance diagram for MeshEditorWithPreview:
+ Collaboration diagram for MeshEditorWithPreview: