private void SaveAndTerminate() { JsonSerializer serializer = JsonSerializer.Create(serializerSettings); List <string> lastPrepickedSelections = TestableEditorElements.StopRecording(); if (userActions.Any()) { userActions.Last().PrepickedSelections = lastPrepickedSelections; } string serialized = JArray.FromObject(userActions, serializer).ToString(); Directory.CreateDirectory(Path.GetDirectoryName(test.PathToRecordedActions)); StreamWriter file = null; try { file = File.CreateText(test.PathToRecordedActions); file.Write(serialized); } finally { IsRecording = false; if (file != null) { file.Close(); } if (recordedWindow != null) { recordedWindow.Close(); } AssetDatabase.ImportAsset(test.PathToRecordedActions); Close(); } }
private void OnGUI() { try { if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "Abort") { Abort(); return; } if (Event.current.type == EventType.ExecuteCommand && Event.current.commandName == "SaveAndTerminate") { SaveAndTerminate(); return; } Rect newPos = recordedWindow.position; minSize = newPos.size; maxSize = newPos.size; position = newPos; MethodInfo onGui = recordedWindow.GetType().GetMethod("OnGUI", BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance); if (Event.current.type != EventType.Used) { if (ShouldRecordEvent()) { if (userActions.Any()) { userActions.Last().PrepickedSelections = TestableEditorElements.StopRecording(); TestableEditorElements.StartRecording(); } Event toRecord = JsonConvert.DeserializeObject <Event>(JsonConvert.SerializeObject(Event.current, serializerSettings), serializerSettings); UserAction userActionToRecord = new UserAction { Event = toRecord }; if (ShouldReplaceLastUserAction()) { userActions[userActions.Count - 1] = userActionToRecord; } else { userActions.Add(userActionToRecord); } } onGui.Invoke(recordedWindow, new object[0]); } Focus(); } catch { IsRecording = false; TestableEditorElements.Panic(); if (recordedWindow != null) { recordedWindow.Close(); } Close(); throw; } }