Legacy Documentation: Version 5.2
LanguageEnglish
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorWindow.OnDestroy()

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual

Description

OnDestroy is called when the EditorWindow is closed.


Displays a log with the number of times that the object was deformed after closing the window.

	// Simple editor script that separates slightly a mesh from its triangles.
	// and prints after closing the inspector how many times the user distortionated the mesh
	//
	// Note the mesh will be updated when you focus the scene view.

class TearMeshApart extends EditorWindow { var noiseCounter = 0; var distortionRange = 0.1; @MenuItem("Example/Distortionate Mesh") static function Init() { var window = GetWindow(TearMeshApart); window.position = Rect(0,0,200,80); window.Show(); } function OnGUI() { GUILayout.Label("Select an object to distortionate"); if(GUILayout.Button("Distortionate")) { AddNoiseToMesh(); } if(GUILayout.Button("Close")) { this.Close(); } } function AddNoiseToMesh() { var objectMesh = Selection.activeTransform ? Selection.activeTransform.GetComponent.<MeshFilter>() : null;

if(!objectMesh) { Debug.LogError("Please select a Game Object with a MeshFilter"); return; } var verts : Vector3[] = objectMesh.sharedMesh.vertices; for(var i = 0; i < verts.Length; i++) verts[i] += Vector3( Random.Range(-distortionRange, distortionRange) - distortionRange/2, Random.Range(-distortionRange, distortionRange) - distortionRange/2, Random.Range(-distortionRange, distortionRange) - distortionRange/2); objectMesh.sharedMesh.vertices = verts; noiseCounter++; } function OnDestroy() { Debug.Log("Deformed the object " + noiseCounter + " times."); } }