EditorWindow.OnInspectorUpdate 当检视面板更新

function OnInspectorUpdate () : void

Description描述

OnInspectorUpdate is called at 10 frames per second to give the inspector a chance to update

OnInspectorUpdate被调用,在给定检视面板每秒10帧更新。

EditorWindow.OnInspectorUpdate 在检视面板更新

Align position of the selected objects.
选择物体的对齐位置。

// Simple script that aligns the position of several selected GameObjects
// with the first selected one.
//带有首先选择的一个,几个选择游戏物体的对齐位置

class AlignPosition extends EditorWindow {
	var alignToX = true;var alignToY = true; var alignToZ = true;
	var selected = "";
	var alignTo = "";

	@MenuItem("Example/Align position")
	static function Init() {
		var window = GetWindow(AlignPosition);
		window.Show();
	}
	function OnInspectorUpdate() {
		// Call Repaint on OnInspectorUpdate as it repaints the windows
		// less times as if it was OnScript/Update
		//在OnInspectorUpdate上调用重绘,因为它在窗口上较少重绘,就好象是OnScript/Update
		Repaint();
	}
	function OnGUI() {
		GUILayout.Label("Select various Objects in the Hierarchy view");
		selected = Selection.activeTransform ? Selection.activeTransform.name : "";
		for(var t : Transform in Selection.transforms)
			if(t.GetInstanceID() != Selection.activeTransform.GetInstanceID())
				alignTo += t.name + " ";
		EditorGUILayout.LabelField("Align: ", alignTo);
		alignTo = "";
		EditorGUILayout.LabelField("With: ", selected);

		alignToX = EditorGUILayout.Toggle("X", alignToX);
		alignToY = EditorGUILayout.Toggle("Y", alignToY);
		alignToZ = EditorGUILayout.Toggle("Z", alignToZ);
		if(GUILayout.Button("Align"))
			Align();
	}
	function Align() {
		if(selected == "" || alignTo == "")
			Debug.LogError("No objects selected to align");
		for(var t : Transform in Selection.transforms) {
			var alignementPosition = Selection.activeTransform.position;
			var newPosition : Vector3;
			newPosition.x = alignToX ? alignementPosition.x : t.position.x;
			newPosition.y = alignToY ? alignementPosition.y : t.position.y;
			newPosition.z = alignToZ ? alignementPosition.z : t.position.z;
			t.position = newPosition;
		}
	}
}
Page last updated: 2011-6-24