Here is my code:
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
public class LevelEdit : EditorWindow {
public string[] options = new string[] {"Dirt","Stone","GrassNormal","GrassBeach"};
Sprite[] tilesprites;
List<GUIContent> _ticons = new List<GUIContent> ();
GUIContent[] tileicons;
public int index = 0;
int tindex = 0;
bool loaded = false;
bool creating;
// Add menu item named "My Window" to the Window menu
[MenuItem("Window/Level Editor")]
public static void ShowWindow()
{
//Show existing window instance. If one doesn't exist, make one.
EditorWindow window = GetWindow(typeof(LevelEdit));
window.Show ();
}
public static Texture2D textureFromSprite(Sprite sprite)
{
if(sprite.rect.width != sprite.texture.width){
Texture2D newText = new Texture2D((int)sprite.rect.width,(int)sprite.rect.height);
Color[] newColors = sprite.texture.GetPixels((int)sprite.textureRect.x,
(int)sprite.textureRect.y,
(int)sprite.textureRect.width,
(int)sprite.textureRect.height );
newText.SetPixels(newColors);
newText.Apply();
return newText;
} else
return sprite.texture;
}
void OnGUI()
{
GUILayout.Label ("Base Settings", EditorStyles.boldLabel);
index = EditorGUILayout.Popup(index, options);
creating = EditorGUILayout.Toggle ("Place Blocks", creating);
if (loaded) {
tindex = EditorGUILayout.Popup(tindex, tileicons);
}
if (GUILayout.Button ("Load")) {
loaded = true;
string tileprefix = "Tiles_" + index;
tilesprites = Resources.LoadAll<Sprite>("Tiles/" + tileprefix);
foreach (Sprite tile in tilesprites) {
_ticons.Add (new GUIContent (textureFromSprite(tile), tile.name));
}
tileicons = _ticons.ToArray ();
}
EditorGUILayout.EndToggleGroup ();
}
}
I am trying to write a level editor for a game I am working on. There is supposed to be a popup box where you can select a type of tile, then hit “Load”, then select a specific tile sprite from another popup that should appear after you hit “Load”, however, when I run it, all I get is this window:

which is completely unresponsive. (I can’t drag or close it)
This doesn’t seem to be a problem with Unity itself as the documentary code works just fine, but whenever I add anything else to it, it breaks.
If it is related at all, I also get this error in the console,
InvalidOperationException: Operation is not valid due to the current state of the object
System.Collections.Generic.Stack`1[System.Boolean].Pop ()
I’m running Unity 5.3 on a Mac OS X 10.9
Thanks in advance