EditorWindow.OnFocus 当获得焦点

function OnFocus () : void

Description描述

Called when the window gets keyboard focus.

当窗口获得键盘焦点时调用。

参见: OnLostFocus.

EditorWindow.OnFocus 当获得焦点

Preview your camera in ortographic mode when you select the window.
当选择窗口在正交视图预览相机。

// Simple script that lets you preview your main camera in Orthographic view
// when selected.
//当选择时,在正交视图预览主相机
class OrthographicPreviewer extends EditorWindow {
	var renderTexture : RenderTexture;
	var camera = Camera.main;
	@MenuItem("Example/Camera Selector")
	static function Init() {
		var window = GetWindow(OrthographicPreviewer);
		window.Show();
	}
	function Awake () {
		renderTexture =
		new RenderTexture(position.width, position.height, RenderTextureFormat.ARGB32 );
	}
	function OnInspectorUpdate() {
		this.Repaint();
	}
	function OnGUI() {
		if(GUILayout.Button("Close")) {
			camera.orthographic = false;
			this.Close();
		}
		GUI.DrawTexture(Rect( 0.0f, 50.0f, position.width, position.height), renderTexture);
	}
	function OnFocus() {
		Selection.activeTransform = camera.transform;
		camera.orthographic = true;
	}
	function Update() {
		if(camera != null) {
			camera.targetTexture = renderTexture;
			camera.Render();
			camera.targetTexture = null;
		}
		if(renderTexture.width != position.width || renderTexture.height != position.height)
			renderTexture = new RenderTexture(position.width,
				position.height,
				RenderTextureFormat.ARGB32 );
	}
	function OnLostFocus() {
		camera.orthographic = false;
	}
}
最后修改:2011年6月24日 Friday 14:59

本脚本参考基于Unity 3.4.1f5

英文部分版权属©Unity公司所有,中文部分© Unity圣典 版权所有,未经许可,严禁转载 。