EditorWindow.OnDestroy 当销毁

function OnDestroy () : void

Description描述

OnDestroy is called when the EditorWindow is closed.

当编辑器窗口关闭时,OnDestroy被调用。

EditorWindow.OnDestroy 当销毁

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.");

	}

}
Page last updated: 2011-6-24