Taskbar icon flashes when editor window open

I have a strange glitch in which the unity’s Windows taskbar icon flashes like so whenever my ToolBar editor window is open.

[15903-untitled+picture.png|15903]

I dont see any reason why is should do this so I’d be interested to see what you guys think about it :stuck_out_tongue:

using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;

[InitializeOnLoad]
public class ToolBox : EditorWindow {
	
	/* This class provides the toolbox menu you see, allowing you to select tools to use in the
	 * main program.
	*/
	
	static Texture2D[] icons = null;
	
	static int selected = 0;
	static int lastSelection = 0;
	
	public static void OpenToolbox(){
		//Opens the toolbox window
		ToolBox window = (ToolBox)EditorWindow.GetWindow(typeof(ToolBox));
		window.position = new Rect(window.position.x, window.position.y, 100, window.position.height);
		
		LoadIcons();
	}
	
	static void LoadIcons(){
		//Load icons into array
		List<Texture2D> newIcons = new List<Texture2D>();
		foreach( string path in new string[] {"ArrowTool.png","LineTool.png","RectTool.png"} ){
			Texture2D icon = (Texture2D)Resources.LoadAssetAtPath("Assets/Modeler/Icons/"+path, typeof(Texture2D) );
			if( icon )
				newIcons.Add( icon );
		}
		icons = newIcons.ToArray();	
	}
	
	void OnGUI(){
		//Calculate the number of colums there should be in the grid
		int c = (int)Mathf.Round(EditorWindow.GetWindow(typeof(ToolBox)).position.width/75);
		if( icons != null && icons.Length > 0 )
			selected = GUILayout.SelectionGrid(selected, icons, c);
		else
			LoadIcons();
		
		//Make sure we only enter line drawing mode when we have a mesh filter to edit
		if( selected != 0 && (!Selection.activeGameObject || !Selection.activeGameObject.GetComponent<MeshFilter>()) )
			selected = 0;
	}
	
	public static int GetCurrentCursor(){
		return selected;
	}
	
}

I was just seeing the same behaviour when I came across this question.

I just figured out why too:

Don’t call EditorWindow.GetWindow to obtain an existing reference to your window. Keep track of it yourself and implement a way to retrieve it as you would any other singleton, or if you have multiple windows (or don’t want to implement it as a singleton) pass it around (as ‘this’) from your EditorWindow derived class as and when you need it.