Legacy Documentation: Version 2017.2 (Go to current version)
LanguageEnglish
  • C#
  • JS

Script language

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

EditorWindow.OnLostFocus()

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

Submission failed

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

Close

Cancel

Description

Called when the window loses keyboard focus.

See Also: OnFocus.


Restores normal view when you lose focus on this window.

no example available in JavaScript
// Simple script that lets you preview your main camera in
// Orthographic view when selected.

using UnityEngine; using UnityEditor;

public class ExampleClass : EditorWindow { RenderTexture renderTexture; Camera camera;

[MenuItem("Examples/Orthographic Previewer")] static void Init() { ExampleClass window = (ExampleClass)EditorWindow.GetWindow(typeof(ExampleClass), true, "My Empty Window"); window.Show(); }

void OnEnable() { int w = (int)this.position.width; int h = (int)this.position.height;

renderTexture = new RenderTexture(w, h, 32, RenderTextureFormat.ARGB32); camera = Camera.main; }

void OnInspectorUpdate() { this.Repaint(); }

void OnGUI() { if (GUILayout.Button("Close")) { camera.orthographic = false; this.Close(); } if (renderTexture != null) { float w = this.position.width; float h = this.position.height; GUI.DrawTexture(new Rect(0.0f, 50.0f, w, h), renderTexture); } }

void OnFocus() { Selection.activeTransform = camera.transform; camera.orthographic = true; }

void Update() { if (camera != null) { camera.targetTexture = renderTexture; camera.Render(); camera.targetTexture = null; }

int w = (int)this.position.width; int h = (int)this.position.height; if (renderTexture.width != w || renderTexture.height != h) { renderTexture = new RenderTexture(w, h, 32, RenderTextureFormat.ARGB32); } }

void OnLostFocus() { camera.orthographic = false; } }

Did you find this page useful? Please give it a rating: