public static void ShowWindow() { //get one if it already exists instance = GetWindow <ThumbnailEditorWindow>(); //delegate to the scenview render method, so we can draw gizmos in the scene using Editor GUI Handles SceneView.onSceneGUIDelegate -= instance.OnSceneGui; //yuck...why unity whyyyy!?! SceneView.onSceneGUIDelegate += instance.OnSceneGui; //callback so that we can draw a preview of the active mesh in the sceneview camera Camera.onPreCull -= instance.DrawActiveObjectScenePreview; Camera.onPreCull += instance.DrawActiveObjectScenePreview; instance.activeObject = null; //load setting data, it's stashed as a really long string encodeded using json //easier than making individual prefs for each settings property. much easier to save also. if (EditorPrefs.HasKey("ThumbData")) { instance.settings = JsonUtility.FromJson <ThumbnailEditorSettings>(EditorPrefs.GetString("ThumbData")); } instance.Show(); }
private void OnDestroy() { SceneView.onSceneGUIDelegate -= OnSceneGui; Camera.onPreCull -= instance.DrawActiveObjectScenePreview; activeObject = null; if (!instance) { instance = GetWindow <ThumbnailEditorWindow>(); } Debug.Log("OnDestroy"); EditorPrefs.DeleteKey("ThumbPath"); EditorPrefs.SetString("ThumbData", JsonUtility.ToJson(instance.settings, true)); instance = null; if (renderCamera != null) { DestroyImmediate(renderCamera.gameObject); } }