OnDestroy は EditorWindow が閉じられたときに呼び出されます
"ウィンドウを閉じた後、オブジェクトが変形した回数のログを表示します。"
// 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."); } }