In Unity I have a custom window and I am trying to load an image from Amazon S3 and display it within the window. However, my function doesn't seem to execute. If I put a Debug.Log in the function it never gets logged, however, a Debug.Log before the function gets called (LoadAvatarTexture) does log. From what I understand is that IEnumerator doesn't work in an EditorWindow class, but works for a MonoBehaviour class. What can I do to make my editor window load an image?
public class MyEditorWindow : EditorWindow {
Texture2D avatarTexture;
[MenuItem("GameSmart/Player Manager", false, 0)]
public static void ShowManager() {
var window = EditorWindow.GetWindow(typeof(MyEditorWindow));
window.titleContent = new GUIContent("Player Manager");
window.minSize = new Vector2(400, 300);
}
void OnGUI() {
var loadPlayer = GUILayout.Button("Load Player");
if (loadPlayer) {
Debug.Log("I log to the console just fine");
LoadAvatarTexture("http://dev-avatars.gamesmart.com/default.png");
}
if (avatarTexture != null) {
float aspect = (float)avatarTexture.width / (float)avatarTexture.height;
Rect previewRect = GUILayoutUtility.GetAspectRect(aspect, GUILayout.Width(100), GUILayout.ExpandWidth(true));
GUI.DrawTexture(previewRect, avatarTexture, ScaleMode.ScaleToFit, true, aspect);
}
}
IEnumerator LoadAvatarTexture(string url) {
Debug.Log("I do not log to the console");
var www = new WWW(url);
yield return www;
avatarTexture = www.texture;
}
}